diff --git a/backend/src/update/mod.rs b/backend/src/update/mod.rs index 0933210dc..f40316876 100644 --- a/backend/src/update/mod.rs +++ b/backend/src/update/mod.rs @@ -88,40 +88,40 @@ fn display_update_result(status: WithRevision, _: &ArgMatches<'_>) const HEADER_KEY: &str = "x-eos-hash"; #[derive(Debug, Clone, Copy)] -enum WritableDrives { +pub enum WritableDrives { Green, Blue, } impl WritableDrives { - fn label(&self) -> &'static str { + pub fn label(&self) -> &'static str { match self { Self::Green => "green", Self::Blue => "blue", } } - fn block_dev(&self) -> &'static Path { + pub fn block_dev(&self) -> &'static Path { Path::new(match self { Self::Green => "/dev/mmcblk0p3", Self::Blue => "/dev/mmcblk0p4", }) } - fn part_uuid(&self) -> &'static str { + pub fn part_uuid(&self) -> &'static str { match self { Self::Green => "cb15ae4d-03", Self::Blue => "cb15ae4d-04", } } - fn as_fs(&self) -> impl FileSystem { + pub fn as_fs(&self) -> impl FileSystem { BlockDev::new(self.block_dev()) } } /// This will be where we are going to be putting the new update #[derive(Debug, Clone, Copy)] -struct NewLabel(WritableDrives); +pub struct NewLabel(pub WritableDrives); /// This is our current label where the os is running -struct CurrentLabel(WritableDrives); +pub struct CurrentLabel(pub WritableDrives); lazy_static! { static ref PARSE_COLOR: Regex = Regex::new("LABEL=(\\w+)[ \t]+/").unwrap(); @@ -259,7 +259,7 @@ async fn do_update( } #[instrument] -async fn query_mounted_label() -> Result<(NewLabel, CurrentLabel), Error> { +pub async fn query_mounted_label() -> Result<(NewLabel, CurrentLabel), Error> { let output = tokio::fs::read_to_string("/etc/fstab") .await .with_ctx(|_| (crate::ErrorKind::Filesystem, "/etc/fstab"))?; @@ -445,9 +445,18 @@ async fn swap_boot_label(new_label: NewLabel) -> Result<(), Error> { new_label.0.label() )) .arg(mounted.as_ref().join("etc/fstab")) - .output() + .invoke(crate::ErrorKind::Filesystem) .await?; mounted.unmount().await?; + Command::new("sed") + .arg("-i") + .arg(&format!( + "s/PARTUUID=cb15ae4d-\\(03\\|04\\)/PARTUUID={}/g", + new_label.0.part_uuid() + )) + .arg(Path::new(BOOT_RW_PATH).join("cmdline.txt.orig")) + .invoke(crate::ErrorKind::Filesystem) + .await?; Command::new("sed") .arg("-i") .arg(&format!( @@ -455,7 +464,7 @@ async fn swap_boot_label(new_label: NewLabel) -> Result<(), Error> { new_label.0.part_uuid() )) .arg(Path::new(BOOT_RW_PATH).join("cmdline.txt")) - .output() + .invoke(crate::ErrorKind::Filesystem) .await?; UPDATED.store(true, Ordering::SeqCst); diff --git a/backend/src/version/v0_3_0_1.rs b/backend/src/version/v0_3_0_1.rs index ddac5714e..dd858ed27 100644 --- a/backend/src/version/v0_3_0_1.rs +++ b/backend/src/version/v0_3_0_1.rs @@ -1,7 +1,13 @@ +use std::path::Path; + use emver::VersionRange; +use tokio::process::Command; use super::*; use crate::disk::quirks::{fetch_quirks, save_quirks, update_quirks}; +use crate::disk::BOOT_RW_PATH; +use crate::update::query_mounted_label; +use crate::util::Invoke; const V0_3_0_1: emver::Version = emver::Version::new(0, 3, 0, 1); @@ -19,6 +25,16 @@ impl VersionT for Version { &*v0_3_0::V0_3_0_COMPAT } async fn up(&self, _db: &mut Db) -> Result<(), Error> { + let (_, current) = query_mounted_label().await?; + Command::new("sed") + .arg("-i") + .arg(&format!( + "s/PARTUUID=cb15ae4d-\\(03\\|04\\)/PARTUUID={}/g", + current.0.part_uuid() + )) + .arg(Path::new(BOOT_RW_PATH).join("cmdline.txt.orig")) + .invoke(crate::ErrorKind::Filesystem) + .await?; let mut q = fetch_quirks().await?; update_quirks(&mut q).await?; save_quirks(&q).await?;