From 3929642167dfa4bf24224296a1f2c822b0c135bc Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 31 May 2026 18:06:31 -0600 Subject: [PATCH] pi-gen: clear leftover BUILD_DIR at startup (robust to killed builds) A SIGTERM/kill (e.g. `systemctl stop`) skips the EXIT-trap cleanup, leaving /var/tmp/wrolpi-build-pi-gen behind. The next build's `mv pi-gen-bookworm-arm64 wrolpi-build-pi-gen` would then nest into the stale dir and fail. Remove the leftover (and intermediate zip/unzip dir) at startup, mirroring the debian build, stripping immutable flags off blob files first. Co-Authored-By: Claude Opus 4.8 (1M context) --- pi-gen/build.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pi-gen/build.sh b/pi-gen/build.sh index 25edce87..3b617912 100755 --- a/pi-gen/build.sh +++ b/pi-gen/build.sh @@ -93,6 +93,14 @@ fi [[ -f "${BLOB_CACHE}/map-overview.pmtiles" && -s "${BLOB_CACHE}/map-overview.pmtiles" ]] || \ (echo "ERROR: Failed to download map overview!" && exit 1) +# Clear leftovers from a previous build before unpacking. The EXIT trap +# normally cleans up, but a SIGTERM/kill (e.g. `systemctl stop`) skips it and +# leaves BUILD_DIR behind -- the `mv` below would then nest the new tree inside +# the stale one and break the build. Strip the immutable flag off blob files +# first (the chroot sets chattr +i), or rm -rf cannot remove them. +chattr -i "${BUILD_DIR}"/work/*/stage*/rootfs/opt/wrolpi-blobs/* 2>/dev/null || : +rm -rf "${BUILD_DIR}" /var/tmp/pi-gen-bookworm-arm64 /var/tmp/bookworm-arm64.zip + # Get the latest pi-gen code. wget https://github.com/RPi-Distro/pi-gen/archive/refs/heads/bookworm-arm64.zip -O /var/tmp/bookworm-arm64.zip unzip /var/tmp/bookworm-arm64.zip -d /var/tmp