diff --git a/.gitignore b/.gitignore index 53649aa..e7d56fa 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ Cargo.lock .idea *.tar.gz .vscode -ctr-bundle \ No newline at end of file +ctr-bundle +quardle* +lumper* diff --git a/Cargo.toml b/Cargo.toml index eee4325..b857627 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "3.0.5", features = ["derive"] } \ No newline at end of file +clap = { version = "3.0.5", features = ["derive"] } +execute = "0.2.10" +flate2 = "1.0.22" +tar = "0.4.38" diff --git a/src/cli/run.rs b/src/cli/run.rs index d2b5c0d..fafa6cf 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -1,6 +1,11 @@ use super::{Handler, Result}; use clap::Args; +extern crate execute; +use std::{fs::File, path::Path, process::Command}; + +use flate2::read::GzDecoder; +use tar::Archive; /// Arguments for `RunCommand` /// /// Usage : @@ -19,6 +24,29 @@ pub struct RunCommand { /// Method that will be called when the command is executed. impl Handler for RunCommand { fn handler(&self) -> Result<()> { + if !Path::new(&self.output).exists() { + let tar_gz = File::open(&self.quardle)?; + let tar = GzDecoder::new(tar_gz); + let mut archive = Archive::new(tar); + + println!("Unpacking quardle..."); + archive.unpack(&self.output)?; + println!("Done"); + } else { + println!("quardle already exists"); + } + + println!("Start lumper..."); + let mut child = Command::new("./lumper") + .arg("-k") + .arg(format!("{}/vmlinux.bin", &self.output)) + .arg("--initramfs") + .arg(format!("{}/initramfs.img", &self.output)) + .spawn() + .expect("lumper faild to start"); + + child.wait().expect("failed to wait on child"); + Ok(()) } }