Switched update to gitea
All checks were successful
Gitea Organization/dotfiles/pipeline/head This commit looks good
Gitea Organization/dotfiles/pipeline/pr-installer This commit looks good

This commit is contained in:
Mutzi 2023-02-12 23:15:09 +01:00
parent 577d9519fa
commit cb8ef1e2e8
3 changed files with 18 additions and 14 deletions

View File

@ -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 {

View File

@ -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()
}

View File

@ -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();