Compare commits

..

No commits in common. "cb8ef1e2e80effb6e8dd367dbbe2eb76483b1a0f" and "6fed41de0a66b6fdd60bf0de0bdc7b588df78a69" have entirely different histories.

4 changed files with 33 additions and 18 deletions

19
.gitlab-ci.yml Normal file
View 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

View File

@ -29,7 +29,7 @@ impl ToString for MainMenu {
} }
fn main() { fn main() {
if let Some(version) = option_env!("BUILD_NUMBER") { if let Some(version) = option_env!("CI_COMMIT_SHA") {
println!("Starting installer version {}", version); println!("Starting installer version {}", version);
update::check_for_updates(version); update::check_for_updates(version);
} else { } else {

View File

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

View File

@ -6,31 +6,27 @@ use std::path::Path;
use serde::Deserialize; use serde::Deserialize;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct PackageEntry { struct Pipeline {
version: String sha: String
} }
const GITEA_KEY: &str = "1e9527c38c98b297dbdaaf39c060e075b2729464"; #[derive(Debug, Deserialize)]
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://gitea.mattv.de/api/v1/packages/root?type=generic&q=installer") let resp: Vec<PackageEntry> = attohttpc::get("https://gitlab.mattv.de/api/v4/projects/43/packages?name=installer&sort=desc").send().unwrap().json().unwrap();
.header("accept", "application/json") let newest = resp.first().unwrap();
.header("Authorization", format!("token {GITEA_KEY}")) if newest.pipeline.sha != version {
.send().unwrap().json().unwrap(); println!("New version exists");
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://gitea.mattv.de/api/packages/root/generic/installer/{newest}/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();
.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();