|
| 1 | +use std::process::{Command, Stdio}; |
| 2 | +use std::io; |
| 3 | +use dialoguer::{Select, Confirm}; |
| 4 | +use colored::*; |
| 5 | + |
| 6 | +// Color-coded output |
| 7 | +fn color_echo(color: &str, text: &str) { |
| 8 | + match color { |
| 9 | + "red" => println!("{}", text.red()), |
| 10 | + "green" => println!("{}", text.green()), |
| 11 | + "yellow" => println!("{}", text.yellow()), |
| 12 | + "blue" => println!("{}", text.blue()), |
| 13 | + _ => println!("{}", text), |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +fn add_flathub() { |
| 18 | + color_echo("yellow", "Adding Flathub..."); |
| 19 | + let status = Command::new("flatpak") |
| 20 | + .args(&["remote-add", "--if-not-exists", "flathub", "https://dl.flathub.org/repo/flathub.flatpakrepo"]) |
| 21 | + .stdout(Stdio::inherit()) |
| 22 | + .stderr(Stdio::inherit()) |
| 23 | + .status() |
| 24 | + .expect("Failed to add Flathub"); |
| 25 | + |
| 26 | + if status.success() { |
| 27 | + color_echo("green", "Flathub added"); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +fn install_rpm_fusion() { |
| 32 | + println!("Installing RPM Fusion..."); |
| 33 | + |
| 34 | + let status = Command::new("sudo") |
| 35 | + .args(&[ |
| 36 | + "dnf", |
| 37 | + "install", |
| 38 | + "-y", |
| 39 | + "rpmfusion-free-release", |
| 40 | + "rpmfusion-nonfree-release", |
| 41 | + ]) |
| 42 | + .stdout(Stdio::inherit()) |
| 43 | + .stderr(Stdio::inherit()) |
| 44 | + .status() |
| 45 | + .expect("Failed to install RPM Fusion"); |
| 46 | + |
| 47 | + if status.success() { |
| 48 | + println!("RPM Fusion installed successfully"); |
| 49 | + } else { |
| 50 | + eprintln!("Failed to install RPM Fusion"); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +fn install_ffmpeg() { |
| 55 | + color_echo("yellow", "Installing FFmpeg..."); |
| 56 | + let status = Command::new("sudo") |
| 57 | + .args(&["dnf", "swap", "ffmpeg-free", "ffmpeg", "--allowerasing", "-y"]) |
| 58 | + .stdout(Stdio::inherit()) |
| 59 | + .stderr(Stdio::inherit()) |
| 60 | + .status() |
| 61 | + .expect("Failed to install FFmpeg"); |
| 62 | + |
| 63 | + if status.success() { |
| 64 | + color_echo("green", "FFmpeg installed"); |
| 65 | + } else { |
| 66 | + color_echo("red", "Failed to install FFmpeg"); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +fn get_user_choice(prompt: &str, choices: &[&str]) -> usize { |
| 71 | + Select::new() |
| 72 | + .with_prompt(prompt) |
| 73 | + .items(choices) |
| 74 | + .default(0) |
| 75 | + .interact() |
| 76 | + .expect("Failed to read user input") |
| 77 | +} |
| 78 | + |
| 79 | +fn install_drivers(cpu_info: &str, gpu_info: &str) { |
| 80 | + if cpu_info == "INTEL" || gpu_info == "INTEL" { |
| 81 | + Command::new("sudo") |
| 82 | + .args(&["dnf", "install", "intel-media-driver", "-y"]) |
| 83 | + .status() |
| 84 | + .expect("Failed to install Intel drivers"); |
| 85 | + } |
| 86 | + |
| 87 | + if cpu_info == "AMD" || gpu_info == "AMD" { |
| 88 | + Command::new("sudo") |
| 89 | + .args(&["dnf", "swap", "mesa-va-drivers", "mesa-va-drivers-freeworld", "-y"]) |
| 90 | + .status() |
| 91 | + .expect("Failed to install AMD drivers"); |
| 92 | + Command::new("sudo") |
| 93 | + .args(&["dnf", "swap", "mesa-vdpau-drivers", "mesa-vdpau-drivers-freeworld", "-y"]) |
| 94 | + .status() |
| 95 | + .expect("Failed to install AMD drivers"); |
| 96 | + } |
| 97 | + |
| 98 | + if gpu_info == "NVIDIA" { |
| 99 | + color_echo("red", "Make sure you are on the latest kernel version!"); |
| 100 | + color_echo("red", "Make sure secure boot is off."); |
| 101 | + Command::new("sudo") |
| 102 | + .args(&["dnf", "install", "akmod-nvidia", "xorg-x11-drv-nvidia-cuda", "-y"]) |
| 103 | + .status() |
| 104 | + .expect("Failed to install NVIDIA drivers"); |
| 105 | + color_echo("blue", "Wait for 5 minutes for the kernel modules to build or check the status using:"); |
| 106 | + color_echo("blue", "modinfo -F version nvidia"); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +fn configure_dnf() { |
| 111 | + if Confirm::new() |
| 112 | + .with_prompt("Do you want to do some tweaks to DNF (Recommended)?") |
| 113 | + .interact() |
| 114 | + .unwrap() |
| 115 | + { |
| 116 | + let status = Command::new("curl") |
| 117 | + .args(&["-o", "/tmp/dnf.conf", "https://raw.githubusercontent.com/Angxddeep/Fedora-Freedom/refs/heads/main/dnf.conf"]) |
| 118 | + .status() |
| 119 | + .expect("Failed to download DNF configuration"); |
| 120 | + |
| 121 | + if status.success() { |
| 122 | + Command::new("sudo") |
| 123 | + .args(&["cp", "/tmp/dnf.conf", "/etc/dnf/dnf.conf"]) |
| 124 | + .status() |
| 125 | + .expect("Failed to update DNF configuration"); |
| 126 | + color_echo("green", "DNF configuration updated."); |
| 127 | + } else { |
| 128 | + color_echo("red", "Failed to download DNF configuration."); |
| 129 | + } |
| 130 | + } else { |
| 131 | + color_echo("yellow", "No changes made to DNF configuration."); |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +fn main() { |
| 136 | + color_echo("blue", "Fedora Setup Wizard"); |
| 137 | + |
| 138 | + if Confirm::new() |
| 139 | + .with_prompt("Add Flathub?") |
| 140 | + .interact() |
| 141 | + .unwrap() |
| 142 | + { |
| 143 | + add_flathub(); |
| 144 | + } |
| 145 | + |
| 146 | + if Confirm::new() |
| 147 | + .with_prompt("Install RPM Fusion?") |
| 148 | + .interact() |
| 149 | + .unwrap() |
| 150 | + { |
| 151 | + install_rpm_fusion(); |
| 152 | + } |
| 153 | + |
| 154 | + install_ffmpeg(); |
| 155 | + |
| 156 | + let cpu_choices = ["INTEL", "AMD"]; |
| 157 | + let cpu_choice = get_user_choice("Select your CPU manufacturer:", &cpu_choices); |
| 158 | + let cpu_info = cpu_choices[cpu_choice]; |
| 159 | + |
| 160 | + let gpu_choices = ["INTEL", "AMD", "NVIDIA"]; |
| 161 | + let gpu_choice = get_user_choice("Select your GPU manufacturer:", &gpu_choices); |
| 162 | + let gpu_info = gpu_choices[gpu_choice]; |
| 163 | + |
| 164 | + color_echo("yellow", "You have provided the following:"); |
| 165 | + color_echo("red", &format!("CPU: {}", cpu_info)); |
| 166 | + color_echo("red", &format!("GPU: {}", gpu_info)); |
| 167 | + |
| 168 | + install_drivers(cpu_info, gpu_info); |
| 169 | + |
| 170 | + configure_dnf(); |
| 171 | +} |
0 commit comments