diff --git a/pack b/pack new file mode 100755 index 0000000..6ce8a8e Binary files /dev/null and b/pack differ diff --git a/src/main.rs b/src/main.rs index 714d450..f57136c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::fs::File; use std::path::Path; +use std::io::Read; use reqwest::Client; use reqwest::header::ETAG; @@ -11,22 +12,26 @@ fn main() -> Result<(), std::io::Error> { let args: Vec<_> = std::env::args().collect(); if args.len() < 2 { - println!("Please enter a package name..."); + println!("[PACK]: Please enter a package name..."); + std::process::exit(1); } let split = args[1].as_str().split("::"); let vec: Vec<&str> = split.collect(); - println!("Downloading {}", vec[0]); + println!("[PACK]: Downloading {}", vec[0]); if !Path::new(format!("/usr/pack/repo/{}", vec[1]).as_str()).exists() { - println!("Path /usr/pack/repo/{} does not exist. Please setup your environment.", vec[1]); + println!("[PACK]: Path /usr/pack/repo/{} does not exist. Please setup your environment.", vec[1]); std::process::exit(1); } print!("Making request..."); let mut resp = client.get(vec[0]) .send().expect("Failed to make request"); + + let full_path: Vec<&str> = vec[0].split("/").collect(); + let pkgname = full_path[full_path.len() - 1]; if resp.status().is_success() { println!("OK"); @@ -34,10 +39,11 @@ fn main() -> Result<(), std::io::Error> { std::fs::write("etag", etag.as_bytes()).expect("Failed to write ETAG..."); } - let mut file = match File::create(format!("/usr/pack/{}/tarballs/bash.pkg.tar.xz", vec[1])) { + let mut file = match File::create(format!("/usr/pack/repo/{}/tarballs/{}", vec[1], pkgname)) { Ok(res) => res, - Err(_) => { - println!("Failed to create file...did you setup arch? Do you have permission to create files?"); + Err(e) => { + println!("Failed to create file...did you setup you environment? Do you have permission to create files?"); + println!("\nError: {}", e); std::process::exit(1); } }; @@ -48,7 +54,7 @@ fn main() -> Result<(), std::io::Error> { std::process::exit(1); } - let archive = File::open(format!("/usr/pack/repo/{}/tarballs/bash.pkg.tar.xz")).expect("Failed to open tar..."); + let mut archive = File::open(format!("/usr/pack/repo/{}/tarballs/{}", vec[1], pkgname)).expect("Failed to open tar..."); let mut tar = Vec::new(); archive.read_to_end(&mut tar).expect("Failed to read tar...");