Made command use command line args
This commit is contained in:
parent
bd22812bfa
commit
b2a06332d1
3 changed files with 22 additions and 12 deletions
1
etag
Normal file
1
etag
Normal file
|
@ -0,0 +1 @@
|
|||
"5d5860c2-180adc"
|
5
scripts/build.sh
Executable file
5
scripts/build.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
cargo build --release
|
||||
|
||||
cp target/release/i .
|
28
src/main.rs
28
src/main.rs
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue