Compare commits
2 Commits
6fed41de0a
...
cb8ef1e2e8
Author | SHA1 | Date | |
---|---|---|---|
cb8ef1e2e8 | |||
577d9519fa |
@ -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
|
|
@ -29,7 +29,7 @@ impl ToString for MainMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let Some(version) = option_env!("CI_COMMIT_SHA") {
|
if let Some(version) = option_env!("BUILD_NUMBER") {
|
||||||
println!("Starting installer version {}", version);
|
println!("Starting installer version {}", version);
|
||||||
update::check_for_updates(version);
|
update::check_for_updates(version);
|
||||||
} else {
|
} else {
|
||||||
|
@ -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", "git@ssh.gitlab.mattv.de:root/dotfiles.git", ".").success()
|
git!("clone", "gitea@gitea.mattv.de:root/dotfiles.git", ".").success()
|
||||||
&& check_config()
|
&& check_config()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,27 +6,31 @@ use std::path::Path;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Pipeline {
|
struct PackageEntry {
|
||||||
sha: String
|
version: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
const GITEA_KEY: &str = "1e9527c38c98b297dbdaaf39c060e075b2729464";
|
||||||
struct PackageEntry {
|
|
||||||
version: String,
|
|
||||||
pipeline: Pipeline
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn check_for_updates(version: &str) {
|
pub fn check_for_updates(version: &str) {
|
||||||
|
let version: u64 = version.parse().unwrap();
|
||||||
print!("Checking for updates... ");
|
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 resp: Vec<PackageEntry> = attohttpc::get("https://gitea.mattv.de/api/v1/packages/root?type=generic&q=installer")
|
||||||
let newest = resp.first().unwrap();
|
.header("accept", "application/json")
|
||||||
if newest.pipeline.sha != version {
|
.header("Authorization", format!("token {GITEA_KEY}"))
|
||||||
println!("New version exists");
|
.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 exe = current_exe().unwrap();
|
||||||
let temp = Path::new("temp");
|
let temp = Path::new("temp");
|
||||||
|
|
||||||
print!("Downloading... ");
|
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");
|
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