diff --git a/crates/rugpi-ctrl/src/cli.rs b/crates/rugpi-ctrl/src/cli.rs index 816f7fa..775aef4 100644 --- a/crates/rugpi-ctrl/src/cli.rs +++ b/crates/rugpi-ctrl/src/cli.rs @@ -22,6 +22,8 @@ use rugpi_common::{ use tempdir::TempDir; use xscript::{run, Run}; +use crate::overlay::overlay_dir; + pub fn main() -> Anyhow<()> { let args = Args::parse(); match &args.command { @@ -47,13 +49,21 @@ pub fn main() -> Anyhow<()> { }, }, Command::Update(update_cmd) => match update_cmd { - UpdateCommand::Install { image, no_reboot } => { + UpdateCommand::Install { + image, + no_reboot, + keep_overlay, + } => { let hot_partitions = get_hot_partitions()?; let default_partitions = get_default_partitions()?; let spare_partitions = default_partitions.flipped(); if hot_partitions != default_partitions { bail!("Hot partitions are not the default!"); } + if !keep_overlay { + let spare_overlay_dir = overlay_dir(spare_partitions); + fs::remove_dir_all(spare_overlay_dir).ok(); + } let loop_device = LoopDevice::attach(image)?; println!("Formatting partitions..."); let boot_label = format!("BOOT-{}", spare_partitions.as_str().to_uppercase()); @@ -231,8 +241,12 @@ pub enum UpdateCommand { Install { /// Path to the image. image: String, + /// Prevent Rugpi from rebooting the system. #[clap(long)] no_reboot: bool, + /// Do not delete an existing overlay. + #[clap(long)] + keep_overlay: bool, }, } diff --git a/crates/rugpi-ctrl/src/main.rs b/crates/rugpi-ctrl/src/main.rs index d66114b..ac664e8 100644 --- a/crates/rugpi-ctrl/src/main.rs +++ b/crates/rugpi-ctrl/src/main.rs @@ -3,6 +3,7 @@ use rugpi_common::Anyhow; pub mod cli; pub mod config; pub mod init; +pub mod overlay; pub mod state; pub fn main() -> Anyhow<()> { diff --git a/crates/rugpi-ctrl/src/overlay.rs b/crates/rugpi-ctrl/src/overlay.rs new file mode 100644 index 0000000..735cd72 --- /dev/null +++ b/crates/rugpi-ctrl/src/overlay.rs @@ -0,0 +1,8 @@ +use std::path::{Path, PathBuf}; + +use rugpi_common::partitions::PartitionSet; + +/// Get the overlay directory for the given partition set. +pub fn overlay_dir(partitions: PartitionSet) -> PathBuf { + Path::new("/run/rugpi/state/overlay").join(partitions.as_str()) +}