-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild-crontab.sh
More file actions
executable file
·50 lines (46 loc) · 1.85 KB
/
Copy pathbuild-crontab.sh
File metadata and controls
executable file
·50 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
# build-crontab.sh — assemble the live crontab from the base + per-agent fragments.
#
# SOURCE OF TRUTH is split (both git-tracked, both in the private vault repo):
# ~/vault/crontab.vps base — system / vault / integration / generic jobs
# ~/vault/agents/<name>/crontab that agent's OWN scheduled jobs (co-located with it)
#
# This script concatenates them and installs via `crontab -`. It is now THE
# install path. Do NOT run `crontab ~/vault/crontab.vps` directly any
# more — that would drop every agent's cron (the drift trap). Edit a source file,
# then re-run this.
#
# build-crontab.sh assemble + install
# build-crontab.sh --dry-run print what WOULD be installed; install nothing
set -euo pipefail
BASE="$HOME/vault/crontab.vps"
AGENTS_DIR="$HOME/vault/agents"
[ -f "$BASE" ] || { echo "build-crontab: base $BASE not found" >&2; exit 1; }
assemble() {
echo "# ============================================================"
echo "# GENERATED by build-crontab.sh — DO NOT EDIT THE LIVE CRONTAB."
echo "# Edit the base (~/vault/crontab.vps) or an agent fragment"
echo "# (~/vault/agents/<name>/crontab), then re-run build-crontab.sh."
echo "# ============================================================"
echo
cat "$BASE"
for f in "$AGENTS_DIR"/*/crontab; do
[ -f "$f" ] || continue
agent="$(basename "$(dirname "$f")")"
echo
echo "# ---- agent: $agent (~/vault/agents/$agent/crontab) ----"
cat "$f"
# guarantee a trailing newline so the next fragment can't merge onto the last line
if [ -n "$(tail -c1 "$f")" ]; then echo; fi
done
}
if [ "${1:-}" = "--dry-run" ]; then
assemble
exit 0
fi
TMP="$(mktemp)"
assemble > "$TMP"
crontab "$TMP"
rm -f "$TMP"
N=$(ls "$AGENTS_DIR"/*/crontab 2>/dev/null | wc -l | tr -d ' ')
echo "✓ crontab installed: base + ${N} agent fragment(s)"