diff --git a/src/main.rs b/src/main.rs index f9421b9..9f23690 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ impl ToString for MainMenu { } fn main() { - if let Some(version) = option_env!("CI_COMMIT_SHA") { + if let Some(version) = option_env!("BUILD_NUMBER") { println!("Starting installer version {}", version); update::check_for_updates(version); } else { diff --git a/src/repository.rs b/src/repository.rs index 4ccfaaf..a88c68f 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -48,7 +48,7 @@ fn check_config() -> bool { fn clone_repo() -> bool { println!("Cloning repo..."); if !Path::new("repo").exists() { std::fs::create_dir("repo").unwrap(); } - git!("clone", "git@ssh.gitlab.mattv.de:root/dotfiles.git", ".").success() + git!("clone", "gitea@gitea.mattv.de:root/dotfiles.git", ".").success() && check_config() } diff --git a/src/update.rs b/src/update.rs index a20e201..263f9c7 100644 --- a/src/update.rs +++ b/src/update.rs @@ -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 = 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 = 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://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();