Mutzi
1c235d1949
All checks were successful
Gitea Organization/dotfiles/pipeline/pr-installer This commit looks good
35 lines
1.3 KiB
Rust
35 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 GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802";
|
|
|
|
pub fn check_for_updates(version: &str) {
|
|
print!("Checking for updates... ");
|
|
let resp: serde_json::Value = attohttpc::get("https://gitea.mattv.de/api/v1/repos/root/dotfiles/branches/installer")
|
|
.header("accept", "application/json")
|
|
.header("Authorization", format!("token {GITEA_KEY}"))
|
|
.send().unwrap().json().unwrap();
|
|
let newest = resp["commit"]["id"].as_str().unwrap();
|
|
if newest != version {
|
|
println!("New version {newest}");
|
|
let exe = current_exe().unwrap();
|
|
let temp = Path::new("temp");
|
|
|
|
print!("Downloading... ");
|
|
attohttpc::get(format!("https://gitea.mattv.de/api/packages/root/generic/installer/{newest}/installer-amd64"))
|
|
.header("Authorization", format!("token {GITEA_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");
|
|
} |