Skip to content

Commit

Permalink
quark: Implement run command
Browse files Browse the repository at this point in the history
  • Loading branch information
MaloPolese committed May 1, 2022
1 parent 915d73b commit b8450e4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ Cargo.lock
.idea
*.tar.gz
.vscode
ctr-bundle
ctr-bundle
quardle*
lumper*
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
clap = { version = "3.0.5", features = ["derive"] }
execute = "0.2.10"
flate2 = "1.0.22"
tar = "0.4.38"
28 changes: 28 additions & 0 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -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 :
Expand All @@ -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(())
}
}

0 comments on commit b8450e4

Please sign in to comment.