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