Skip to main content

max / makenotwork

2.4 KB · 54 lines History Blame Raw
1 #!/usr/bin/env bash
2 # Fail when the live Sando topology is not what the repo says it should be.
3 #
4 # The self-update oneshot installs `sando/sando.toml` over /etc/sando/sando.toml,
5 # so between self-updates the two can still separate: a commit lands on main and
6 # nothing has shipped it yet, or somebody edits the live file by hand. Neither is
7 # visible without someone remembering to diff, which is exactly how the
8 # multithreaded companion block drifted for 19 days.
9 #
10 # This is the reporting half. It changes nothing; it exits non-zero and prints
11 # the diff. Run from `sando-config-drift.timer` daily, where a non-zero exit
12 # leaves a failed unit for PoM to see, or by hand on the Sando host.
13 #
14 # Source of truth is the deploy branch of the bare repo sandod maintains, NOT the
15 # operator's dev tree: an uncommitted edit in ~/Code is not deployable and should
16 # not read as drift, and the bare repo is the same provenance seal the
17 # self-update's ancestor check trusts.
18 #
19 # Config via environment (defaults shown):
20 # SANDO_UPSTREAM_URL /srv/sando/mnw.git bare repo to read the topology from
21 # SANDO_DEPLOY_BRANCH main branch within it
22 # SANDO_TOPOLOGY /etc/sando/sando.toml the live file
23 set -euo pipefail
24
25 BARE="${SANDO_UPSTREAM_URL:-/srv/sando/mnw.git}"
26 BRANCH="${SANDO_DEPLOY_BRANCH:-main}"
27 TOPOLOGY="${SANDO_TOPOLOGY:-/etc/sando/sando.toml}"
28
29 [[ -f "$TOPOLOGY" ]] || { echo "check-topology-drift: no live topology at $TOPOLOGY" >&2; exit 2; }
30
31 # No fetch. sandod is the only writer of this repo and refreshes it on every
32 # build and self-update; fetching here would need git credentials this unit
33 # deliberately does not carry, and a stale bare repo is the self-update's
34 # problem rather than a drift report's.
35 if ! REPO_COPY="$(git -C "$BARE" show "$BRANCH:sando/sando.toml" 2>/dev/null)"; then
36 echo "check-topology-drift: cannot read $BRANCH:sando/sando.toml from $BARE" >&2
37 exit 2
38 fi
39
40 if diff -u --label "$BARE ($BRANCH)" --label "$TOPOLOGY" <(printf '%s\n' "$REPO_COPY") "$TOPOLOGY"; then
41 echo "check-topology-drift: live topology matches $BRANCH"
42 exit 0
43 fi
44
45 cat >&2 <<'MSG'
46
47 check-topology-drift: the live topology and the repo have separated.
48
49 Fix it by shipping, not by editing the live file: push the intended topology to
50 main and trigger a sandod self-update, which installs it. Hand-editing
51 /etc/sando/sando.toml is what this check exists to catch.
52 MSG
53 exit 1
54