summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHibby <hibby@Hibbys-MacBook-Air.local>2026-05-04 22:32:04 -0500
committerHibby <hibby@Hibbys-MacBook-Air.local>2026-05-04 22:32:04 -0500
commitc47d8437b7be5144b7cf72fd7d5789a3d34383b5 (patch)
tree8a2754f4c24a8bfa7b3df1ca90f7e9990f6b7d5b
parent65c447d20aea2c402ae8093e740a215bdae846ad (diff)
Clean stale ISOs before publishing live-build output
-rwxr-xr-xbuild.sh50
1 files changed, 44 insertions, 6 deletions
diff --git a/build.sh b/build.sh
index 9943f2c..b2b7d83 100755
--- a/build.sh
+++ b/build.sh
@@ -38,15 +38,38 @@ run_build() {
cd "$WORKDIR/config"
- # Run live-build config
- echo "Running lb config..." >> "$LOGFILE"
- lb config >> "$LOGFILE" 2>&1
+ # Run live-build config
+ echo "Running lb config..." >> "$LOGFILE"
+ lb config >> "$LOGFILE" 2>&1
+
+ echo "Cleaning previous live-build binary output..." >> "$LOGFILE"
+ sudo lb clean --binary >> "$LOGFILE" 2>&1
# Build (must be root)
echo "Running lb build..." >> "$LOGFILE"
+ remove_existing_work_isos
+ BUILD_MARKER=$(mktemp "$WORKDIR/config/.hibbian-build-start.XXXXXX")
+ touch "$BUILD_MARKER"
run_live_build
log_step "lb build complete; starting post_build"
post_build
+ rm -f "$BUILD_MARKER"
+}
+
+remove_existing_work_isos() {
+ local stale_isos=()
+
+ mapfile -t stale_isos < <(find . -maxdepth 1 -type f -name '*.iso' -print 2>/dev/null | sort)
+
+ if (( ${#stale_isos[@]} == 0 )); then
+ return 0
+ fi
+
+ log_step "removing ${#stale_isos[@]} stale ISO(s) before live-build"
+
+ for iso in "${stale_isos[@]}"; do
+ rm -f "$iso"
+ done
}
run_live_build() {
@@ -99,17 +122,32 @@ run_live_build() {
}
post_build() {
+ local iso_candidates=()
+
log_step "post_build: preparing output directories"
mkdir -p "$OUTPUT_DIR" "$AMD64_DIR" "$ARM64_DIR"
log_step "post_build: entering $WORKDIR/config"
cd "$WORKDIR/config"
- log_step "post_build: finding newest ISO"
- ISO=$(ls -t ./*.iso 2>/dev/null | head -n 1 || true)
+ log_step "post_build: finding ISO produced by this build"
+
+ if [[ -n "${BUILD_MARKER:-}" && -f "$BUILD_MARKER" ]]; then
+ mapfile -t iso_candidates < <(find . -maxdepth 1 -type f -name '*.iso' -newer "$BUILD_MARKER" -printf '%T@ %p\n' 2>/dev/null | sort -nr | cut -d' ' -f2-)
+ else
+ mapfile -t iso_candidates < <(find . -maxdepth 1 -type f -name '*.iso' -newermt "$TIMESTAMP 00:00:00" -printf '%T@ %p\n' 2>/dev/null | sort -nr | cut -d' ' -f2-)
+ fi
+
+ ISO="${iso_candidates[0]:-}"
if [[ -z "$ISO" ]]; then
- echo "ERROR: No ISO found!" >> "$LOGFILE"
+ echo "ERROR: live-build did not produce an ISO; refusing to publish a stale image" >> "$LOGFILE"
+ exit 1
+ fi
+
+ if (( ${#iso_candidates[@]} > 1 )); then
+ echo "ERROR: live-build produced multiple ISOs; refusing to guess which one to publish" >> "$LOGFILE"
+ printf ' %s\n' "${iso_candidates[@]}" >> "$LOGFILE"
exit 1
fi