feat: add some functionality to bootpkg
This commit is contained in:
parent
a0416cf6a9
commit
174bbe93ec
2 changed files with 24 additions and 14 deletions
|
@ -65,13 +65,13 @@ fn main() {
|
|||
|
||||
let mut tmp_dir = temp_dir();
|
||||
tmp_dir.push(format!("{}", Uuid::new_v4()));
|
||||
create_dir_all(&tmp_dir)
|
||||
.expect("Could not create tmp dir.");
|
||||
create_dir_all(&tmp_dir).expect("Could not create tmp dir.");
|
||||
|
||||
println!("** extracting pkgtar...");
|
||||
{
|
||||
let mut archive = tar::Archive::new(Cursor::new(pkg.data));
|
||||
archive.unpack(format!("{}/contents", &tmp_dir.to_str().unwrap()))
|
||||
archive
|
||||
.unpack(format!("{}/contents", &tmp_dir.to_str().unwrap()))
|
||||
.expect("Could not extract archive");
|
||||
}
|
||||
|
||||
|
@ -81,9 +81,16 @@ fn main() {
|
|||
println!("** running bootstrap commands...");
|
||||
let res_bootstrap = run_bootstrap(mani);
|
||||
println!("** removing temporary directory...");
|
||||
remove_dir_all(&tmp_dir)
|
||||
.expect(&*format!("Could not remove tmp dir: {}", &tmp_dir.to_str().unwrap()));
|
||||
exit(if res_bootstrap { println!("!! bootstrap success"); 0 } else { 1 })
|
||||
remove_dir_all(&tmp_dir).expect(&*format!(
|
||||
"Could not remove tmp dir: {}",
|
||||
&tmp_dir.to_str().unwrap()
|
||||
));
|
||||
exit(if res_bootstrap {
|
||||
println!("!! bootstrap success");
|
||||
0
|
||||
} else {
|
||||
1
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
println!("Unsupported command, allowed commands: strap.");
|
||||
|
|
|
@ -13,7 +13,7 @@ pub struct PKGR {
|
|||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Bootstrap {
|
||||
pub check_installed_commands: Vec<String>,
|
||||
pub commands: Vec<String>
|
||||
pub commands: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -30,7 +30,7 @@ pub fn mani_from_str(s: &str) -> Manifest<Option<PKGR>> {
|
|||
fs: mani.fs,
|
||||
bin: mani.bin,
|
||||
build: mani.build,
|
||||
pkgr: bmani.pkgr
|
||||
pkgr: bmani.pkgr,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,26 +41,29 @@ pub fn run_bootstrap(mani: Manifest<Option<PKGR>>) -> bool {
|
|||
std::process::Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(s.into())
|
||||
.spawn().expect("Could not spawn process.")
|
||||
.wait().expect("Could not wait for process.")
|
||||
.code().expect("Could not fetch exit code.")
|
||||
.spawn()
|
||||
.expect("Could not spawn process.")
|
||||
.wait()
|
||||
.expect("Could not wait for process.")
|
||||
.code()
|
||||
.expect("Could not fetch exit code.")
|
||||
}
|
||||
|
||||
for command in &bootstrap.check_installed_commands {
|
||||
if run_command(command) != 0 {
|
||||
println!("!! Command failed: {}", command);
|
||||
println!("!! Already installed.");
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for command in &bootstrap.commands {
|
||||
if run_command(command) != 0 {
|
||||
println!("!! Command failed: {}", command);
|
||||
println!("!! Bootstrap failed!!!");
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue