diff options
| author | Hibby <hibby@Hibbys-MacBook-Air.local> | 2026-05-04 23:25:37 -0500 |
|---|---|---|
| committer | Hibby <hibby@Hibbys-MacBook-Air.local> | 2026-05-04 23:25:37 -0500 |
| commit | 3fa845d41d005d2c8d78fa74abfd5cb1282b968a (patch) | |
| tree | 3a57ab1df1b9a274e5751ec98bdaec322bbae898 | |
| parent | 31c9567b561448d6fa6ab2c2ef5926141364e0c7 (diff) | |
Sense check some functions and refactor a little
| -rwxr-xr-x | build-arm64.sh | 3 | ||||
| -rwxr-xr-x | build-helpers.sh | 56 | ||||
| -rwxr-xr-x | build.sh | 49 |
3 files changed, 59 insertions, 49 deletions
diff --git a/build-arm64.sh b/build-arm64.sh index d7bb334..1061f9d 100755 --- a/build-arm64.sh +++ b/build-arm64.sh @@ -16,7 +16,8 @@ REMOTE_DIR="/opt/livebuild/output/arm64" TODAY=$(date +%Y-%m-%d) IMG_NAME="${TODAY}-Hibbian-arm64.img" ZIP_NAME="${TODAY}-Hibbian-arm64.img.zip" -LOGFILE="${TODAY}-build-arm64.log" +LOGFILE_BASENAME="${TODAY}-build-arm64.log" +LOGFILE="$SCRIPT_DIR/$LOGFILE_BASENAME" LOG_TO_STDOUT=1 # shellcheck source=build-helpers.sh diff --git a/build-helpers.sh b/build-helpers.sh index 36238d5..828c57c 100755 --- a/build-helpers.sh +++ b/build-helpers.sh @@ -64,6 +64,28 @@ get_today_build() { return 1 } +find_single_artifact() { + local dir="$1" + local pattern="$2" + local description="$3" + local artifacts=() + + mapfile -t artifacts < <(find "$dir" -maxdepth 1 -type f -name "$pattern" -print 2>/dev/null | sort) + + if (( ${#artifacts[@]} == 0 )); then + echo "ERROR: No $description produced" >> "$LOGFILE" + return 1 + fi + + if (( ${#artifacts[@]} > 1 )); then + echo "ERROR: Multiple $description files found; refusing to guess which one to publish" >> "$LOGFILE" + printf ' %s\n' "${artifacts[@]}" >> "$LOGFILE" + return 1 + fi + + printf '%s\n' "${artifacts[0]}" +} + has_today_remote_arm64() { ssh "$REMOTE" " for f in $REMOTE_DIR/$ZIP_NAME; do @@ -689,6 +711,40 @@ verify_remote() { echo "✅ Remote verification successful" } +run_stats() { + echo "Regenerating stats (best effort)..." + + ensure_all_diffs # only depends on packages.txt + rebuild_metrics # skips missing safely + generate_index # renders whatever exists +} + +run_sync() { + echo "Starting sync to remote..." + + # Safety check + if [[ -z "${REMOTE_TARGET:-}" ]]; then + echo "ERROR: REMOTE_TARGET not set" + return 1 + fi + + if [[ ! -d "$OUTPUT_DIR" ]]; then + echo "ERROR: OUTPUT_DIR does not exist" + return 1 + fi + + # Perform rsync (mirror mode) + rsync -avz --delete "$OUTPUT_DIR/" "$REMOTE_TARGET" + + # Optional: verify after sync + verify_remote || { + echo "ERROR: Remote verification failed" + return 1 + } + + echo "Sync complete" +} + extract_date() { local name="$1" [[ "$name" =~ ^([0-9]{4}-[0-9]{2}-[0-9]{2}) ]] && echo "${BASH_REMATCH[1]}" @@ -104,8 +104,6 @@ run_live_build() { } post_build() { - local iso_candidates=() - log_step "post_build: preparing output directories" mkdir -p "$OUTPUT_DIR" "$AMD64_DIR" "$ARM64_DIR" @@ -113,18 +111,7 @@ post_build() { cd "$WORKDIR/config" log_step "post_build: finding live-build ISO" - mapfile -t iso_candidates < <(find . -maxdepth 1 -type f -name '*.iso' -print 2>/dev/null | sort) - - ISO="${iso_candidates[0]:-}" - - if [[ -z "$ISO" ]]; then - echo "ERROR: live-build did not produce an ISO" >> "$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" + if ! ISO=$(find_single_artifact "." "*.iso" "live-build ISO"); then exit 1 fi @@ -149,40 +136,6 @@ post_build() { log_step "Build complete" } -run_stats() { - echo "Regenerating stats (best effort)..." - - ensure_all_diffs # only depends on packages.txt - rebuild_metrics # skips missing safely - generate_index # renders whatever exists -} - -run_sync() { - echo "Starting sync to remote..." - - # Safety check - if [[ -z "${REMOTE_TARGET:-}" ]]; then - echo "ERROR: REMOTE_TARGET not set" - return 1 - fi - - if [[ ! -d "$OUTPUT_DIR" ]]; then - echo "ERROR: OUTPUT_DIR does not exist" - return 1 - fi - - # Perform rsync (mirror mode) - rsync -avz --delete "$OUTPUT_DIR/" "$REMOTE_TARGET" - - # Optional: verify after sync - verify_remote || { - echo "ERROR: Remote verification failed" - return 1 - } - - echo "Sync complete" -} - case "$MODE" in build) run_build |
