Made command use command line args

This commit is contained in:
Skye Bleed 2019-09-03 10:23:13 -05:00
parent bd22812bfa
commit b2a06332d1
3 changed files with 22 additions and 12 deletions

1
etag Normal file
View File

@ -0,0 +1 @@
"5d5860c2-180adc"

5
scripts/build.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
cargo build --release
cp target/release/i .

View File

@ -1,9 +1,6 @@
extern crate flate2;
extern crate tar;
use flate2::read::GzDecoder;
use tar::Archive;
use std::fs::File;
use reqwest::Client;
@ -12,7 +9,14 @@ use reqwest::header::ETAG;
fn main() -> Result<(), std::io::Error> {
let client = Client::new();
let mut resp = client.get("http://mirrors.advancedhosters.com/archlinux/core/os/x86_64/bash-5.0.009-1-x86_64.pkg.tar.xz")
let args: Vec<_> = std::env::args().collect();
if args.len() < 2 {
println!("Please enter a package name...");
}
let split = args[1].as_str().split("::");
let vec: Vec<&str> = split.collect();
let mut resp = client.get(vec[0])
.send().expect("Failed to make request");
if resp.status().is_success() {
@ -20,16 +24,16 @@ fn main() -> Result<(), std::io::Error> {
std::fs::write("etag", etag.as_bytes()).expect("Failed to write ETAG...");
}
let mut file = File::create("/imperfect/repo/arch/tarballs/bash.pkg.tar.xz").expect("file creation failed. Did you setup arch? Do you have permission?");
let mut file = match File::create(format!("/imperfect/repo/{}/tarballs/bash.pkg.tar.xz", vec[1])) {
Ok(res) => res,
Err(_) => {
println!("Failed to create file...did you setup arch? Do you have permission to create files?");
std::process::exit(1);
}
};
resp.copy_to(&mut file).expect("failed to write file");
}
let path = "/imperfect/pkgs/tarballs/bash.pkg.tar.xz";
let tar_gz = File::open(path).expect("Failed to open tar file...");
let tar = GzDecoder::new(tar_gz);
let mut archive = Archive::new(tar);
archive.unpack("/imperfect/pkgs/tarball").expect("Could not unpack tarball");
Ok(())
}