summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHibby <hibby@Hibbys-MacBook-Air.local>2026-05-04 22:14:55 -0500
committerHibby <hibby@Hibbys-MacBook-Air.local>2026-05-04 22:14:55 -0500
commit65c447d20aea2c402ae8093e740a215bdae846ad (patch)
treef61fa7d33a391c7c3662e6c46140a6a13214cc57
parentb11abf7a90d4e5a9d8d7daa9f538f34f80804a14 (diff)
Various changes based on cron fails
-rwxr-xr-xbuild-arm64.sh82
-rwxr-xr-xbuild-helpers.sh10
-rwxr-xr-xbuild.sh96
3 files changed, 139 insertions, 49 deletions
diff --git a/build-arm64.sh b/build-arm64.sh
index 0045de3..d7bb334 100755
--- a/build-arm64.sh
+++ b/build-arm64.sh
@@ -1,10 +1,12 @@
#!/usr/bin/env bash
-set -euo pipefail
+set -Eeuo pipefail
# -----------------------------
# Config
# -----------------------------
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
+cd "$SCRIPT_DIR"
+
PI_GEN_REPO="https://git.hibbian.org/Hibbian/pi-gen.git"
PI_GEN_DIR="$SCRIPT_DIR/pi-gen"
BUILD_DIR="$PI_GEN_DIR/deploy"
@@ -14,46 +16,59 @@ 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"
+LOG_TO_STDOUT=1
# shellcheck source=build-helpers.sh
source "$SCRIPT_DIR/build-helpers.sh"
+trap 'echo "ERROR: command failed at ${BASH_SOURCE[0]}:${LINENO}: $BASH_COMMAND" >> "$LOGFILE"' ERR
+
+log_step "arm64: starting build script"
+
# -----------------------------
# 1) Remote check (authoritative)
# -----------------------------
-if has_today_remote_arm64; then
- echo "✔ arm64 build already exists on main server — skipping build + transfer"
+log_step "arm64: checking remote for today's build"
+if has_today_remote_arm64 >> "$LOGFILE" 2>&1; then
+ log_step "arm64: build already exists on main server; skipping build and transfer"
exit 0
fi
# -----------------------------
# 2) Local check (reuse)
# -----------------------------
+log_step "arm64: checking for existing local image"
if IMG_FILE="$(get_today_build "$BUILD_DIR" "arm64.img")"; then
- echo "✔ Using existing local image"
+ log_step "arm64: using existing local image: $IMG_FILE"
else
- echo "No local image — running pi-gen..."
- ensure_pi_gen
+ log_step "arm64: no local image; preparing pi-gen"
+ ensure_pi_gen >> "$LOGFILE" 2>&1
# ---- RUN YOUR PI-GEN BUILD HERE ----
# Adjust this to your actual invocation
+ log_step "arm64: running pi-gen build"
pushd "$PI_GEN_DIR" >/dev/null
- sudo CLEAN=1 ./build.sh
+ sudo CLEAN=1 ./build.sh >> "$LOGFILE" 2>&1
popd >/dev/null
- sudo chown -R "$USER:$USER" "$BUILD_DIR"
+
+ log_step "arm64: fixing deploy ownership"
+ sudo chown -R "$USER:$USER" "$BUILD_DIR" >> "$LOGFILE" 2>&1
# Find newest image
+ log_step "arm64: finding newest pi-gen image"
IMG="$(ls -t "$BUILD_DIR"/*.img 2>/dev/null | head -n 1 || true)"
if [[ -z "$IMG" ]]; then
- echo "ERROR: No image produced"
+ echo "ERROR: No image produced" >> "$LOGFILE"
exit 1
fi
FINAL_IMG="$BUILD_DIR/$IMG_NAME"
- mv "$IMG" "$FINAL_IMG"
+ log_step "arm64: moving $IMG to $FINAL_IMG"
+ mv "$IMG" "$FINAL_IMG" >> "$LOGFILE" 2>&1
IMG_FILE="$FINAL_IMG"
fi
@@ -61,38 +76,43 @@ fi
# -----------------------------
# 3) Transfer IMG to main server
# -----------------------------
-echo "Transferring $(basename "$IMG_FILE")..."
-rsync -avz "$IMG_FILE" "$REMOTE:$REMOTE_DIR/"
+log_step "arm64: transferring $(basename "$IMG_FILE") to $REMOTE:$REMOTE_DIR"
+rsync -avz "$IMG_FILE" "$REMOTE:$REMOTE_DIR/" >> "$LOGFILE" 2>&1
# -----------------------------
# 4) Remote: zip + checksum + publish
# -----------------------------
-echo "Triggering remote packaging + publish..."
+log_step "arm64: triggering remote packaging and publish"
-ssh "$REMOTE" "
- set -e
+REMOTE_PACKAGE_SCRIPT="
+set -e
- cd $REMOTE_DIR
+cd '$REMOTE_DIR'
- IMG='$IMG_NAME'
- ZIP='$ZIP_NAME'
+IMG='$IMG_NAME'
+ZIP='$ZIP_NAME'
- if [ -f \"\$IMG\" ]; then
- echo 'Generating checksum for IMG...'
- sha256sum \"\$IMG\" > \"\$IMG.sha256\"
+if [ -f \"\$IMG\" ]; then
+ echo 'Generating checksum for IMG...'
+ sha256sum \"\$IMG\" > \"\$IMG.sha256\"
- echo 'Updating checksum symlink...'
- ln -sfn \"\$IMG.sha256\" hibbian-latest.img.sha256
+ echo 'Updating checksum symlink...'
+ ln -sfn \"\$IMG.sha256\" hibbian-latest.img.sha256
- echo 'Zipping image...'
- zip -q \"\$ZIP\" \"\$IMG\"
+ echo 'Zipping image...'
+ zip -q \"\$ZIP\" \"\$IMG\"
- echo 'Updating ZIP symlink...'
- ln -sfn \"\$ZIP\" hibbian-latest.img.zip
+ echo 'Updating ZIP symlink...'
+ ln -sfn \"\$ZIP\" hibbian-latest.img.zip
- echo 'Removing raw image...'
- rm -f \"\$IMG\"
- fi
+ echo 'Removing raw image...'
+ rm -f \"\$IMG\"
+else
+ echo \"ERROR: \$IMG not found in $REMOTE_DIR\"
+ exit 1
+fi
"
+printf -v REMOTE_PACKAGE_COMMAND "%q" "$REMOTE_PACKAGE_SCRIPT"
+ssh "$REMOTE" "bash -lc $REMOTE_PACKAGE_COMMAND" >> "$LOGFILE" 2>&1
-echo "✔ Done"
+log_step "arm64: done"
diff --git a/build-helpers.sh b/build-helpers.sh
index ecb21fc..36238d5 100755
--- a/build-helpers.sh
+++ b/build-helpers.sh
@@ -3,6 +3,16 @@
# Helper functions for the Hibbian build scripts. This file expects callers to
# define the shared configuration variables they need before sourcing it.
+log_step() {
+ local message="==== $(date) $* ===="
+
+ if [[ "${LOG_TO_STDOUT:-0}" == "1" ]]; then
+ echo "$message" | tee -a "$LOGFILE"
+ else
+ echo "$message" >> "$LOGFILE"
+ fi
+}
+
ensure_git_repo_present() {
local repo_url="$1"
local repo_dir="$2"
diff --git a/build.sh b/build.sh
index 942f748..9943f2c 100755
--- a/build.sh
+++ b/build.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-set -euo pipefail
+set -Eeuo pipefail
MODE="${1:-build}"
### CONFIG ###
TIMESTAMP=$(date +%Y-%m-%d)
@@ -10,13 +10,18 @@ OUTPUT_DIR="/opt/livebuild/output"
AMD64_DIR="$OUTPUT_DIR/amd64"
ARM64_DIR="$OUTPUT_DIR/arm64"
REMOTE_TARGET="hibby@hibbian.org:/var/www/download/"
-LOGFILE="/opt/livebuild/build-${TIMESTAMP}.log"
+LOGFILE="${TIMESTAMP}-build-amd64.log"
FINAL_NAME="${TIMESTAMP}-Hibbian-amd64.iso"
+LIVE_BUILD_SUCCESS_GRACE_SECONDS="${LIVE_BUILD_SUCCESS_GRACE_SECONDS:-300}"
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
+cd "$SCRIPT_DIR"
+
# shellcheck source=build-helpers.sh
source "$SCRIPT_DIR/build-helpers.sh"
+trap 'echo "ERROR: command failed at ${BASH_SOURCE[0]}:${LINENO}: $BASH_COMMAND" >> "$LOGFILE"' ERR
+
run_build() {
mkdir -p "$WORKDIR" "$OUTPUT_DIR" "$AMD64_DIR" "$ARM64_DIR"
@@ -37,18 +42,70 @@ run_build() {
echo "Running lb config..." >> "$LOGFILE"
lb config >> "$LOGFILE" 2>&1
- # Build (must be root)
- echo "Running lb build..." >> "$LOGFILE"
- sudo lb build >> "$LOGFILE" 2>&1
- echo "Build complete, on to post build"
- post_build
+ # Build (must be root)
+ echo "Running lb build..." >> "$LOGFILE"
+ run_live_build
+ log_step "lb build complete; starting post_build"
+ post_build
+}
+
+run_live_build() {
+ local success_marker="P: Build completed successfully"
+ local grace_started=0
+ local deadline=0
+ local pid
+ local status
+ local log_start_size
+ local lb_command=(sudo lb build)
+
+ log_start_size=$(wc -c < "$LOGFILE" 2>/dev/null || echo 0)
+
+ if command -v setsid >/dev/null 2>&1; then
+ setsid "${lb_command[@]}" </dev/null >> "$LOGFILE" 2>&1 &
+ else
+ "${lb_command[@]}" </dev/null >> "$LOGFILE" 2>&1 &
+ fi
+
+ pid=$!
+
+ while kill -0 "$pid" 2>/dev/null; do
+ if (( grace_started == 0 )) && tail -c +"$((log_start_size + 1))" "$LOGFILE" | grep -qF "$success_marker"; then
+ grace_started=1
+ deadline=$(( $(date +%s) + LIVE_BUILD_SUCCESS_GRACE_SECONDS ))
+ log_step "lb build reported success; waiting up to ${LIVE_BUILD_SUCCESS_GRACE_SECONDS}s for process exit"
+ fi
+
+ if (( grace_started == 1 && $(date +%s) >= deadline )); then
+ log_step "lb build still running after success; terminating stuck process group"
+ kill -- "-$pid" 2>/dev/null || kill "$pid" 2>/dev/null || true
+ sleep 5
+ kill -KILL -- "-$pid" 2>/dev/null || kill -KILL "$pid" 2>/dev/null || true
+ wait "$pid" 2>/dev/null || true
+ return 0
+ fi
+
+ sleep 5
+ done
+
+ if wait "$pid"; then
+ status=0
+ else
+ status=$?
+ fi
+
+ if (( status != 0 )); then
+ return "$status"
+ fi
}
post_build() {
+ 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"
- # Find ISO
+ log_step "post_build: finding newest ISO"
ISO=$(ls -t ./*.iso 2>/dev/null | head -n 1 || true)
if [[ -z "$ISO" ]]; then
@@ -56,22 +113,25 @@ post_build() {
exit 1
fi
- cp "$ISO" "$AMD64_DIR/$FINAL_NAME"
+ log_step "post_build: copying $ISO to $AMD64_DIR/$FINAL_NAME"
+ cp "$ISO" "$AMD64_DIR/$FINAL_NAME" >> "$LOGFILE" 2>&1
- # generate checksum
- (cd "$AMD64_DIR" && sha256sum "$FINAL_NAME" > "$FINAL_NAME.sha256")
+ log_step "post_build: generating checksum"
+ (cd "$AMD64_DIR" && sha256sum "$FINAL_NAME" > "$FINAL_NAME.sha256") >> "$LOGFILE" 2>&1
- generate_links_notes
+ log_step "post_build: generating latest links and release notes"
+ generate_links_notes >> "$LOGFILE" 2>&1
- # I don't care about the old ones
- prune_old_builds
+ log_step "post_build: pruning old builds"
+ prune_old_builds >> "$LOGFILE" 2>&1
- run_stats
+ log_step "post_build: regenerating stats and index"
+ run_stats >> "$LOGFILE" 2>&1
- # Transfer to remote server
- run_sync
+ log_step "post_build: syncing to remote"
+ run_sync >> "$LOGFILE" 2>&1
- echo "==== $(date) Build complete ====" >> "$LOGFILE"
+ log_step "Build complete"
}
run_stats() {