use std::env::current_exe; use std::fs; use std::fs::File; use std::os::unix::process::CommandExt; use std::path::Path; const JENKINS_KEY: &str = "1196373359a3f17bbb8f0f5685b8152276"; pub fn check_for_updates(version: u64, name: &str) { print!("Checking for updates... "); let newest: u64 = attohttpc::get(format!("https://jenkins.mattv.de/job/Gitea%20Organization/job/dotfiles/job/{name}/lastSuccessfulBuild/buildNumber")) .basic_auth("root", Some(JENKINS_KEY)) .send().unwrap() .text().unwrap() .parse().unwrap(); if newest > version { println!("New version {name}-{newest}"); let exe = current_exe().unwrap(); let temp = Path::new("temp"); print!("Downloading... "); attohttpc::get(format!("https://jenkins.mattv.de/job/Gitea%20Organization/job/dotfiles/job/{name}/{newest}/artifact/installer-amd64")) .basic_auth("root", Some(JENKINS_KEY)) .send().unwrap() .write_to(File::create(temp).unwrap()).unwrap(); println!("Done"); fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap(); fs::rename(&temp, &exe).unwrap(); std::process::Command::new(exe).exec(); std::process::exit(1); } println!("No new version"); }