Compare commits
No commits in common. "208a4e9e7998aa999fe2bd4df690a6706bf94eec" and "a2bdd281cc87230d9bcced28d07ae9c92ab5984e" have entirely different histories.
208a4e9e79
...
a2bdd281cc
19
.gitlab-ci.yml
Normal file
19
.gitlab-ci.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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
|
44
Cargo.lock
generated
44
Cargo.lock
generated
@ -8,10 +8,11 @@ version = "0.24.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b85f766c20e6ae766956f7a2fcc4e0931e79a7e1f48b29132b5d647021114914"
|
checksum = "b85f766c20e6ae766956f7a2fcc4e0931e79a7e1f48b29132b5d647021114914"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
|
||||||
"http",
|
"http",
|
||||||
"log",
|
"log",
|
||||||
"rustls",
|
"rustls",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"url",
|
"url",
|
||||||
"webpki",
|
"webpki",
|
||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
@ -23,12 +24,6 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base64"
|
|
||||||
version = "0.13.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@ -321,6 +316,12 @@ dependencies = [
|
|||||||
"webpki",
|
"webpki",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sct"
|
name = "sct"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@ -352,10 +353,21 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_spanned"
|
name = "serde_json"
|
||||||
version = "0.6.1"
|
version = "1.0.91"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
|
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2c68e921cef53841b8925c2abadd27c9b891d9613bdc43d6b823062866df38e8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@ -414,9 +426,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.7.2"
|
version = "0.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6"
|
checksum = "4fb9d890e4dc9298b70f740f615f2e05b9db37dce531f6b24fb77ac993f9f217"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_spanned",
|
"serde_spanned",
|
||||||
@ -426,18 +438,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.6.1"
|
version = "0.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
|
checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_edit"
|
name = "toml_edit"
|
||||||
version = "0.19.3"
|
version = "0.18.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5e6a7712b49e1775fb9a7b998de6635b299237f48b404dde71704f2e0e7f37e5"
|
checksum = "729bfd096e40da9c001f778f5cdecbd2957929a24e10e5883d9392220a751581"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"nom8",
|
"nom8",
|
||||||
|
@ -8,7 +8,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
dialoguer = "0.10.3"
|
dialoguer = "0.10.3"
|
||||||
indicatif = "0.17.3"
|
indicatif = "0.17.3"
|
||||||
toml = "0.7.2"
|
toml = "0.6.0"
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "1.0.152"
|
version = "1.0.152"
|
||||||
@ -18,6 +18,6 @@ features = ["derive"]
|
|||||||
version = "0.24.0"
|
version = "0.24.0"
|
||||||
default_features = false
|
default_features = false
|
||||||
features = [
|
features = [
|
||||||
"basic-auth",
|
"json",
|
||||||
"tls-rustls-webpki-roots"
|
"tls-rustls-webpki-roots"
|
||||||
]
|
]
|
||||||
|
4
Jenkinsfile
vendored
4
Jenkinsfile
vendored
@ -10,10 +10,10 @@ pipeline {
|
|||||||
TOKEN = credentials('abd7020c-43d6-485b-ae09-2f9b484d9c15')
|
TOKEN = credentials('abd7020c-43d6-485b-ae09-2f9b484d9c15')
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'apk add pkgconf musl-dev'
|
sh 'apk add pkgconf musl-dev curl'
|
||||||
sh 'cargo build --release --target x86_64-unknown-linux-musl'
|
sh 'cargo build --release --target x86_64-unknown-linux-musl'
|
||||||
sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64'
|
sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64'
|
||||||
archiveArtifacts artifacts: 'installer-amd64', allowEmptyArchive: false, onlyIfSuccessful: true
|
sh 'curl --user root:${TOKEN} --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${BUILD_NUMBER}/installer-amd64'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,9 @@ impl ToString for MainMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let (Some(version), Some(name)) = (option_env!("BUILD_ID"), option_env!("JOB_BASE_NAME")) {
|
if let Some(version) = option_env!("CI_COMMIT_SHA") {
|
||||||
println!("Starting installer version {name}-{version}");
|
println!("Starting installer version {}", version);
|
||||||
update::check_for_updates(version.parse().unwrap(), name);
|
update::check_for_updates(version);
|
||||||
} else {
|
} else {
|
||||||
println!("Starting installer version unknown");
|
println!("Starting installer version unknown");
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ fn check_config() -> bool {
|
|||||||
fn clone_repo() -> bool {
|
fn clone_repo() -> bool {
|
||||||
println!("Cloning repo...");
|
println!("Cloning repo...");
|
||||||
if !Path::new("repo").exists() { std::fs::create_dir("repo").unwrap(); }
|
if !Path::new("repo").exists() { std::fs::create_dir("repo").unwrap(); }
|
||||||
git!("clone", "gitea@gitea.mattv.de:root/dotfiles.git", ".").success()
|
git!("clone", "git@ssh.gitlab.mattv.de:root/dotfiles.git", ".").success()
|
||||||
&& check_config()
|
&& check_config()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,26 +3,30 @@ use std::fs;
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
const JENKINS_KEY: &str = "1196373359a3f17bbb8f0f5685b8152276";
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct Pipeline {
|
||||||
|
sha: String
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check_for_updates(version: u64, name: &str) {
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct PackageEntry {
|
||||||
|
version: String,
|
||||||
|
pipeline: Pipeline
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_for_updates(version: &str) {
|
||||||
print!("Checking for updates... ");
|
print!("Checking for updates... ");
|
||||||
let newest: u64 = attohttpc::get(format!("https://jenkins.mattv.de/job/Gitea%20Organization/job/dotfiles/job/{name}/lastSuccessfulBuild/buildNumber"))
|
let resp: Vec<PackageEntry> = attohttpc::get("https://gitlab.mattv.de/api/v4/projects/43/packages?name=installer&sort=desc").send().unwrap().json().unwrap();
|
||||||
.basic_auth("root", Some(JENKINS_KEY))
|
let newest = resp.first().unwrap();
|
||||||
.send().unwrap()
|
if newest.pipeline.sha != version {
|
||||||
.text().unwrap()
|
println!("New version exists");
|
||||||
.parse().unwrap();
|
|
||||||
if newest > version {
|
|
||||||
println!("New version {name}-{newest}");
|
|
||||||
let exe = current_exe().unwrap();
|
let exe = current_exe().unwrap();
|
||||||
let temp = Path::new("temp");
|
let temp = Path::new("temp");
|
||||||
|
|
||||||
print!("Downloading... ");
|
print!("Downloading... ");
|
||||||
attohttpc::get(format!("https://jenkins.mattv.de/job/Gitea%20Organization/job/dotfiles/job/{name}/{newest}/artifact/installer-amd64"))
|
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();
|
||||||
.basic_auth("root", Some(JENKINS_KEY))
|
|
||||||
.send().unwrap()
|
|
||||||
.write_to(File::create(temp).unwrap()).unwrap();
|
|
||||||
println!("Done");
|
println!("Done");
|
||||||
|
|
||||||
fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap();
|
fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user