summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHibby <hibby@debian.org>2026-06-26 21:52:33 +0100
committerHibby <hibby@debian.org>2026-06-26 21:52:33 +0100
commit4dfeca51f9dcad91edd255198272e4aa640f4e47 (patch)
tree25aaa0a82557f5275375aa44f4bcb129a6b0ccce
parent1232c9ca398de19ce1ed31337bffd98d4c7e69aa (diff)
arm64: keep sudo alive, reclaim work/ space, prune old images
- Prime sudo and run a background keep-alive so the post-build chown no longer blocks on a hidden password prompt after the long build expires the credential cache. - Remove the multi-GB pi-gen work/ tree once the image is in deploy/. - Prune deploy/ to the newest 2 dated images on every run.
-rwxr-xr-xbuild-arm64.sh20
-rwxr-xr-xbuild-helpers.sh28
2 files changed, 48 insertions, 0 deletions
diff --git a/build-arm64.sh b/build-arm64.sh
index 1061f9d..43c3bfc 100755
--- a/build-arm64.sh
+++ b/build-arm64.sh
@@ -49,6 +49,16 @@ else
# ---- RUN YOUR PI-GEN BUILD HERE ----
# Adjust this to your actual invocation
+ # Prime sudo and keep the credential cache alive for the whole run. The
+ # pi-gen build runs for far longer than sudo's default timeout, so without
+ # this the later chown would silently block on a password prompt that has
+ # been redirected into the logfile.
+ log_step "arm64: priming sudo credentials"
+ sudo -v
+ ( while true; do sudo -n true; sleep 60; kill -0 "$$" 2>/dev/null || exit; done ) &
+ SUDO_KEEPALIVE_PID=$!
+ trap 'kill "$SUDO_KEEPALIVE_PID" 2>/dev/null || true' EXIT
+
log_step "arm64: running pi-gen build"
pushd "$PI_GEN_DIR" >/dev/null
sudo CLEAN=1 ./build.sh >> "$LOGFILE" 2>&1
@@ -72,9 +82,19 @@ else
mv "$IMG" "$FINAL_IMG" >> "$LOGFILE" 2>&1
IMG_FILE="$FINAL_IMG"
+
+ # The image is safely in deploy/ now; reclaim the huge pi-gen work tree.
+ log_step "arm64: cleaning pi-gen work directory"
+ clean_pi_gen_work "$PI_GEN_DIR" >> "$LOGFILE" 2>&1
fi
# -----------------------------
+# 2b) Retention: keep newest 2 local images
+# -----------------------------
+log_step "arm64: pruning old local images (keeping newest 2)"
+prune_old_images "$BUILD_DIR" 2 >> "$LOGFILE" 2>&1
+
+# -----------------------------
# 3) Transfer IMG to main server
# -----------------------------
log_step "arm64: transferring $(basename "$IMG_FILE") to $REMOTE:$REMOTE_DIR"
diff --git a/build-helpers.sh b/build-helpers.sh
index d51ac21..0e52735 100755
--- a/build-helpers.sh
+++ b/build-helpers.sh
@@ -753,6 +753,34 @@ run_sync() {
echo "Sync complete"
}
+clean_pi_gen_work() {
+ # pi-gen leaves a multi-GB "work/" tree behind after a build (one subdir per
+ # stage, each containing a full rootfs). The only artifacts we keep live in
+ # deploy/, so wipe everything else the build generated to reclaim disk.
+ # work/ is created by the sudo build, so it is root-owned.
+ local pi_gen_dir="$1"
+
+ if [[ -d "$pi_gen_dir/work" ]]; then
+ echo "Removing pi-gen work directory: $pi_gen_dir/work"
+ sudo rm -rf "$pi_gen_dir/work"
+ fi
+}
+
+prune_old_images() {
+ # Keep the newest N dated images in a directory, deleting older ones along
+ # with their sidecar checksum files. Filenames are expected to start with a
+ # YYYY-MM-DD date so the glob never matches "hibbian-latest"-style symlinks.
+ local dir="$1"
+ local keep="${2:-2}"
+
+ mapfile -t images < <(ls -t "$dir"/[0-9][0-9][0-9][0-9]-*.img 2>/dev/null)
+
+ for image in "${images[@]:$keep}"; do
+ echo "Removing old image: $(basename "$image")"
+ rm -f "$image" "$image.sha256"
+ done
+}
+
extract_date() {
local name="$1"