dotfiles/src/update.rs
Mutzi 208a4e9e79
Some checks failed
Gitea Organization/dotfiles/pipeline/head This commit looks good
Gitea Organization/dotfiles/pipeline/pr-installer There was a failure building this commit
Use Jenkins for updates
2023-02-13 20:05:20 +01:00

36 lines
1.3 KiB
Rust

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");
}