|
1 | | - |
| 1 | +use colored::*; |
| 2 | +use std::process::{Command, Stdio}; |
| 3 | +use std::io::{self, Write}; |
| 4 | +use std::thread; |
| 5 | +use std::time::Duration; |
| 6 | +use std::sync::{Arc, atomic::{AtomicUsize, Ordering}}; |
| 7 | +pub fn run_command_with_progress(program: &str, args: Vec<&str>, message: &str) { |
| 8 | + println!("{}", format!("▶ {}: {}", message, args.join(" ")).blue().bold().on_black()); |
| 9 | + let progress = Arc::new(AtomicUsize::new(0)); |
| 10 | + let progress_clone = progress.clone(); |
| 11 | + let handle = thread::spawn(move || { |
| 12 | + let bar_length = 20; |
| 13 | + while progress_clone.load(Ordering::Relaxed) < 100 { |
| 14 | + let p = progress_clone.load(Ordering::Relaxed); |
| 15 | + let filled = (p as f32 / 100.0 * bar_length as f32) as usize; |
| 16 | + let bar: String = (0..bar_length).map(|i| if i < filled { '#' } else { '.' }).collect(); |
| 17 | + print!("\r{}% <{}>", p, bar.purple().bold()); |
| 18 | + let _ = io::stdout().flush(); |
| 19 | + thread::sleep(Duration::from_millis(200)); // Simulate progress |
| 20 | + progress_clone.store((p + 2).min(99), Ordering::Relaxed); // Increment slowly |
| 21 | + } |
| 22 | + print!("\r100% <{}> \n", "#".repeat(bar_length).purple().bold()); |
| 23 | + let _ = io::stdout().flush(); |
| 24 | + }); |
| 25 | + let mut child = Command::new(program) |
| 26 | + .args(&args) |
| 27 | + .stdout(Stdio::piped()) |
| 28 | + .stderr(Stdio::piped()) |
| 29 | + .spawn() |
| 30 | + .expect(&format!("Failed to execute {}", program)); |
| 31 | + // Simple simulation, no real progress parsing for now |
| 32 | + let output = child.wait_with_output().expect("Failed to wait on child"); |
| 33 | + progress.store(100, Ordering::Relaxed); |
| 34 | + handle.join().unwrap(); |
| 35 | + if output.status.success() { |
| 36 | + let out_str = String::from_utf8_lossy(&output.stdout).to_string(); |
| 37 | + if !out_str.is_empty() { |
| 38 | + println!("{}", format!("┌── Output ────────────────").green().bold().on_black()); |
| 39 | + println!("{}", out_str.green().on_black()); |
| 40 | + println!("{}", format!("└──────────────────────────").green().bold().on_black()); |
| 41 | + } else { |
| 42 | + println!("{}", "✔ Success (no output)".green().bold().on_black()); |
| 43 | + } |
| 44 | + } else { |
| 45 | + let err_str = String::from_utf8_lossy(&output.stderr).to_string(); |
| 46 | + println!("{}", format!("┌── Error ─────────────────").red().bold().on_black()); |
| 47 | + println!("{}", err_str.red().on_black()); |
| 48 | + println!("{}", format!("└──────────────────────────").red().bold().on_black()); |
| 49 | + } |
| 50 | +} |
| 51 | +pub fn handle_update() { |
| 52 | + println!("{}", "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓".magenta().bold().on_black()); |
| 53 | + println!("{}", "┃ Starting System Update ┃".magenta().bold().on_black()); |
| 54 | + println!("{}", "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛".magenta().bold().on_black()); |
| 55 | + run_command_with_progress("sudo", vec!["apt", "update"], "Updating APT repositories"); |
| 56 | + run_command_with_progress("sudo", vec!["apt", "upgrade", "-y"], "Upgrading APT packages"); |
| 57 | + run_command_with_progress("flatpak", vec!["update", "-y"], "Updating Flatpak packages"); |
| 58 | + // Removed snap refresh |
| 59 | + run_command_with_progress("fwupdmgr", vec!["update"], "Updating firmware"); |
| 60 | + run_command_with_progress("omz", vec!["update"], "Updating Oh-My-Zsh"); |
| 61 | + // Immutable update: update in snapshot |
| 62 | + let snapshot_dir = "/var/cache/hacker/"; |
| 63 | + let timestamp = chrono::Utc::now().format("%Y%m%d%H%M%S").to_string(); |
| 64 | + let new_snapshot = format!("{}/update-snapshot-{}", snapshot_dir, timestamp); |
| 65 | + run_command_with_progress("sudo", vec!["btrfs", "subvolume", "snapshot", "/", &new_snapshot], "Creating update snapshot"); |
| 66 | + run_command_with_progress("sudo", vec!["chroot", &new_snapshot, "/usr/share/HackerOS/apt", "upgrade", "-y"], "Upgrading in snapshot"); |
| 67 | + run_command_with_progress("sudo", vec!["btrfs", "subvolume", "set-default", &new_snapshot], "Setting update snapshot as default"); |
| 68 | + println!("{}", "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓".green().bold().on_black()); |
| 69 | + println!("{}", "┃ System Update Complete ┃".green().bold().on_black()); |
| 70 | + println!("{}", "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛".green().bold().on_black()); |
| 71 | +} |
| 72 | +pub fn handle_cybersecurity() { |
| 73 | + println!("{}", "========== Installing Penetration Tools ==========".cyan().bold().on_black()); |
| 74 | + run_command_with_progress("flatpak", vec!["remote-add", "--if-not-exists", "flathub", "https://dl.flathub.org/repo/flathub.flatpakrepo"], "Adding flathub repo"); |
| 75 | + run_command_with_progress("sudo", vec!["apt", "install", "-y", "nmap", "wireshark", "nikto", "john", "hydra", "aircrack-ng", "sqlmap", "ettercap-text-only", "tcpdump", "zmap", "bettercap", "wfuzz", "hashcat", "fail2ban", "rkhunter", "chkrootkit", "lynis", "clamav", "tor", "proxychains4", "httrack", "sublist3r", "macchanger", "inxi", "htop", "openvas", "openvpn"], "Installing cybersecurity tools"); |
| 76 | + // Removed Metasploit snap |
| 77 | + println!("{}", "========== Installing Ghidra ==========".cyan().bold().on_black()); |
| 78 | + run_command_with_progress("flatpak", vec!["install", "-y", "flathub", "org.ghidra_sre.Ghidra"], "Installing Ghidra"); |
| 79 | + println!("{}", "========== Hacker-Unpack-Cybersecurity Complete ==========".green().bold().on_black()); |
| 80 | +} |
| 81 | +pub fn handle_gaming() { |
| 82 | + println!("{}", "========== Installing Gaming Tools ==========".cyan().bold().on_black()); |
| 83 | + run_command_with_progress("flatpak", vec!["remote-add", "--if-not-exists", "flathub", "https://dl.flathub.org/repo/flathub.flatpakrepo"], "Adding flathub repo"); |
| 84 | + run_command_with_progress("sudo", vec!["apt", "install", "-y", "obs-studio", "lutris"], "Installing OBS Studio and Lutris"); |
| 85 | + run_command_with_progress("flatpak", vec!["install", "-y", "flathub", "com.valvesoftware.Steam"], "Installing Steam"); |
| 86 | + run_command_with_progress("flatpak", vec!["install", "-y", "flathub", "io.github.giantpinkrobots.varia"], "Installing Pika Torrent"); |
| 87 | + run_command_with_progress("flatpak", vec!["install", "-y", "flathub", "net.davidotek.pupgui2"], "Installing ProtonUp-Qt"); |
| 88 | + run_command_with_progress("flatpak", vec!["install", "-y", "flathub", "com.heroicgameslauncher.hgl", "protontricks", "com.discordapp.Discord"], "Installing Heroic Games Launcher, Protontricks, and Discord"); |
| 89 | + run_command_with_progress("flatpak", vec!["install", "--user", "https://sober.vinegarhq.org/sober.flatpakref"], "Installing Roblox"); |
| 90 | + run_command_with_progress("flatpak", vec!["install", "-y", "flathub", "org.vinegarhq.Vinegar"], "Installing Roblox Studio"); |
| 91 | + println!("{}", "========== Hacker-Unpack-Gaming Complete ==========".green().bold().on_black()); |
| 92 | +} |
0 commit comments