extern crate alloc; use alloc::format; use alloc::string::String; use alloc::vec::Vec; use spin::Mutex; #[derive(Debug, Clone)] pub struct DebianPackage { pub name: &'static str, pub version: &'static str, pub size_kb: usize, pub description: &'static str, pub is_installed: bool, } pub static DEBIAN_REPO: Mutex<[DebianPackage; 10]> = Mutex::new([ DebianPackage { name: "neofetch", version: "7.1.0-4", size_kb: 128, description: "Fast, highly customizable system info script", is_installed: false }, DebianPackage { name: "curl", version: "7.88.1-10", size_kb: 420, description: "Command line tool for transferring data with URL syntax", is_installed: false }, DebianPackage { name: "htop", version: "3.2.2-1", size_kb: 310, description: "Interactive high-resolution process viewer", is_installed: false }, DebianPackage { name: "vim", version: "9.0.1378-2", size_kb: 1450, description: "Vi IMproved - enhanced vi text editor", is_installed: false }, DebianPackage { name: "git", version: "2.39.2-1", size_kb: 6800, description: "Fast, scalable, distributed revision control system", is_installed: false }, DebianPackage { name: "python3", version: "3.11.2-1", size_kb: 14200, description: "Interactive high-level object-oriented language", is_installed: false }, DebianPackage { name: "rustc", version: "1.70.0-1", size_kb: 48000, description: "Rust systems programming language compiler", is_installed: false }, DebianPackage { name: "gcc", version: "12.2.0-14", size_kb: 32000, description: "GNU C compiler suite", is_installed: false }, DebianPackage { name: "doom", version: "1.10-3", size_kb: 4500, description: "Classic retro 1993 3D arcade first-person shooter", is_installed: false }, DebianPackage { name: "snapd", version: "2.58.3-1", size_kb: 18500, description: "Daemon and tooling for transactional snap packages", is_installed: true }, ]); pub fn init() { // Initialize Debian APT package cache & mirrors let _repo = DEBIAN_REPO.lock(); } pub fn run_apt(args: &[&str]) -> Vec { let mut out = Vec::new(); if args.is_empty() { out.push(String::from("apt 2.6.1 (x86_64) - Debian APT Package Manager")); out.push(String::from("Usage: apt [command] [package]")); out.push(String::from("Commands:")); out.push(String::from(" update - Update list of available packages")); out.push(String::from(" install - Install a new Debian package")); out.push(String::from(" remove - Remove an installed package")); out.push(String::from(" list [--installed] - List packages")); out.push(String::from(" search - Search package names and descriptions")); out.push(String::from("Note: 'aptitude' is aliased with identical functionality.")); return out; } match args[0] { "update" => { out.push(String::from("Hit:1 http://deb.debian.org/debian bookworm InRelease")); out.push(String::from("Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]")); out.push(String::from("Get:3 http://security.debian.org/debian-security bookworm-security InRelease [48.0 kB]")); out.push(String::from("Get:4 http://deb.debian.org/debian bookworm/main Sources [9,634 kB]")); out.push(String::from("Get:5 http://deb.debian.org/debian bookworm/main amd64 Packages [8,780 kB]")); out.push(String::from("Fetched 18.5 MB in 1s (18.5 MB/s)")); out.push(String::from("Reading package lists... Done")); out.push(String::from("Building dependency tree... Done")); out.push(String::from("All 68,412 packages are up to date.")); } "install" => { if args.len() < 2 { out.push(String::from("E: Command line error: Must specify at least one package to install.")); return out; } let target = args[1]; let mut repo = DEBIAN_REPO.lock(); let mut found = false; for pkg in repo.iter_mut() { if pkg.name == target { found = true; if pkg.is_installed { out.push(format!("{} is already the newest version ({}).", pkg.name, pkg.version)); } else { out.push(String::from("Reading package lists... Done")); out.push(String::from("Building dependency tree... Done")); out.push(format!("The following NEW packages will be installed: {}", pkg.name)); out.push(format!("Need to get {} kB of archives.", pkg.size_kb)); out.push(format!("Get:1 http://deb.debian.org/debian bookworm/main amd64 {} amd64 {} [{} kB]", pkg.name, pkg.version, pkg.size_kb)); out.push(format!("Unpacking {} ({})...", pkg.name, pkg.version)); out.push(format!("Setting up {} ({})...", pkg.name, pkg.version)); out.push(format!("[+] Successfully installed {} into /bin/{}", pkg.name, pkg.name)); pkg.is_installed = true; } break; } } if !found { out.push(format!("E: Unable to locate package {}", target)); } } "remove" => { if args.len() < 2 { out.push(String::from("E: Must specify at least one package to remove.")); return out; } let target = args[1]; let mut repo = DEBIAN_REPO.lock(); let mut found = false; for pkg in repo.iter_mut() { if pkg.name == target { found = true; if !pkg.is_installed { out.push(format!("Package '{}' is not installed, so not removed", pkg.name)); } else { out.push(format!("Removing {} ({})...", pkg.name, pkg.version)); out.push(format!("[+] Successfully removed /bin/{}", pkg.name)); pkg.is_installed = false; } break; } } if !found { out.push(format!("E: Unable to locate package {}", target)); } } "list" => { let filter_installed = args.iter().any(|&a| a == "--installed"); let repo = DEBIAN_REPO.lock(); out.push(String::from("Listing packages... Done")); for pkg in repo.iter() { if filter_installed && !pkg.is_installed { continue; } let status = if pkg.is_installed { "[installed]" } else { "" }; out.push(format!("{}/bookworm {} amd64 {}", pkg.name, pkg.version, status)); } } "search" => { if args.len() < 2 { out.push(String::from("E: Must specify search keyword.")); return out; } let query = args[1]; let repo = DEBIAN_REPO.lock(); out.push(String::from("Sorting... Done")); out.push(String::from("Full Text Search... Done")); let mut hits = 0; for pkg in repo.iter() { if pkg.name.contains(query) || pkg.description.contains(query) { out.push(format!("{} - {}", pkg.name, pkg.description)); hits += 1; } } if hits == 0 { out.push(format!("No packages found matching '{}'", query)); } } cmd => { out.push(format!("apt: unknown command '{}'", cmd)); out.push(String::from("See 'apt --help' for available commands.")); } } out }