use std::env::current_exe; use std::fs; use std::fs::File; use std::os::unix::process::CommandExt; use std::path::Path; use serde::Deserialize; #[derive(Debug, Deserialize)] struct PackageEntry { version: String } const GITEA_KEY: &str = "1e9527c38c98b297dbdaaf39c060e075b2729464"; pub fn check_for_updates(version: &str) { let version: u64 = version.parse().unwrap(); print!("Checking for updates... "); let resp: Vec = attohttpc::get("https://gitea.mattv.de/api/v1/packages/root?type=generic&q=installer") .header("accept", "application/json") .header("Authorization", format!("token {GITEA_KEY}")) .send().unwrap().json().unwrap(); let newest = resp.into_iter() .map(|entry| entry.version.parse::().unwrap()) .max().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"); }