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