#!/usr/bin/env bash # Run all repo audits and regenerate the sitemap. # Suitable for cron; exits non-zero if anything failed. # # Env: # SILENT=1 suppress per-audit headers # STRICT=1 also exit non-zero if audits report issues # (default: only exit non-zero on script errors, not on findings — # so the cron mail surfaces the report without flapping daily) # CHECK_LINKS=1 also run the (slow, network-bound) external link rot check set -u cd "$(dirname "$0")/.." ROOT="$(pwd)" PY="${PYTHON:-python3}" heading() { [ "${SILENT:-0}" = "1" ] || printf '\n=== %s ===\n' "$1"; } run_audit() { local name="$1"; shift heading "$name" if "$@"; then return 0 else local rc=$? [ "${STRICT:-0}" = "1" ] && return $rc return 0 fi } # Generate sitemap first (unconditional, idempotent). heading "generate_sitemap" "$PY" "$ROOT/tools/generate_sitemap.py" || exit $? # Audits — STRICT controls whether their findings fail the run. run_audit "link_check" "$PY" "$ROOT/tools/link_check.py" LC_RC=$? run_audit "html_audit" "$PY" "$ROOT/tools/html_audit.py" HA_RC=$? run_audit "image_budget" "$PY" "$ROOT/tools/image_budget.py" IB_RC=$? LR_RC=0 if [ "${CHECK_LINKS:-0}" = "1" ]; then run_audit "link_rot" "$PY" "$ROOT/tools/link_rot.py" LR_RC=$? fi if [ "${STRICT:-0}" = "1" ]; then exit $(( LC_RC | HA_RC | IB_RC | LR_RC )) fi exit 0