From 4ad2700f06e73e615d5bf854dac6e1c727e43b6f Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 11 Mar 2023 17:44:40 +0100 Subject: [PATCH] Fix the run-in-chroot check --- configs/crystal/configure-locale/up.nu | 1 + configs/crystal/configure-network/up.nu | 1 + configs/crystal/configure-unakite/up.nu | 1 + configs/crystal/install-base/up.nu | 1 - configs/crystal/install-bootloader/up.nu | 1 + configs/crystal/install-desktop/up.nu | 1 + configs/crystal/install-extra-packages/up.nu | 1 + configs/crystal/install-flatpak/up.nu | 1 + configs/crystal/install-kernels/up.nu | 1 + configs/crystal/install-timeshift/up.nu | 1 + configs/crystal/install-zramd/up.nu | 1 + configs/crystal/setup-root-user/up.nu | 1 + configs/crystal/setup-users/up.nu | 2 +- src/task/chrooting/mapping.rs | 10 ++++++---- src/task/exec_builder.rs | 2 +- src/task/task_executor.rs | 12 ++++++++++-- 16 files changed, 29 insertions(+), 9 deletions(-) diff --git a/configs/crystal/configure-locale/up.nu b/configs/crystal/configure-locale/up.nu index 193ce9d..949cd64 100644 --- a/configs/crystal/configure-locale/up.nu +++ b/configs/crystal/configure-locale/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `configure-locale` def main [cfg] { echo "Executing up task `configure-locale` with config" $cfg diff --git a/configs/crystal/configure-network/up.nu b/configs/crystal/configure-network/up.nu index fdbf12c..2ffcb1a 100644 --- a/configs/crystal/configure-network/up.nu +++ b/configs/crystal/configure-network/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `configure-network` def main [cfg] { echo "Executing up task `configure-network` with config" $cfg diff --git a/configs/crystal/configure-unakite/up.nu b/configs/crystal/configure-unakite/up.nu index 9b2728a..d4dcc63 100644 --- a/configs/crystal/configure-unakite/up.nu +++ b/configs/crystal/configure-unakite/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `configure-unakite` def main [cfg] { echo "Executing up task `configure-unakite` with config" $cfg diff --git a/configs/crystal/install-base/up.nu b/configs/crystal/install-base/up.nu index ebe9889..3fbee4f 100644 --- a/configs/crystal/install-base/up.nu +++ b/configs/crystal/install-base/up.nu @@ -1,4 +1,3 @@ -let REQUIRES_CHROOT = true; # Applies all system changes of `install-base` def main [cfg] { echo "Executing up task `install-base` with config" $cfg diff --git a/configs/crystal/install-bootloader/up.nu b/configs/crystal/install-bootloader/up.nu index 5cf68ad..e38bdf8 100644 --- a/configs/crystal/install-bootloader/up.nu +++ b/configs/crystal/install-bootloader/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `install-bootloader` def main [cfg] { echo "Executing up task `install-bootloader` with config" $cfg diff --git a/configs/crystal/install-desktop/up.nu b/configs/crystal/install-desktop/up.nu index 82a6ceb..13b0a23 100644 --- a/configs/crystal/install-desktop/up.nu +++ b/configs/crystal/install-desktop/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `install-desktop` def main [cfg] { echo "Executing up task `install-desktop` with config" $cfg diff --git a/configs/crystal/install-extra-packages/up.nu b/configs/crystal/install-extra-packages/up.nu index 01c2b85..fad7ecd 100644 --- a/configs/crystal/install-extra-packages/up.nu +++ b/configs/crystal/install-extra-packages/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `install-extra-packages` def main [cfg] { echo "Executing up task `install-extra-packages` with config" $cfg diff --git a/configs/crystal/install-flatpak/up.nu b/configs/crystal/install-flatpak/up.nu index c8b8f88..ada0fd9 100644 --- a/configs/crystal/install-flatpak/up.nu +++ b/configs/crystal/install-flatpak/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `install-flatpak` def main [cfg] { echo "Executing up task `install-flatpak` with config" $cfg diff --git a/configs/crystal/install-kernels/up.nu b/configs/crystal/install-kernels/up.nu index 821a7c9..f385ba8 100644 --- a/configs/crystal/install-kernels/up.nu +++ b/configs/crystal/install-kernels/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `install-kernels` def main [cfg] { echo "Executing up task `install-kernels` with config" $cfg diff --git a/configs/crystal/install-timeshift/up.nu b/configs/crystal/install-timeshift/up.nu index 1f8fc39..fb907ed 100644 --- a/configs/crystal/install-timeshift/up.nu +++ b/configs/crystal/install-timeshift/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `install-timeshift` def main [cfg] { echo "Executing up task `install-timeshift` with config" $cfg diff --git a/configs/crystal/install-zramd/up.nu b/configs/crystal/install-zramd/up.nu index 7ccc0e2..02daee8 100644 --- a/configs/crystal/install-zramd/up.nu +++ b/configs/crystal/install-zramd/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `install-zramd` def main [cfg] { echo "Executing up task `install-zramd` with config" $cfg diff --git a/configs/crystal/setup-root-user/up.nu b/configs/crystal/setup-root-user/up.nu index 76ef853..c51015e 100644 --- a/configs/crystal/setup-root-user/up.nu +++ b/configs/crystal/setup-root-user/up.nu @@ -1,3 +1,4 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `setup-root-user` def main [cfg] { echo "Executing up task `setup-root-user` with config" $cfg diff --git a/configs/crystal/setup-users/up.nu b/configs/crystal/setup-users/up.nu index b8b65f8..b2bb378 100644 --- a/configs/crystal/setup-users/up.nu +++ b/configs/crystal/setup-users/up.nu @@ -1,5 +1,5 @@ +let RUN_IN_CHROOT = true; # Applies all system changes of `setup-users` def main [cfg] { echo "Executing up task `setup-users` with config" $cfg - echo $TRM_CONFIG } diff --git a/src/task/chrooting/mapping.rs b/src/task/chrooting/mapping.rs index 7ec2764..7ee65ce 100644 --- a/src/task/chrooting/mapping.rs +++ b/src/task/chrooting/mapping.rs @@ -144,7 +144,7 @@ impl Mapping { .await .map_err(|e| ChrootError::Link(src.to_owned(), e))?; Ok(MappingHandle::Link(LinkDrop { - path: src.to_owned(), + path: dst.to_owned(), })) } @@ -155,9 +155,11 @@ impl Mapping { .map_err(|e| ChrootError::Copy(src.to_owned(), e))?; } - fs::copy(src, dst) - .await - .map_err(|e| ChrootError::Copy(src.to_owned(), e))?; + if src.exists() { + fs::copy(src, dst) + .await + .map_err(|e| ChrootError::Copy(src.to_owned(), e))?; + } Ok(MappingHandle::None) } diff --git a/src/task/exec_builder.rs b/src/task/exec_builder.rs index 3260cae..14374cf 100644 --- a/src/task/exec_builder.rs +++ b/src/task/exec_builder.rs @@ -54,7 +54,7 @@ impl ExecBuilder { /// Returns if the script needs to be run inside the new root pub fn requires_chroot(&self) -> bool { self.ctx - .get_var("run_in_chroot") + .get_var("RUN_IN_CHROOT") .and_then(|v| v.as_bool().ok()) .unwrap_or(false) } diff --git a/src/task/task_executor.rs b/src/task/task_executor.rs index 399da04..b6ab060 100644 --- a/src/task/task_executor.rs +++ b/src/task/task_executor.rs @@ -63,12 +63,20 @@ impl TaskExecutor { #[tracing::instrument(level = "trace", skip_all)] pub async fn execute(&mut self) -> Result<()> { self.tasks.sort_by(Task::compare); - let chroot = Chroot::create(&*ROOT_MNT).await?; + let mut chroot = None; for task in &self.tasks { if let Some(up_task) = task.up(&self.os_config)? { if up_task.requires_chroot() { - chroot.run(|| up_task.exec()).await.unwrap()??; + if chroot.is_none() { + chroot = Some(Chroot::create(&*ROOT_MNT).await?); + } + chroot + .as_ref() + .unwrap() + .run(|| up_task.exec()) + .await + .unwrap()??; } else { up_task.exec()?; }