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