version checking
This commit is contained in:
parent
4511983e09
commit
18d5967b76
1 changed files with 11 additions and 0 deletions
11
src/main.rs
11
src/main.rs
|
@ -1,5 +1,6 @@
|
||||||
mod gitea;
|
mod gitea;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
@ -52,6 +53,15 @@ fn install_package(package: String) {
|
||||||
println!("EROR: Your home directory could not be found. Installation halted.");
|
println!("EROR: Your home directory could not be found. Installation halted.");
|
||||||
return;
|
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() {
|
if Path::new(&format!("{}/.local/share/curze/cache/{}/.curze/build.sh", home, realised_name)).exists() {
|
||||||
println!("NOTE: Building {}.", package);
|
println!("NOTE: Building {}.", package);
|
||||||
let result_of_build = Command::new("sh")
|
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))
|
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
||||||
.output();
|
.output();
|
||||||
if result_of_install.is_ok() {
|
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);
|
println!("NOTE: {} successfully installed!", package);
|
||||||
} else {
|
} else {
|
||||||
println!("EROR: Installation failed!");
|
println!("EROR: Installation failed!");
|
||||||
|
|
Reference in a new issue