Fix the run-in-chroot check

main^2
trivernis 2 years ago
parent eb88743d01
commit 4ad2700f06
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `configure-locale` # Applies all system changes of `configure-locale`
def main [cfg] { def main [cfg] {
echo "Executing up task `configure-locale` with config" $cfg echo "Executing up task `configure-locale` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `configure-network` # Applies all system changes of `configure-network`
def main [cfg] { def main [cfg] {
echo "Executing up task `configure-network` with config" $cfg echo "Executing up task `configure-network` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `configure-unakite` # Applies all system changes of `configure-unakite`
def main [cfg] { def main [cfg] {
echo "Executing up task `configure-unakite` with config" $cfg echo "Executing up task `configure-unakite` with config" $cfg

@ -1,4 +1,3 @@
let REQUIRES_CHROOT = true;
# Applies all system changes of `install-base` # Applies all system changes of `install-base`
def main [cfg] { def main [cfg] {
echo "Executing up task `install-base` with config" $cfg echo "Executing up task `install-base` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `install-bootloader` # Applies all system changes of `install-bootloader`
def main [cfg] { def main [cfg] {
echo "Executing up task `install-bootloader` with config" $cfg echo "Executing up task `install-bootloader` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `install-desktop` # Applies all system changes of `install-desktop`
def main [cfg] { def main [cfg] {
echo "Executing up task `install-desktop` with config" $cfg echo "Executing up task `install-desktop` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `install-extra-packages` # Applies all system changes of `install-extra-packages`
def main [cfg] { def main [cfg] {
echo "Executing up task `install-extra-packages` with config" $cfg echo "Executing up task `install-extra-packages` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `install-flatpak` # Applies all system changes of `install-flatpak`
def main [cfg] { def main [cfg] {
echo "Executing up task `install-flatpak` with config" $cfg echo "Executing up task `install-flatpak` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `install-kernels` # Applies all system changes of `install-kernels`
def main [cfg] { def main [cfg] {
echo "Executing up task `install-kernels` with config" $cfg echo "Executing up task `install-kernels` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `install-timeshift` # Applies all system changes of `install-timeshift`
def main [cfg] { def main [cfg] {
echo "Executing up task `install-timeshift` with config" $cfg echo "Executing up task `install-timeshift` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `install-zramd` # Applies all system changes of `install-zramd`
def main [cfg] { def main [cfg] {
echo "Executing up task `install-zramd` with config" $cfg echo "Executing up task `install-zramd` with config" $cfg

@ -1,3 +1,4 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `setup-root-user` # Applies all system changes of `setup-root-user`
def main [cfg] { def main [cfg] {
echo "Executing up task `setup-root-user` with config" $cfg echo "Executing up task `setup-root-user` with config" $cfg

@ -1,5 +1,5 @@
let RUN_IN_CHROOT = true;
# Applies all system changes of `setup-users` # Applies all system changes of `setup-users`
def main [cfg] { def main [cfg] {
echo "Executing up task `setup-users` with config" $cfg echo "Executing up task `setup-users` with config" $cfg
echo $TRM_CONFIG
} }

@ -144,7 +144,7 @@ impl Mapping {
.await .await
.map_err(|e| ChrootError::Link(src.to_owned(), e))?; .map_err(|e| ChrootError::Link(src.to_owned(), e))?;
Ok(MappingHandle::Link(LinkDrop { 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))?; .map_err(|e| ChrootError::Copy(src.to_owned(), e))?;
} }
fs::copy(src, dst) if src.exists() {
.await fs::copy(src, dst)
.map_err(|e| ChrootError::Copy(src.to_owned(), e))?; .await
.map_err(|e| ChrootError::Copy(src.to_owned(), e))?;
}
Ok(MappingHandle::None) Ok(MappingHandle::None)
} }

@ -54,7 +54,7 @@ impl ExecBuilder {
/// Returns if the script needs to be run inside the new root /// Returns if the script needs to be run inside the new root
pub fn requires_chroot(&self) -> bool { pub fn requires_chroot(&self) -> bool {
self.ctx self.ctx
.get_var("run_in_chroot") .get_var("RUN_IN_CHROOT")
.and_then(|v| v.as_bool().ok()) .and_then(|v| v.as_bool().ok())
.unwrap_or(false) .unwrap_or(false)
} }

@ -63,12 +63,20 @@ impl TaskExecutor {
#[tracing::instrument(level = "trace", skip_all)] #[tracing::instrument(level = "trace", skip_all)]
pub async fn execute(&mut self) -> Result<()> { pub async fn execute(&mut self) -> Result<()> {
self.tasks.sort_by(Task::compare); self.tasks.sort_by(Task::compare);
let chroot = Chroot::create(&*ROOT_MNT).await?; let mut chroot = None;
for task in &self.tasks { for task in &self.tasks {
if let Some(up_task) = task.up(&self.os_config)? { if let Some(up_task) = task.up(&self.os_config)? {
if up_task.requires_chroot() { 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 { } else {
up_task.exec()?; up_task.exec()?;
} }

Loading…
Cancel
Save