|
|
|
|
@@ -6,27 +6,31 @@ use std::path::Path;
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct Pipeline {
|
|
|
|
|
sha: String
|
|
|
|
|
struct PackageEntry {
|
|
|
|
|
version: String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
struct PackageEntry {
|
|
|
|
|
version: String,
|
|
|
|
|
pipeline: Pipeline
|
|
|
|
|
}
|
|
|
|
|
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<PackageEntry> = 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 resp: Vec<PackageEntry> = 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::<u64>().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://gitlab.mattv.de/api/v4/projects/43/packages/generic/installer/{}/installer-amd64", newest.version)).send().unwrap().write_to(File::create(temp).unwrap()).unwrap();
|
|
|
|
|
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();
|
|
|
|
|
|