Use Jenkins for updates
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user