mirror of
https://github.com/bitbaum/dotfiles.git
synced 2026-12-04 00:37:18 +01:00
fleet drift.sh answers "is the same commit on the laptop, GitHub, Gitea and the box?", but nothing ran it, so it changed nothing. It takes a minute, too slow for SessionStart, so an hourly user timer (fleet-drift.timer) runs scripts/fleet-drift-cache.sh into ~/.cache/fleet-drift.txt and the hook only reads it, next to the agent list. A missing or stale (>3 h) cache is said, never hidden. tests/session-start.test.sh (4 cases, mutation-checked) runs in CI. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.6 KiB
Bash
Executable File
32 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run fleet's drift.sh and keep its answer where every session start reads it.
|
|
#
|
|
# drift.sh answers "is the same commit on the laptop, GitHub, Gitea and the
|
|
# box?" — but a sensor nobody runs is decoration. It takes about a minute (ssh
|
|
# to the box, one ls-remote per repo), too slow for the SessionStart hook's
|
|
# budget, so a systemd user timer (fleet-drift.timer, hourly) runs this and the
|
|
# hook only cats the cache. Same split as fleet-status: the hook owns no logic.
|
|
#
|
|
# Output: ~/.cache/fleet-drift.txt — first line "as of <time>", then drift.sh's
|
|
# report ("clean" when it printed nothing). Written atomically, so a session
|
|
# never reads half a file.
|
|
# Install (units live in ~/.config/systemd/user, like the other user timers):
|
|
# fleet-drift.service Type=oneshot, Nice=10, ExecStart=%h/dev/dotfiles/scripts/fleet-drift-cache.sh
|
|
# fleet-drift.timer OnBootSec=5min, OnUnitActiveSec=1h, Persistent=true, WantedBy=timers.target
|
|
# systemctl --user enable --now fleet-drift.timer
|
|
set -uo pipefail
|
|
OUT="${XDG_CACHE_HOME:-$HOME/.cache}/fleet-drift.txt"
|
|
DRIFT="${FLEET_ROOT:-$HOME/dev}/fleet/scripts/fleet/drift.sh"
|
|
[ -f "$DRIFT" ] || { echo "no $DRIFT" >&2; exit 1; }
|
|
tmp="$(mktemp "$OUT.XXXXXX")"
|
|
{
|
|
echo "as of $(date '+%Y-%m-%d %H:%M')"
|
|
report=$(HETZNER_IP="${HETZNER_IP:-167.233.22.31}" \
|
|
GITEA_TOKEN_FILE="${GITEA_TOKEN_FILE:-$HOME/.config/gitea/token-nbg}" \
|
|
timeout 600 bash "$DRIFT" 2>&1)
|
|
rc=$?
|
|
if [ -n "$report" ]; then printf '%s\n' "$report"; else echo "clean — every repo on the same commit at every layer"; fi
|
|
[ "$rc" = 0 ] || echo "(drift.sh exit $rc)"
|
|
} >"$tmp"
|
|
mv -f "$tmp" "$OUT"
|