36 lines
1.4 KiB
Bash
36 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
# post-pull.sh — homelab-context sync hook.
|
|
# Replaces raw `git pull` in the launchd/systemd timer.
|
|
# Runs after every git pull to auto-setup tools from the repo.
|
|
#
|
|
# Convention: any script at tools/*.setup.sh is sourced/exec'd after pull.
|
|
# This lets us ship new tooling to all agent hosts via a simple git push.
|
|
|
|
set -euo pipefail
|
|
|
|
CONTEXT_DIR="${HOMELAB_CONTEXT_DIR:-/opt/homelab-context}"
|
|
|
|
# Git safe.directory workaround: the repo is owned by the regular user
|
|
# but launchd runs as root. Run git as the repo owner.
|
|
REPO_OWNER=$(stat -f "%Su" "$CONTEXT_DIR" 2>/dev/null || echo "root")
|
|
|
|
# 1. Git pull (as repo owner to avoid safe.directory issues)
|
|
if [ "$REPO_OWNER" != "root" ] && command -v sudo &>/dev/null; then
|
|
sudo -u "$REPO_OWNER" git -C "$CONTEXT_DIR" pull --ff-only --quiet 2>&1 || \
|
|
echo "[post-pull] git pull failed (network?) continuing..."
|
|
else
|
|
git -C "$CONTEXT_DIR" pull --ff-only --quiet 2>&1 || \
|
|
echo "[post-pull] git pull failed (network?) continuing..."
|
|
fi
|
|
|
|
# 2. Run any auto-setup scripts
|
|
for setup_script in "$CONTEXT_DIR"/tools/*.setup.sh; do
|
|
[ -f "$setup_script" ] || continue
|
|
echo "[post-pull] running $setup_script..."
|
|
bash "$setup_script" || echo "[post-pull] WARNING: $setup_script exited with code $?"
|
|
done
|
|
|
|
# 3. Symlink AGENTS.md for agent orientation (macOS)
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
ln -sf "$CONTEXT_DIR/AGENTS.md" /etc/AGENTS.md 2>/dev/null || true
|
|
fi |