diff --git a/src/downloader.rs b/src/downloader.rs index a0f8f09..a4b2076 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -7,10 +7,8 @@ use std::thread; use console::style; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; -use md5; use reqwest::blocking::Client; -/// Prüft Datei gegen erwarteten MD5-Hash fn verify_md5(file_path: &Path, expected_hash: &str) -> bool { let mut f = match File::open(file_path) { Ok(f) => f, @@ -25,7 +23,6 @@ fn verify_md5(file_path: &Path, expected_hash: &str) -> bool { hex == expected_hash } -/// Download + Live-MD5-Prüfung pub fn download_files( wget_list: &str, target_dir: &Path, @@ -39,7 +36,6 @@ pub fn download_files( let client = Arc::new(Client::new()); let mp = Arc::new(MultiProgress::new()); - // Clone md5_map before the loop so we can move it into threads let md5_map = md5_map.cloned(); let mut handles = vec![]; @@ -106,7 +102,6 @@ pub fn download_files( pb.set_position(downloaded); } - // Live-MD5-Prüfung let status = if let Some(ref md5_map) = md5_map { if let Some(expected_hash) = md5_map.get(filename) { if verify_md5(&filepath, expected_hash) { diff --git a/src/main.rs b/src/main.rs index 7f3c525..6a0517d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ use std::env; use std::path::PathBuf; fn main() -> Result<(), Box> { - // LFS sources Pfad let lfs_sources = match env::var("LFS") { Ok(lfs) => PathBuf::from(lfs).join("sources"), Err(_) => { @@ -26,10 +25,8 @@ fn main() -> Result<(), Box> { } }; - // Mirror für Pakete auswählen let package_mirror = mirrors::choose_package_mirror(); - // Wget-Liste vom Original LFS-Mirror holen let wget_list = wget_list::get_wget_list()?; // MD5 Map vorbereiten @@ -42,7 +39,6 @@ fn main() -> Result<(), Box> { } } - // Pakete herunterladen + Live-MD5 prüfen downloader::download_files(&wget_list, &lfs_sources, package_mirror, Some(&md5_map))?; println!("{} All done!", style("🎉").green().bold()); diff --git a/src/md5_utils.rs b/src/md5_utils.rs index f13e040..3a31ac3 100644 --- a/src/md5_utils.rs +++ b/src/md5_utils.rs @@ -1,9 +1,3 @@ -use console::style; -use md5; -use std::fs::File; -use std::io::{BufRead, BufReader, Read}; -use std::path::Path; - pub fn get_md5sums() -> Result> { let client = reqwest::blocking::Client::builder() .redirect(reqwest::redirect::Policy::none()) @@ -14,5 +8,3 @@ pub fn get_md5sums() -> Result> { .text()?; Ok(res) } - - diff --git a/src/mirrors b/src/mirrors deleted file mode 100644 index ee199c6..0000000 --- a/src/mirrors +++ /dev/null @@ -1,33 +0,0 @@ -use console::Style; -use std::io::{self, Write}; - -pub fn choose_package_mirror() -> Option { - let mirrors = vec![ - "https://ftp.fau.de", - "https://mirror.kernel.org/linux", - "https://mirror.example.org/linux", - ]; - - println!("Optional: choose a mirror for source packages:"); - - for (i, mirror) in mirrors.iter().enumerate() { - println!(" [{}] {}", i + 1, mirror); - } - - print!("Enter number or press Enter for default: "); - io::stdout().flush().unwrap(); - - let mut input = String::new(); - io::stdin().read_line(&mut input).unwrap(); - let input = input.trim(); - - if input.is_empty() { - None - } else { - let choice = input.parse::().unwrap_or(1); - let chosen = mirrors.get(choice.saturating_sub(1)).unwrap_or(&mirrors[0]); - println!("Using package mirror: {}", Style::new().green().apply_to(chosen)); - Some(chosen.to_string()) - } -} - diff --git a/src/mirrors.rs b/src/mirrors.rs index 8d2645f..b488108 100644 --- a/src/mirrors.rs +++ b/src/mirrors.rs @@ -9,7 +9,11 @@ pub fn choose_package_mirror() -> Option { Err(e) => { println!("Failed to fetch mirrors: {}", e); // Fallback to a default list if fetching fails - vec!["ftp.fau.de".to_string(), "mirror.kernel.org".to_string(), "mirror.example.org".to_string()] + vec![ + "ftp.fau.de".to_string(), + "mirror.kernel.org".to_string(), + "mirror.example.org".to_string(), + ] } }; @@ -41,10 +45,11 @@ pub fn choose_package_mirror() -> Option { fn fetch_mirrors() -> Result, Box> { let client = Client::new(); - // Fetching from the LFS mirrors page as it lists mirrors for various projects, including GNU - let res = client.get("https://www.linuxfromscratch.org/lfs/mirrors.html#files").send()?.text()?; + let res = client + .get("https://www.linuxfromscratch.org/lfs/mirrors.html#files") + .send()? + .text()?; let document = Html::parse_document(&res); - // This selector targets links that are likely to be mirrors. Adjust if needed. let selector = Selector::parse("a[href^='http']").unwrap(); let mirrors = document .select(&selector)