From e1f17f7e38629ec7be7c36d01ae034676a04b332 Mon Sep 17 00:00:00 2001 From: mia26MAjFm Date: Sat, 20 Jun 2026 12:43:53 -0400 Subject: [PATCH] fix: export CHROOT/DISTRO/KVER to build-rootfs.sh + sanity guard (#21) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dispatch in #20 ran build-rootfs.sh without exporting $CHROOT, so inside the script it was empty — meaning '/' expansions like `mv "$UNPACK/rootfs"/* "$CHROOT/"` resolved to '/' and the bazzite rootfs went into the build container's root. Container-contained, but the build failed with a confusing 'Device or resource busy' on /etc/resolv.conf. Two fixes: - entrypoint exports DISTRO/CHROOT/KVER/ROOT_LABEL/EFI_LABEL when calling the per-distro script, and asserts $CHROOT non-empty. - bazzite + batocera scripts have a top-of-file guard that bails if $CHROOT is unset, missing, or '/'. Co-authored-by: mia26MAjFm --- distros/batocera/build-rootfs.sh | 4 ++++ distros/bazzite/build-rootfs.sh | 4 ++++ docker/image-builder/entrypoint.sh | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/distros/batocera/build-rootfs.sh b/distros/batocera/build-rootfs.sh index 4cd645b..ecac5c4 100755 --- a/distros/batocera/build-rootfs.sh +++ b/distros/batocera/build-rootfs.sh @@ -13,6 +13,10 @@ set -ex +: "${CHROOT:?ERROR: \$CHROOT unset/empty}" +[ -d "$CHROOT" ] || { echo "ERROR: \$CHROOT=$CHROOT not a directory"; exit 2; } +case "$CHROOT" in /) echo "ERROR: refuse to operate on /"; exit 2 ;; esac + # Batocera is a Buildroot-based emulation distro. It ships as a # single .img.gz with FAT32 boot + ext4 SHARE partitions; the OS # itself lives in a squashfs file (`/boot/batocera`) on the FAT32. diff --git a/distros/bazzite/build-rootfs.sh b/distros/bazzite/build-rootfs.sh index 55ddccf..04a9e6f 100755 --- a/distros/bazzite/build-rootfs.sh +++ b/distros/bazzite/build-rootfs.sh @@ -11,6 +11,10 @@ set -ex +: "${CHROOT:?ERROR: \$CHROOT unset/empty}" +[ -d "$CHROOT" ] || { echo "ERROR: \$CHROOT=$CHROOT not a directory"; exit 2; } +case "$CHROOT" in /) echo "ERROR: refuse to operate on /"; exit 2 ;; esac + # Bazzite is an OCI atomic image; bypass distrobuilder entirely. # DISTRO=bazzite -> ghcr.io/ublue-os/bazzite:stable # DISTRO=bazzite-deck -> ghcr.io/ublue-os/bazzite-deck:stable diff --git a/docker/image-builder/entrypoint.sh b/docker/image-builder/entrypoint.sh index 4b8b024..42ae45b 100755 --- a/docker/image-builder/entrypoint.sh +++ b/docker/image-builder/entrypoint.sh @@ -32,8 +32,12 @@ elif [ -x "/repo/distros/${DISTRO}/build-rootfs.sh" ]; then # bypassed entirely. Most often used for OCI atomic images (bazzite via # skopeo+umoci) or pre-built rootfs images (batocera squashfs). echo "=== Building $DISTRO rootfs via distros/${DISTRO}/build-rootfs.sh ===" + [ -n "$CHROOT" ] || { echo "FATAL: \$CHROOT empty"; exit 1; } + mkdir -p "$CHROOT" rm -rf "$CHROOT"/* "$CHROOT"/.[!.]* 2>/dev/null || true - bash "/repo/distros/${DISTRO}/build-rootfs.sh" + DISTRO="$DISTRO" CHROOT="$CHROOT" KVER="$KVER" \ + ROOT_LABEL="$ROOT_LABEL" EFI_LABEL="$EFI_LABEL" \ + bash "/repo/distros/${DISTRO}/build-rootfs.sh" else echo "=== Building $DISTRO rootfs ===" # --- Stage files for distrobuilder's copy generators ---