version checking

This commit is contained in:
abbie 2023-08-10 10:43:17 +01:00
parent 4511983e09
commit 18d5967b76
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C

View file

@ -1,5 +1,6 @@
mod gitea;
use clap::{Parser, Subcommand};
use std::fs;
use std::path::Path;
use std::process::Command;
@ -52,6 +53,15 @@ fn install_package(package: String) {
println!("EROR: Your home directory could not be found. Installation halted.");
return;
}
if Path::new(&format!("{}/.local/share/curze/{}.version", home, realised_name)).exists() {
let package_version = fs::read_to_string(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name)).unwrap_or("4294967295".to_string()).parse::<u32>().unwrap_or(4294967295);
let installed_version = fs::read_to_string(format!("{}/.local/share/curze/{}.version", home, realised_name)).unwrap_or("4294967295".to_string()).parse::<u32>().unwrap_or(4294967295);
if package_version == installed_version || installed_version > package_version {
println!("NOTE: No updates, installation halted.");
return;
}
}
if Path::new(&format!("{}/.local/share/curze/cache/{}/.curze/build.sh", home, realised_name)).exists() {
println!("NOTE: Building {}.", package);
let result_of_build = Command::new("sh")
@ -71,6 +81,7 @@ fn install_package(package: String) {
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
.output();
if result_of_install.is_ok() {
fs::copy(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name), format!("{}/.local/share/curze/{}.version", home, realised_name));
println!("NOTE: {} successfully installed!", package);
} else {
println!("EROR: Installation failed!");