From 77b6e2aba3e3b486f5d560a9e67c0d34ea1fca49 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:21:44 +0100 Subject: [PATCH 01/19] Testing with Jenkins --- Jenkinsfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..551d922 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,13 @@ +pipeline { + agent none + stage('Build') { + agent { + docker { image 'rust:alpine' } + } + steps { + sh 'export' + sh 'cargo --release build' + sh 'ls -la' + } + } +} \ No newline at end of file From 0b7af4e3d79de8390fe27e46c7a9369843e1fe2b Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:22:46 +0100 Subject: [PATCH 02/19] Testing with Jenkins --- Jenkinsfile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 551d922..8d4520c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,13 +1,15 @@ pipeline { agent none - stage('Build') { - agent { - docker { image 'rust:alpine' } - } - steps { - sh 'export' - sh 'cargo --release build' - sh 'ls -la' + stages { + stage('Build') { + agent { + docker { image 'rust:alpine' } + } + steps { + sh 'export' + sh 'cargo --release build' + sh 'ls -la' + } } } } \ No newline at end of file From ff18cd16ceddd72e43b848a01b82be65c94a0a7a Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:40:40 +0100 Subject: [PATCH 03/19] Testing with Jenkins --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8d4520c..64baedc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,8 +6,7 @@ pipeline { docker { image 'rust:alpine' } } steps { - sh 'export' - sh 'cargo --release build' + sh 'cargo build --release' sh 'ls -la' } } From 21b30a441fb7ceced5df86685bb59659a531a549 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:44:02 +0100 Subject: [PATCH 04/19] Testing with Jenkins --- Jenkinsfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 64baedc..b2adb9d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,8 +5,12 @@ pipeline { agent { docker { image 'rust:alpine' } } + environment { + RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' + } steps { - sh 'cargo build --release' + sh 'apk add pkgconf musl-dev curl' + sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'ls -la' } } From c587705f5a632ddd4ae2dd03ff82196427b71f96 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 12:44:44 +0100 Subject: [PATCH 05/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b2adb9d..fd89c8b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' } steps { - sh 'apk add pkgconf musl-dev curl' + sh 'sudo apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'ls -la' } From 9798dfe5cbfe31710ebed077e23dce2de3fb3cd5 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 13:02:39 +0100 Subject: [PATCH 06/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index fd89c8b..b2adb9d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' } steps { - sh 'sudo apk add pkgconf musl-dev curl' + sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'ls -la' } From 5ad952d37e1848c4e6cbe7ffe86212ce29ec98d4 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 13:47:23 +0100 Subject: [PATCH 07/19] Testing with Jenkins --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b2adb9d..394ed41 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,11 +7,13 @@ pipeline { } environment { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' + TOKEN = credentials('00912d76-da44-4f04-890f-b11180e7a68f') } steps { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' - sh 'ls -la' + sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' + sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } From 181a2e37539c99176b87e40360cf26e44a28bca5 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 16:34:41 +0100 Subject: [PATCH 08/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 394ed41..8c2dc24 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { } environment { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' - TOKEN = credentials('00912d76-da44-4f04-890f-b11180e7a68f') + TOKEN = credentials('gitea-key') } steps { sh 'apk add pkgconf musl-dev curl' From a2bdd281cc87230d9bcced28d07ae9c92ab5984e Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 16:36:38 +0100 Subject: [PATCH 09/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8c2dc24..7c6e781 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { } environment { RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' - TOKEN = credentials('gitea-key') + TOKEN = credentials('abd7020c-43d6-485b-ae09-2f9b484d9c15') } steps { sh 'apk add pkgconf musl-dev curl' From 8461871d7a0b6e99e1e3b568478171d4355b204e Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 16:44:55 +0100 Subject: [PATCH 10/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7c6e781..a8f81c4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -v --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } From 4f09a0eb81fb8a29d74ba19c1081e031cd68e379 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sat, 11 Feb 2023 16:59:41 +0100 Subject: [PATCH 11/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a8f81c4..32a096f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -v --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/v1/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } From 5657c570df41f2d359dd5cb43e765a8977d407cf Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 22:13:29 +0100 Subject: [PATCH 12/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 32a096f..138c091 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/v1/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -s -v --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } From d5abe0c38a7d9369685ec7d6dbb122a15f7d0aa6 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 22:21:58 +0100 Subject: [PATCH 13/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 138c091..744083b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -s -v --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -s -v -H "Authorization: token ${TOKEN}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } From 6fed41de0a66b6fdd60bf0de0bdc7b588df78a69 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 22:36:36 +0100 Subject: [PATCH 14/19] Testing with Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 744083b..14b8caf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -s -v -H "Authorization: token ${TOKEN}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' } } } From 577d9519fab4bfb99986b2e80bbccdd4cc6f5137 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 22:39:29 +0100 Subject: [PATCH 15/19] Removed gitlab CI --- .gitlab-ci.yml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index e875bfd..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,19 +0,0 @@ -stages: - - build - -variables: - PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/installer" - -build: - stage: build - image: rust:alpine - rules: - - if: $CI_COMMIT_BRANCH == "installer" - script: - - apk add pkgconf musl-dev curl - - RUSTFLAGS='-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' cargo build --release --target x86_64-unknown-linux-musl - - cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64 - - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file installer-amd64 "${PACKAGE_REGISTRY_URL}/dev-$CI_COMMIT_SHA/installer-amd64"' - artifacts: - paths: - - installer-amd64 From cb8ef1e2e80effb6e8dd367dbbe2eb76483b1a0f Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 23:15:09 +0100 Subject: [PATCH 16/19] Switched update to gitea --- src/main.rs | 2 +- src/repository.rs | 2 +- src/update.rs | 28 ++++++++++++++++------------ 3 files changed, 18 insertions(+), 14 deletions(-) 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(); From 60fce326dd7365a36788d7ae2f7d7828ce7091ab Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 23:30:26 +0100 Subject: [PATCH 17/19] Use commit for version again --- Cargo.lock | 5 +++-- Cargo.toml | 1 + Jenkinsfile | 2 +- src/main.rs | 2 +- src/update.rs | 11 ++++------- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b41dc0..2dddb2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,7 @@ dependencies = [ "dialoguer", "indicatif", "serde", + "serde_json", "toml", ] @@ -354,9 +355,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" dependencies = [ "itoa", "ryu", diff --git a/Cargo.toml b/Cargo.toml index 7559aee..17f67b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" dialoguer = "0.10.3" indicatif = "0.17.3" toml = "0.6.0" +serde_json = "1.0.93" [dependencies.serde] version = "1.0.152" diff --git a/Jenkinsfile b/Jenkinsfile index 14b8caf..3c49e99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh 'apk add pkgconf musl-dev curl' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64' + sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${GIT_COMMIT}/installer-amd64' } } } diff --git a/src/main.rs b/src/main.rs index 9f23690..7592212 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!("BUILD_NUMBER") { + if let Some(version) = option_env!("GIT_COMMIT") { println!("Starting installer version {}", version); update::check_for_updates(version); } else { diff --git a/src/update.rs b/src/update.rs index 263f9c7..5fa13cc 100644 --- a/src/update.rs +++ b/src/update.rs @@ -10,19 +10,16 @@ struct PackageEntry { version: String } -const GITEA_KEY: &str = "1e9527c38c98b297dbdaaf39c060e075b2729464"; +const GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802"; pub fn check_for_updates(version: &str) { - let version: u64 = version.parse().unwrap(); print!("Checking for updates... "); - let resp: Vec = attohttpc::get("https://gitea.mattv.de/api/v1/packages/root?type=generic&q=installer") + 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.into_iter() - .map(|entry| entry.version.parse::().unwrap()) - .max().unwrap(); - if newest > version { + 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"); From 1c235d1949aec8a30cd1f11f365026941f8f2bc4 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Sun, 12 Feb 2023 23:32:30 +0100 Subject: [PATCH 18/19] Fixed warnings --- src/update.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/update.rs b/src/update.rs index 5fa13cc..73417b5 100644 --- a/src/update.rs +++ b/src/update.rs @@ -3,12 +3,6 @@ use std::fs; use std::fs::File; use std::os::unix::process::CommandExt; use std::path::Path; -use serde::Deserialize; - -#[derive(Debug, Deserialize)] -struct PackageEntry { - version: String -} const GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802"; From 208a4e9e7998aa999fe2bd4df690a6706bf94eec Mon Sep 17 00:00:00 2001 From: Mutzi Date: Mon, 13 Feb 2023 20:05:20 +0100 Subject: [PATCH 19/19] Use Jenkins for updates --- Cargo.lock | 43 +++++++++++++++---------------------------- Cargo.toml | 5 ++--- Jenkinsfile | 4 ++-- src/main.rs | 6 +++--- src/update.rs | 25 +++++++++++++------------ 5 files changed, 35 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2dddb2d..c169383 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,11 +8,10 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b85f766c20e6ae766956f7a2fcc4e0931e79a7e1f48b29132b5d647021114914" dependencies = [ + "base64", "http", "log", "rustls", - "serde", - "serde_json", "url", "webpki", "webpki-roots", @@ -24,6 +23,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "bitflags" version = "1.3.2" @@ -87,7 +92,6 @@ dependencies = [ "dialoguer", "indicatif", "serde", - "serde_json", "toml", ] @@ -317,12 +321,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "ryu" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" - [[package]] name = "sct" version = "0.7.0" @@ -353,22 +351,11 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" -dependencies = [ - "itoa", - "ryu", - "serde", -] - [[package]] name = "serde_spanned" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c68e921cef53841b8925c2abadd27c9b891d9613bdc43d6b823062866df38e8" +checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4" dependencies = [ "serde", ] @@ -427,9 +414,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "toml" -version = "0.6.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb9d890e4dc9298b70f740f615f2e05b9db37dce531f6b24fb77ac993f9f217" +checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6" dependencies = [ "serde", "serde_spanned", @@ -439,18 +426,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" +checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729bfd096e40da9c001f778f5cdecbd2957929a24e10e5883d9392220a751581" +checksum = "5e6a7712b49e1775fb9a7b998de6635b299237f48b404dde71704f2e0e7f37e5" dependencies = [ "indexmap", "nom8", diff --git a/Cargo.toml b/Cargo.toml index 17f67b6..efbd6d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,7 @@ edition = "2021" [dependencies] dialoguer = "0.10.3" indicatif = "0.17.3" -toml = "0.6.0" -serde_json = "1.0.93" +toml = "0.7.2" [dependencies.serde] version = "1.0.152" @@ -19,6 +18,6 @@ features = ["derive"] version = "0.24.0" default_features = false features = [ - "json", + "basic-auth", "tls-rustls-webpki-roots" ] diff --git a/Jenkinsfile b/Jenkinsfile index 3c49e99..644db0f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,10 +10,10 @@ pipeline { TOKEN = credentials('abd7020c-43d6-485b-ae09-2f9b484d9c15') } steps { - sh 'apk add pkgconf musl-dev curl' + sh 'apk add pkgconf musl-dev' sh 'cargo build --release --target x86_64-unknown-linux-musl' sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64' - sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${GIT_COMMIT}/installer-amd64' + archiveArtifacts artifacts: 'installer-amd64', allowEmptyArchive: false, onlyIfSuccessful: true } } } diff --git a/src/main.rs b/src/main.rs index 7592212..3da4ce8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,9 +29,9 @@ impl ToString for MainMenu { } fn main() { - if let Some(version) = option_env!("GIT_COMMIT") { - println!("Starting installer version {}", version); - update::check_for_updates(version); + if let (Some(version), Some(name)) = (option_env!("BUILD_ID"), option_env!("JOB_BASE_NAME")) { + println!("Starting installer version {name}-{version}"); + update::check_for_updates(version.parse().unwrap(), name); } else { println!("Starting installer version unknown"); } diff --git a/src/update.rs b/src/update.rs index 73417b5..779ab77 100644 --- a/src/update.rs +++ b/src/update.rs @@ -4,24 +4,25 @@ use std::fs::File; use std::os::unix::process::CommandExt; use std::path::Path; -const GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802"; +const JENKINS_KEY: &str = "1196373359a3f17bbb8f0f5685b8152276"; -pub fn check_for_updates(version: &str) { +pub fn check_for_updates(version: u64, name: &str) { print!("Checking for updates... "); - 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 newest: u64 = attohttpc::get(format!("https://jenkins.mattv.de/job/Gitea%20Organization/job/dotfiles/job/{name}/lastSuccessfulBuild/buildNumber")) + .basic_auth("root", Some(JENKINS_KEY)) + .send().unwrap() + .text().unwrap() + .parse().unwrap(); + if newest > version { + println!("New version {name}-{newest}"); let exe = current_exe().unwrap(); let temp = Path::new("temp"); print!("Downloading... "); - 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(); + attohttpc::get(format!("https://jenkins.mattv.de/job/Gitea%20Organization/job/dotfiles/job/{name}/{newest}/artifact/installer-amd64")) + .basic_auth("root", Some(JENKINS_KEY)) + .send().unwrap() + .write_to(File::create(temp).unwrap()).unwrap(); println!("Done"); fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap();