Skip to main content

horto_os_ui_shared/steps/
s1_packages.rs

1//! reference: horto-os/scripts/s1_init_horto_os.sh
2use crate::context::{HostContext, PlannedAction};
3use crate::error::Result;
4use crate::kits::apt;
5use crate::step::Step;
6
7/// Install base cockpit packages (`s1`).
8pub struct S1Packages;
9
10/// Base packages from tip `s1_init_horto_os.sh` (`IoT` packages move to s2 when `IOT_LAN=y`).
11pub const S1_PACKAGES: &[&str] = &["cockpit", "cockpit-networkmanager"];
12
13impl Step for S1Packages {
14    fn id(&self) -> &'static str {
15        "s1"
16    }
17    fn title(&self) -> &'static str {
18        "Install base packages"
19    }
20    fn reference_script(&self) -> &'static str {
21        "s1_init_horto_os.sh"
22    }
23    fn step_version(&self) -> u32 {
24        2
25    }
26    fn is_done(&self, _ctx: &HostContext) -> bool {
27        S1_PACKAGES.iter().all(|p| apt::package_installed(p))
28    }
29    fn plan(&self, ctx: &mut HostContext) -> Result<Vec<PlannedAction>> {
30        ctx.plan_action("apt update");
31        ctx.plan_action(format!("apt install -y {}", S1_PACKAGES.join(" ")));
32        Ok(ctx.planned.clone())
33    }
34    fn apply(&self, ctx: &mut HostContext) -> Result<()> {
35        apt::apt_update(ctx)?;
36        apt::apt_install(ctx, S1_PACKAGES)?;
37        ctx.log("Step s1 complete: base packages installed.");
38        Ok(())
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn package_list_matches_script() {
48        assert_eq!(S1_PACKAGES, &["cockpit", "cockpit-networkmanager"]);
49    }
50}