mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
fix issue where boot label reverts on quirk change
This commit is contained in:
committed by
Aiden McClelland
parent
4960aeedad
commit
604d0ae052
@@ -88,40 +88,40 @@ fn display_update_result(status: WithRevision<UpdateResult>, _: &ArgMatches<'_>)
|
|||||||
const HEADER_KEY: &str = "x-eos-hash";
|
const HEADER_KEY: &str = "x-eos-hash";
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum WritableDrives {
|
pub enum WritableDrives {
|
||||||
Green,
|
Green,
|
||||||
Blue,
|
Blue,
|
||||||
}
|
}
|
||||||
impl WritableDrives {
|
impl WritableDrives {
|
||||||
fn label(&self) -> &'static str {
|
pub fn label(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Green => "green",
|
Self::Green => "green",
|
||||||
Self::Blue => "blue",
|
Self::Blue => "blue",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn block_dev(&self) -> &'static Path {
|
pub fn block_dev(&self) -> &'static Path {
|
||||||
Path::new(match self {
|
Path::new(match self {
|
||||||
Self::Green => "/dev/mmcblk0p3",
|
Self::Green => "/dev/mmcblk0p3",
|
||||||
Self::Blue => "/dev/mmcblk0p4",
|
Self::Blue => "/dev/mmcblk0p4",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn part_uuid(&self) -> &'static str {
|
pub fn part_uuid(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Green => "cb15ae4d-03",
|
Self::Green => "cb15ae4d-03",
|
||||||
Self::Blue => "cb15ae4d-04",
|
Self::Blue => "cb15ae4d-04",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn as_fs(&self) -> impl FileSystem {
|
pub fn as_fs(&self) -> impl FileSystem {
|
||||||
BlockDev::new(self.block_dev())
|
BlockDev::new(self.block_dev())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will be where we are going to be putting the new update
|
/// This will be where we are going to be putting the new update
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
struct NewLabel(WritableDrives);
|
pub struct NewLabel(pub WritableDrives);
|
||||||
|
|
||||||
/// This is our current label where the os is running
|
/// This is our current label where the os is running
|
||||||
struct CurrentLabel(WritableDrives);
|
pub struct CurrentLabel(pub WritableDrives);
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref PARSE_COLOR: Regex = Regex::new("LABEL=(\\w+)[ \t]+/").unwrap();
|
static ref PARSE_COLOR: Regex = Regex::new("LABEL=(\\w+)[ \t]+/").unwrap();
|
||||||
@@ -259,7 +259,7 @@ async fn do_update(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[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")
|
let output = tokio::fs::read_to_string("/etc/fstab")
|
||||||
.await
|
.await
|
||||||
.with_ctx(|_| (crate::ErrorKind::Filesystem, "/etc/fstab"))?;
|
.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()
|
new_label.0.label()
|
||||||
))
|
))
|
||||||
.arg(mounted.as_ref().join("etc/fstab"))
|
.arg(mounted.as_ref().join("etc/fstab"))
|
||||||
.output()
|
.invoke(crate::ErrorKind::Filesystem)
|
||||||
.await?;
|
.await?;
|
||||||
mounted.unmount().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")
|
Command::new("sed")
|
||||||
.arg("-i")
|
.arg("-i")
|
||||||
.arg(&format!(
|
.arg(&format!(
|
||||||
@@ -455,7 +464,7 @@ async fn swap_boot_label(new_label: NewLabel) -> Result<(), Error> {
|
|||||||
new_label.0.part_uuid()
|
new_label.0.part_uuid()
|
||||||
))
|
))
|
||||||
.arg(Path::new(BOOT_RW_PATH).join("cmdline.txt"))
|
.arg(Path::new(BOOT_RW_PATH).join("cmdline.txt"))
|
||||||
.output()
|
.invoke(crate::ErrorKind::Filesystem)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
UPDATED.store(true, Ordering::SeqCst);
|
UPDATED.store(true, Ordering::SeqCst);
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use emver::VersionRange;
|
use emver::VersionRange;
|
||||||
|
use tokio::process::Command;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::disk::quirks::{fetch_quirks, save_quirks, update_quirks};
|
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);
|
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
|
&*v0_3_0::V0_3_0_COMPAT
|
||||||
}
|
}
|
||||||
async fn up<Db: DbHandle>(&self, _db: &mut Db) -> Result<(), Error> {
|
async fn up<Db: DbHandle>(&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?;
|
let mut q = fetch_quirks().await?;
|
||||||
update_quirks(&mut q).await?;
|
update_quirks(&mut q).await?;
|
||||||
save_quirks(&q).await?;
|
save_quirks(&q).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user