Compare commits
2 commits
25a07e8e7a
...
4a5435f1c8
Author | SHA1 | Date | |
---|---|---|---|
4a5435f1c8 | |||
dc82d9be9e |
3 changed files with 71 additions and 6 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -197,7 +197,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curze"
|
name = "curze"
|
||||||
version = "0.3.3"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"home",
|
"home",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "curze"
|
name = "curze"
|
||||||
version = "0.3.4"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
73
src/main.rs
73
src/main.rs
|
@ -16,6 +16,9 @@ struct Cli {
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// Downloads, builds and installs packages.
|
/// Downloads, builds and installs packages.
|
||||||
Install {
|
Install {
|
||||||
|
/// Force install even if there are updates.
|
||||||
|
#[arg(short, long)]
|
||||||
|
force: bool,
|
||||||
/// Packages to install.
|
/// Packages to install.
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
},
|
},
|
||||||
|
@ -29,6 +32,13 @@ enum Commands {
|
||||||
/// Packages to build.
|
/// Packages to build.
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
},
|
},
|
||||||
|
/// Downloads a package and uses git to checkout a specific branch or tag.
|
||||||
|
Checkout {
|
||||||
|
/// Package to checkout.
|
||||||
|
name: String,
|
||||||
|
/// Branch to grab.
|
||||||
|
branch: String,
|
||||||
|
},
|
||||||
/// Purges the package cache, freeing space.
|
/// Purges the package cache, freeing space.
|
||||||
Purge {},
|
Purge {},
|
||||||
}
|
}
|
||||||
|
@ -37,12 +47,12 @@ fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Some(Commands::Install { name }) => {
|
Some(Commands::Install { name, force }) => {
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
println!("EROR: No packages named for install.");
|
println!("EROR: No packages named for install.");
|
||||||
} else {
|
} else {
|
||||||
for package in name {
|
for package in name {
|
||||||
install_package(package.to_string());
|
install_package(package.to_string(), force.to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,12 +74,55 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(Commands::Checkout { name, branch }) => {
|
||||||
|
if name.is_empty() {
|
||||||
|
println!("EROR: No packages named for checkout.");
|
||||||
|
} else {
|
||||||
|
checkout_package(name.to_string(), branch.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
Some(Commands::Purge {}) => {purge_package_cache()}
|
Some(Commands::Purge {}) => {purge_package_cache()}
|
||||||
None => {println!("NOTE: Run curze help for subcommands and options.")}
|
None => {println!("NOTE: Run curze help for subcommands and options.")}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_package(package: String) {
|
fn checkout_package(package: String, branch: String) {
|
||||||
|
println!("NOTE: Checking if {} can be checked out.", package);
|
||||||
|
if gitea::is_package_installable(package.clone()) {
|
||||||
|
println!("NOTE: Preparing to checkout {} at {}.", package, branch);
|
||||||
|
let cache_result = handle_package_cache(package.clone());
|
||||||
|
if cache_result {
|
||||||
|
let realised_name = package.clone().replace("/",".");
|
||||||
|
let home_out = fetch_home_dir();
|
||||||
|
let home;
|
||||||
|
if home_out.is_some() {
|
||||||
|
home = home_out.unwrap().clone();
|
||||||
|
} else {
|
||||||
|
println!("EROR: Your home directory could not be found. Checkout halted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
println!("NOTE: Performing checkout of {}.", package);
|
||||||
|
let result_of_pull = Command::new("git")
|
||||||
|
.arg("checkout")
|
||||||
|
.arg(format!("{}", branch))
|
||||||
|
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
||||||
|
.output();
|
||||||
|
if result_of_pull.is_ok() {
|
||||||
|
println!("NOTE: Checkout successful.");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
println!("EROR: Checkout failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("EROR: {} is not a valid package! Checkout halted!", package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn install_package(package: String, force: bool) {
|
||||||
println!("NOTE: Checking if {} can be installed.", package);
|
println!("NOTE: Checking if {} can be installed.", package);
|
||||||
if gitea::is_package_installable(package.clone()) {
|
if gitea::is_package_installable(package.clone()) {
|
||||||
println!("NOTE: Preparing to install {}.", package);
|
println!("NOTE: Preparing to install {}.", package);
|
||||||
|
@ -85,7 +138,7 @@ fn install_package(package: String) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if Path::new(&format!("{}/.local/share/curze/{}.version", home, realised_name)).exists() {
|
if Path::new(&format!("{}/.local/share/curze/{}.version", home, realised_name)).exists() && !force {
|
||||||
let package_version_a = fs::read_to_string(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name)).unwrap_or("4294967295".to_string()).replace("\n","").replace("\r\n","");
|
let package_version_a = fs::read_to_string(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name)).unwrap_or("4294967295".to_string()).replace("\n","").replace("\r\n","");
|
||||||
let package_version = package_version_a.parse::<u32>().unwrap_or(0);
|
let package_version = package_version_a.parse::<u32>().unwrap_or(0);
|
||||||
let installed_version_a = fs::read_to_string(format!("{}/.local/share/curze/{}.version", home, realised_name)).unwrap_or("4294967295".to_string()).replace("\n","").replace("\r\n","");
|
let installed_version_a = fs::read_to_string(format!("{}/.local/share/curze/{}.version", home, realised_name)).unwrap_or("4294967295".to_string()).replace("\n","").replace("\r\n","");
|
||||||
|
@ -261,6 +314,18 @@ fn handle_package_cache(package: String) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if Path::new(&format!("{}/.local/share/curze/cache/{}/", home, realised_name)).exists() {
|
if Path::new(&format!("{}/.local/share/curze/cache/{}/", home, realised_name)).exists() {
|
||||||
|
println!("NOTE: Clearing potential unchanged files.");
|
||||||
|
let result_of_pull = Command::new("git")
|
||||||
|
.arg("reset")
|
||||||
|
.arg("--hard")
|
||||||
|
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
||||||
|
.output();
|
||||||
|
if result_of_pull.is_ok() {
|
||||||
|
println!("NOTE: Clear successful.");
|
||||||
|
} else {
|
||||||
|
println!("WARN: Clear failed. Upstream updates not downloaded. Installation will continue.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
println!("NOTE: Pulling latest changes of {}.", package);
|
println!("NOTE: Pulling latest changes of {}.", package);
|
||||||
let result_of_pull = Command::new("git")
|
let result_of_pull = Command::new("git")
|
||||||
.arg("pull")
|
.arg("pull")
|
||||||
|
|
Reference in a new issue