feat: implemented the whole process

This commit is contained in:
Didier Slof 2023-07-13 22:47:09 +02:00
parent 4bd99c44ec
commit e5cbd9f9e5
Signed by: didier
GPG key ID: 01E71F18AA4398E5
9 changed files with 64 additions and 25 deletions

View file

@ -12,8 +12,8 @@ pub struct PKGR {
#[derive(Serialize, Deserialize)]
pub struct Bootstrap {
check_installed_commands: Vec<String>,
commands: Vec<String>
pub check_installed_commands: Vec<String>,
pub commands: Vec<String>
}
#[derive(Serialize, Deserialize)]
@ -33,3 +33,34 @@ pub fn mani_from_str(s: &str) -> Manifest<Option<PKGR>> {
pkgr: bmani.pkgr
}
}
pub fn run_bootstrap(mani: Manifest<Option<PKGR>>) -> bool {
if let Some(pkgr) = mani.pkgr {
if let Some(bootstrap) = pkgr.bootstrap {
fn run_command<S: Into<String>>(s: S) -> i32 {
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.")
}
for command in &bootstrap.check_installed_commands {
if run_command(command) != 0 {
println!("!! Command failed: {}", command);
println!("!! Already installed.");
return false
}
}
for command in &bootstrap.commands {
if run_command(command) != 0 {
println!("!! Command failed: {}", command);
println!("!! Bootstrap failed!!!");
return false
}
}
}
}
return true
}