moar cool stuff like building
This commit is contained in:
parent
181dc07fc8
commit
d3eeaa7e1e
3 changed files with 115 additions and 16 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -197,7 +197,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curze"
|
name = "curze"
|
||||||
version = "0.2.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"home",
|
"home",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "curze"
|
name = "curze"
|
||||||
version = "0.2.0"
|
version = "0.3.1"
|
||||||
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
|
||||||
|
|
127
src/main.rs
127
src/main.rs
|
@ -14,16 +14,23 @@ struct Cli {
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// Installs a list of packages.
|
/// Downloads, builds and installs packages.
|
||||||
Install {
|
Install {
|
||||||
/// Packages to install.
|
/// Packages to install.
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
},
|
},
|
||||||
/// Uninstalls a list of packages.
|
/// Uninstalls packages.
|
||||||
Uninstall {
|
Uninstall {
|
||||||
/// Packages to uninstall.
|
/// Packages to uninstall.
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
},
|
},
|
||||||
|
/// Downloads and builds packages.
|
||||||
|
Build {
|
||||||
|
/// Packages to build.
|
||||||
|
name: Vec<String>,
|
||||||
|
},
|
||||||
|
/// Purges the package cache, freeing space.
|
||||||
|
Purge {},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -48,6 +55,16 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(Commands::Build { name }) => {
|
||||||
|
if name.is_empty() {
|
||||||
|
println!("EROR: No packages named for build.");
|
||||||
|
} else {
|
||||||
|
for package in name {
|
||||||
|
build_package(package.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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.")}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +72,7 @@ fn main() {
|
||||||
fn install_package(package: String) {
|
fn install_package(package: String) {
|
||||||
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 {}.", package);
|
println!("NOTE: Preparing to install {}.", package);
|
||||||
let cache_result = handle_package_cache(package.clone());
|
let cache_result = handle_package_cache(package.clone());
|
||||||
if cache_result {
|
if cache_result {
|
||||||
let realised_name = package.clone().replace("/",".");
|
let realised_name = package.clone().replace("/",".");
|
||||||
|
@ -88,17 +105,21 @@ fn install_package(package: String) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("NOTE: Installing {}.", package);
|
if Path::new(&format!("{}/.local/share/curze/cache/{}/.curze/install.sh", home, realised_name)).exists() {
|
||||||
let result_of_install = Command::new("sh")
|
println!("NOTE: Installing {}.", package);
|
||||||
.arg("-c")
|
let result_of_install = Command::new("sh")
|
||||||
.arg(".curze/install.sh")
|
.arg("-c")
|
||||||
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
.arg(".curze/install.sh")
|
||||||
.output();
|
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
||||||
if result_of_install.is_ok() {
|
.output();
|
||||||
let _ = fs::copy(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name), format!("{}/.local/share/curze/{}.version", home, realised_name));
|
if result_of_install.is_ok() {
|
||||||
println!("NOTE: {} successfully installed!", package);
|
let _ = 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!");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("EROR: Installation failed!");
|
println!("EROR: Install script not present. Installation halted.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -117,7 +138,7 @@ fn uninstall_package(package: String) {
|
||||||
if home_out.is_some() {
|
if home_out.is_some() {
|
||||||
home = home_out.unwrap().clone();
|
home = home_out.unwrap().clone();
|
||||||
} else {
|
} else {
|
||||||
println!("EROR: Your home directory could not be found. Installation halted.");
|
println!("EROR: Your home directory could not be found. Uninstallation halted.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +170,84 @@ fn uninstall_package(package: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_package(package: String) {
|
||||||
|
println!("NOTE: Checking if {} can be built.", package);
|
||||||
|
if gitea::is_package_installable(package.clone()) {
|
||||||
|
println!("NOTE: Preparing to build {}.", package);
|
||||||
|
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. Build 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, build 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")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(".curze/build.sh")
|
||||||
|
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
||||||
|
.output();
|
||||||
|
if result_of_build.is_ok() {
|
||||||
|
println!("NOTE: Build successful.");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
println!("EROR: Build unsuccessful.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("EROR: Build script not present. Build halted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("EROR: {} is not a valid package! Build halted!", package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn purge_package_cache() {
|
||||||
|
println!("NOTE: Purging package cache.");
|
||||||
|
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. Purge halted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result_purge = fs::remove_dir_all(format!("{}/.local/share/curze/cache", home));
|
||||||
|
if result_purge.is_ok() {
|
||||||
|
println!("NOTE: Purge successful. Reinitialising cache folder.");
|
||||||
|
let result_recr = fs::create_dir(format!("{}/.local/share/curze/cache", home));
|
||||||
|
if result_recr.is_ok() {
|
||||||
|
println!("NOTE: Reinit successful. Purge complete.");
|
||||||
|
} else {
|
||||||
|
println!("EROR: Reinit unsuccessful. Package management commands may fail.");
|
||||||
|
println!("EROR: Please manually recreate the {}/.local/share/curze/cache directory.", home);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("EROR: Purging package cache failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_package_cache(package: String) -> bool {
|
fn handle_package_cache(package: String) -> bool {
|
||||||
let realised_name = package.clone().replace("/",".");
|
let realised_name = package.clone().replace("/",".");
|
||||||
let home_out = fetch_home_dir();
|
let home_out = fetch_home_dir();
|
||||||
|
|
Reference in a new issue