pack/src/main.rs

51 lines
1.6 KiB
Rust
Raw Normal View History

2019-09-03 23:17:02 +00:00
use std::result::Result;
2019-09-20 00:12:36 +00:00
use std::path::Path;
2019-09-03 10:37:49 +00:00
use reqwest::Client;
2019-09-20 00:12:36 +00:00
mod arch;
2019-09-04 23:04:18 +00:00
fn err_and_exit(msg: String, code: i32) {
println!("ERROR!: {}", msg);
std::process::exit(code);
}
2019-09-03 10:37:49 +00:00
fn main() -> Result<(), std::io::Error> {
let client = Client::new();
2019-09-03 15:23:13 +00:00
let args: Vec<_> = std::env::args().collect();
if args.len() < 2 {
2019-09-03 22:38:25 +00:00
println!("[PACK]: Please enter a package name...");
std::process::exit(1);
2019-09-03 15:23:13 +00:00
}
let split = args[1].as_str().split("::");
let vec: Vec<&str> = split.collect();
2019-09-04 23:04:18 +00:00
if vec.len() < 2 {
err_and_exit("Please enter a repo to download from!".to_string(), 0);
}
2019-09-20 00:12:36 +00:00
2019-09-03 22:38:25 +00:00
println!("[PACK]: Downloading {}", vec[0]);
2019-09-03 21:41:20 +00:00
if !Path::new(format!("/usr/pack/repo/{}", vec[1]).as_str()).exists() {
2019-09-04 23:04:18 +00:00
err_and_exit(format!("Path /usr/pack/repo/{} does not exist. Please setup your environment.", vec[1]), 1);
2019-09-03 15:44:47 +00:00
}
2019-09-03 22:38:25 +00:00
let full_path: Vec<&str> = vec[0].split("/").collect();
let pkgname = full_path[full_path.len() - 1];
2019-09-06 19:28:12 +00:00
let repo = match vec[1] { // get repo url based on command line argument
2019-09-04 16:46:44 +00:00
"arch_core" => "http://mirrors.advancedhosters.com/archlinux/core/os/x86_64/",
2019-09-06 00:03:12 +00:00
"arch_extra" => "http://mirrors.advancedhosters.com/archlinux/extra/os/x86_64/",
2019-09-06 19:28:12 +00:00
"arch_community" => "http://mirrors.advancedhosters.com/archlinux/community/os/x86_64/",
2019-09-20 00:12:36 +00:00
"void" => "http://mirror.clarkson.edu/voidlinux/current/x86_64-repodata",
2019-09-03 23:17:02 +00:00
_ => {
2019-09-04 23:04:18 +00:00
println!("ERROR!: Repo {} is not supported...", vec[1]);
2019-09-03 23:17:02 +00:00
std::process::exit(0);
},
};
2019-09-20 00:12:36 +00:00
arch::get_arch_pkg(repo, pkgname, vec, client);
2019-09-03 21:41:20 +00:00
2019-09-03 10:37:49 +00:00
Ok(())
2019-09-06 00:03:12 +00:00
}