Updated to jenkins and gitea (#4)
All checks were successful
Gitea Organization/dotfiles/pipeline/head This commit looks good

Co-authored-by: Mutzi <root@mattv.de>
Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
2023-02-12 22:36:01 +00:00
parent 39f08615d8
commit 00a38cbf03
7 changed files with 37 additions and 39 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!("GIT_COMMIT") {
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

@@ -3,30 +3,25 @@ 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
}
const GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802";
pub fn check_for_updates(version: &str) {
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: serde_json::Value = attohttpc::get("https://gitea.mattv.de/api/v1/repos/root/dotfiles/branches/installer")
.header("accept", "application/json")
.header("Authorization", format!("token {GITEA_KEY}"))
.send().unwrap().json().unwrap();
let newest = resp["commit"]["id"].as_str().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();