meow
This commit is contained in:
parent
9670deab55
commit
98c5feaaee
5 changed files with 9 additions and 54 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ use std::env;
|
|||
use std::path::PathBuf;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 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<dyn std::error::Error>> {
|
|||
}
|
||||
};
|
||||
|
||||
// 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<dyn std::error::Error>> {
|
|||
}
|
||||
}
|
||||
|
||||
// Pakete herunterladen + Live-MD5 prüfen
|
||||
downloader::download_files(&wget_list, &lfs_sources, package_mirror, Some(&md5_map))?;
|
||||
|
||||
println!("{} All done!", style("🎉").green().bold());
|
||||
|
|
|
|||
|
|
@ -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<String, Box<dyn std::error::Error>> {
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
|
|
@ -14,5 +8,3 @@ pub fn get_md5sums() -> Result<String, Box<dyn std::error::Error>> {
|
|||
.text()?;
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
33
src/mirrors
33
src/mirrors
|
|
@ -1,33 +0,0 @@
|
|||
use console::Style;
|
||||
use std::io::{self, Write};
|
||||
|
||||
pub fn choose_package_mirror() -> Option<String> {
|
||||
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::<usize>().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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -9,7 +9,11 @@ pub fn choose_package_mirror() -> Option<String> {
|
|||
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<String> {
|
|||
|
||||
fn fetch_mirrors() -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue