garden/scripts/auto-rebuild-watcher.sh
Vigilio Desto 5703e606d0
garden: port content, rebuild public/, add new scripts and features
- Ported Ludo profile from vault to garden
- Added auto-rebuild watcher scripts
- Updated static data snapshots
- Added garden-features.js and api-garden.json
- Added GARDEN-CONTENT-GAPS.md for tracking
- Rebuilt Hugo public/ output
2026-06-08 02:11:24 +02:00

52 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
# auto-rebuild-watcher.sh — inotifywait daemon for garden content/ changes
#
# Runs as a systemd service (garden-content-watcher.service).
# Watches ~/projects/garden/content/ recursively and triggers garden-build.sh
# on file create/modify/delete/move events.
#
# Debounce: waits 3 seconds after the last event before triggering rebuild,
# so rapid batch edits (e.g. `git pull`, bulk copy) cause one rebuild, not N.
set -euo pipefail
CONTENT_DIR="$HOME/projects/garden/content"
BUILD_SCRIPT="$HOME/pulse/garden-build.sh"
if [ ! -d "$CONTENT_DIR" ]; then
echo "✗ Content dir not found: $CONTENT_DIR"
exit 1
fi
if [ ! -x "$BUILD_SCRIPT" ]; then
echo "✗ Build script not found/executable: $BUILD_SCRIPT"
exit 1
fi
echo "=== Garden content watcher starting at $(date -u) ==="
echo " Watching: $CONTENT_DIR"
echo " Rebuild: $BUILD_SCRIPT"
# Initial rebuild on startup (content may have changed while watcher was down)
bash "$BUILD_SCRIPT"
# Monitor with inotifywait — recursive, all file events in content/
inotifywait -m -r -e modify -e create -e delete -e move \
--format '%e %w%f' \
"$CONTENT_DIR" 2>/dev/null |
while IFS= read -r line; do
EVENT_TYPE="${line%% *}"
FILE_PATH="${line#* }"
# Debounce flag: touch a temp flag, sleep 3 seconds, then rebuild if
# the flag is still there (no newer event removed it)
FLAG="${HOME}/projects/garden/.rebuild-pending"
touch "$FLAG"
sleep 3
if [ -f "$FLAG" ]; then
rm -f "$FLAG"
echo "→ Content change detected: $EVENT_TYPE ${FILE_PATH##$HOME/projects/garden/content/}"
bash "$BUILD_SCRIPT"
fi
done