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 Pipeline { sha: String } #[derive(Debug, Deserialize)] struct PackageEntry { version: String, pipeline: Pipeline } pub fn check_for_updates(version: &str) { print!("Checking for updates... "); let resp: Vec = attohttpc::get("https://gitlab.mattv.de/api/v4/projects/43/packages?name=installer&sort=desc").send().unwrap().json().unwrap(); let newest = resp.first().unwrap(); if newest.pipeline.sha != version { println!("New version exists"); let exe = current_exe().unwrap(); let temp = Path::new("temp"); print!("Downloading... "); attohttpc::get(format!("https://gitlab.mattv.de/api/v4/projects/43/packages/generic/installer/{}/installer-amd64", newest.version)).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"); }