Add post installation commands
This commit is contained in:
parent
1f689b683a
commit
14eaf86da2
@ -16,6 +16,13 @@ systems:
|
||||
- --yes
|
||||
current_dir: null
|
||||
env: {}
|
||||
post_install:
|
||||
- exe: sudo
|
||||
params:
|
||||
- apt
|
||||
- autoremove
|
||||
current_dir: null
|
||||
env: {}
|
||||
- name: Rustup
|
||||
install:
|
||||
exe: rustup
|
||||
|
@ -11,6 +11,7 @@ enum UpdateSteps {
|
||||
Fetch,
|
||||
Compile,
|
||||
Install,
|
||||
PostInstall,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -24,6 +25,7 @@ pub struct System {
|
||||
fetch: Option<Cmd>,
|
||||
compile: Option<Cmd>,
|
||||
install: Cmd,
|
||||
post_install: Option<Vec<Cmd>>,
|
||||
// deps or rDeps : Tree
|
||||
// exclusive_with : List
|
||||
}
|
||||
@ -51,6 +53,7 @@ impl From<&str> for UpdateSteps {
|
||||
"fetch" => UpdateSteps::Fetch,
|
||||
"compile" => UpdateSteps::Compile,
|
||||
"install" => UpdateSteps::Install,
|
||||
"post_install" => UpdateSteps::PostInstall,
|
||||
|
||||
_ => panic!("Step {} not recognized", value),
|
||||
}
|
||||
@ -64,6 +67,7 @@ impl From<&String> for UpdateSteps {
|
||||
"fetch" => UpdateSteps::Fetch,
|
||||
"compile" => UpdateSteps::Compile,
|
||||
"install" => UpdateSteps::Install,
|
||||
"post_install" => UpdateSteps::PostInstall,
|
||||
|
||||
_ => panic!("Step {} not recognized", value),
|
||||
}
|
||||
@ -74,10 +78,11 @@ impl Updater {
|
||||
fn new() -> Updater {
|
||||
let mut up = Updater { systems: vec![] };
|
||||
up.systems.push(System {
|
||||
name: "".into(),
|
||||
name: Default::default(),
|
||||
fetch: None,
|
||||
compile: None,
|
||||
install: Cmd::new(),
|
||||
post_install: None,
|
||||
});
|
||||
up
|
||||
}
|
||||
@ -117,11 +122,13 @@ impl Updater {
|
||||
}
|
||||
|
||||
fn update(&self, sys: &System, opt: &Opt) -> Result<()> {
|
||||
// TODO: compute once before calling this function, maybe?
|
||||
let steps = if opt.steps.is_empty() {
|
||||
vec![
|
||||
UpdateSteps::Fetch,
|
||||
UpdateSteps::Compile,
|
||||
UpdateSteps::Install,
|
||||
UpdateSteps::PostInstall,
|
||||
]
|
||||
} else {
|
||||
opt.steps.iter().map(|u| u.into()).collect()
|
||||
@ -136,6 +143,9 @@ impl Updater {
|
||||
if steps.contains(&UpdateSteps::Install) {
|
||||
sys.install(opt)?;
|
||||
}
|
||||
if steps.contains(&UpdateSteps::PostInstall) {
|
||||
sys.post_install(opt)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -148,6 +158,7 @@ impl System {
|
||||
let exit_status = cmd
|
||||
.execute(opt)
|
||||
.map_err(|err| MyError::new(MyErrorKind::Fetch, err, cmd.clone()))?;
|
||||
|
||||
if !exit_status.success() {
|
||||
return Err(MyError::new(
|
||||
MyErrorKind::Fetch,
|
||||
@ -165,9 +176,10 @@ impl System {
|
||||
let exit_status = cmd
|
||||
.execute(opt)
|
||||
.map_err(|err| MyError::new(MyErrorKind::Compile, err, cmd.clone()))?;
|
||||
|
||||
if !exit_status.success() {
|
||||
return Err(MyError::new(
|
||||
MyErrorKind::Fetch,
|
||||
MyErrorKind::Compile,
|
||||
io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)),
|
||||
cmd.clone(),
|
||||
));
|
||||
@ -181,15 +193,36 @@ impl System {
|
||||
let exit_status = cmd
|
||||
.execute(opt)
|
||||
.map_err(|err| MyError::new(MyErrorKind::Install, err, cmd.clone()))?;
|
||||
|
||||
if !exit_status.success() {
|
||||
return Err(MyError::new(
|
||||
MyErrorKind::Fetch,
|
||||
MyErrorKind::Install,
|
||||
io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)),
|
||||
cmd.clone(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn post_install(&self, opt: &Opt) -> Result<()> {
|
||||
if let Some(post_install) = &self.post_install {
|
||||
for cmd in post_install {
|
||||
let cmd = cmd.clone().prepare(opt);
|
||||
let exit_status = cmd
|
||||
.execute(opt)
|
||||
.map_err(|err| MyError::new(MyErrorKind::PostInstall, err, cmd.clone()))?;
|
||||
|
||||
if !exit_status.success() {
|
||||
return Err(MyError::new(
|
||||
MyErrorKind::PostInstall,
|
||||
io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)),
|
||||
cmd.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Cmd {
|
||||
|
@ -22,9 +22,10 @@ pub struct MyError {
|
||||
#[non_exhaustive]
|
||||
pub enum MyErrorKind {
|
||||
Config,
|
||||
Fetch, // TODO: merge into "Update" or "Command" type of error? => Have this as an other level of error?
|
||||
Compile, // TODO: merge into "Update" or "Command" type of error? => Have this as an other level of error?
|
||||
Install, // TODO: merge into "Update" or "Command" type of error? => Have this as an other level of error?
|
||||
Fetch,
|
||||
Compile,
|
||||
Install,
|
||||
PostInstall,
|
||||
}
|
||||
|
||||
impl MyError {
|
||||
@ -70,6 +71,12 @@ impl Display for MyError {
|
||||
self.cmd,
|
||||
self.source().unwrap()
|
||||
),
|
||||
MyErrorKind::PostInstall => write!(
|
||||
f,
|
||||
"Could not do the post_install command {}: {}",
|
||||
self.cmd,
|
||||
self.source().unwrap()
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user