Skip to content

Commit

Permalink
feat!: add option to keep the overlay on update (closes #7)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Previously, the overlay has been kept implicitly when
installing an update. Now, `--keep-overlay` must be used to keep the
overlay. Otherwise, it will be discarded.
  • Loading branch information
koehlma committed Nov 26, 2023
1 parent 6e069f1 commit 4453af7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/rugpi-ctrl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
Expand Down Expand Up @@ -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,
},
}

Expand Down
1 change: 1 addition & 0 deletions crates/rugpi-ctrl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
8 changes: 8 additions & 0 deletions crates/rugpi-ctrl/src/overlay.rs
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 4453af7

Please sign in to comment.