From c7d82102ed7573cc920ed453311536063377b3e5 Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Thu, 11 May 2023 14:16:19 -0600 Subject: [PATCH] Bugfix/gpt reflash (#2266) * debug entry * update magic numbers * remove dbg * fix hostname * fix reinstall logic --- backend/src/bin/embassy-init.rs | 2 ++ backend/src/os_install/gpt.rs | 21 ++++++++++----------- backend/src/os_install/mbr.rs | 18 +++++++----------- backend/src/os_install/mod.rs | 2 ++ build/raspberrypi/init_resize.sh | 2 ++ 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/backend/src/bin/embassy-init.rs b/backend/src/bin/embassy-init.rs index d58bf7c80..aceeb6e83 100644 --- a/backend/src/bin/embassy-init.rs +++ b/backend/src/bin/embassy-init.rs @@ -55,6 +55,8 @@ async fn setup_or_init(cfg_path: Option) -> Result<(), Error> { .await .is_err() { + embassy::hostname::sync_hostname(&embassy::hostname::Hostname("embassy".into())).await?; + let ctx = SetupContext::init(cfg_path).await?; let server = WebServer::setup(([0, 0, 0, 0], 80).into(), ctx.clone()).await?; diff --git a/backend/src/os_install/gpt.rs b/backend/src/os_install/gpt.rs index 8d69ed83b..4139b4cf2 100644 --- a/backend/src/os_install/gpt.rs +++ b/backend/src/os_install/gpt.rs @@ -13,6 +13,7 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result Result= 33556480 { - if idx < 3 { - guid_part = Some(entry.clone()) - } - break; - } if part_info.guid.is_some() { - return Err(Error::new( - eyre!("Not enough space before embassy data"), - crate::ErrorKind::InvalidRequest, - )); + if entry.first_lba < if use_efi { 33759266 } else { 33570850 } { + return Err(Error::new( + eyre!("Not enough space before embassy data"), + crate::ErrorKind::InvalidRequest, + )); + } + guid_part = Some(entry.clone()); + break; } } } @@ -65,7 +64,7 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result Result= 33556480 { - if idx < 3 { - guid_part = - Some(std::mem::replace(entry, MBRPartitionEntry::empty())) - } - break; - } if part_info.guid.is_some() { - return Err(Error::new( - eyre!("Not enough space before embassy data"), - crate::ErrorKind::InvalidRequest, - )); + if entry.starting_lba < 33556480 { + return Err(Error::new( + eyre!("Not enough space before embassy data"), + crate::ErrorKind::InvalidRequest, + )); + } + guid_part = Some(std::mem::replace(entry, MBRPartitionEntry::empty())); } *entry = MBRPartitionEntry::empty(); } diff --git a/backend/src/os_install/mod.rs b/backend/src/os_install/mod.rs index 405a9050f..8b32acf20 100644 --- a/backend/src/os_install/mod.rs +++ b/backend/src/os_install/mod.rs @@ -232,6 +232,8 @@ pub async fn execute( .invoke(crate::ErrorKind::OpenSsh) .await?; + tokio::fs::write(current.join("etc/hostname"), "embassy\n").await?; + Command::new("chroot") .arg(¤t) .arg("ln") diff --git a/build/raspberrypi/init_resize.sh b/build/raspberrypi/init_resize.sh index b2ec58f86..b999550db 100755 --- a/build/raspberrypi/init_resize.sh +++ b/build/raspberrypi/init_resize.sh @@ -104,6 +104,8 @@ main () { return 1 fi + echo embassy > /etc/hostname + ln -sf /usr/lib/embassy/scripts/fake-apt /usr/local/bin/apt-get return 0