#!/bin/sh # Timer target: rebuild the garden only when the vault or repo changed. # Successor to the Quartz update_quartz_docker.sh change-detection loop. # Usage: auto-build.sh [--force] (--force skips change detection — used # by the manual rebuild hook) set -eu REPO=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) VAULT="${VAULT:-/home/nox/docker/obsidian/vaults/weeslahw_coppermind}" STATE="$REPO/.build_state" FORCE=0 [ "${1:-}" = "--force" ] && FORCE=1 cd "$REPO" # serialize builds: the 5-min timer and the manual hook must never run # docker/npm into the same checkout concurrently exec 9>"$REPO/.build.lock" flock 9 # a dirty tree can make pull fail; still rebuild whatever is checked out git pull -q || echo "git pull failed (dirty tree?) — building local state" # signature covers committed HEAD, any uncommitted repo edits, vault mtimes, # and the notebook exports (gitignored, so git status/diff can't see them — # they land here on their own timer via deploy/export-notebooks.py) sig=$({ git rev-parse HEAD git status --porcelain=v1 git diff find "$VAULT" -name .obsidian -prune -o -type f -printf '%T@ %p\n' | sort find "$REPO/notebooks-export" -type f -printf '%T@ %p\n' 2>/dev/null | sort # the ACannons export: gitignored like the notebooks, written by a Gitea # Action on cannons_reloaded rather than a timer here. Its own clause for # the reason spelled out below -- with `-o` the -printf binds only to the # LAST clause, so folding this into an OR-chain would silently print the # other matches in a different format and stop the signature being stable. find "$REPO/cannons-export" -type f -printf '%T@ %p\n' 2>/dev/null | sort # same deal for every reading map payload: gitignored, written by library-rag-export.service # on its own timer, so git status/diff above cannot see them change. One glob rather than a # list — with `-o` the `-printf` binds only to the LAST clause, so an OR-chain silently # prints the earlier matches in a different format and the signature stops being stable. # It also means a future payload is watched without editing this line. find "$REPO/public" -maxdepth 1 -name 'reading_*.json' -printf '%T@ %p\n' 2>/dev/null | sort } | sha256sum | cut -d' ' -f1) if [ "$FORCE" -eq 0 ] && [ -f "$STATE" ] && [ "$(cat "$STATE")" = "$sig" ]; then exit 0 fi sh "$REPO/deploy/build.sh" printf %s "$sig" >"$STATE" echo "garden rebuilt $(date -Is)"