A notice the whole hall shows: hall-announce on the host, served by every game's site, shown at the top of each page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jm2auWk6RP71CjaAb4FMoG
This commit is contained in:
Eric Wagoner
2026-09-29 13:03:15 -04:00
co-authored by Claude Opus 5.5
parent 294b1d5460
commit 96ec6861d5
9 changed files with 242 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# The notice every game of Kestrel's Hall shows at the top of its pages.
# Each site serves /var/lib/hall/announcement.json at /hall/announcement.json;
# a page checks it on load and every few minutes. Run on the host as root:
# hall-announce "Kestrel's Hall is down for five minutes of maintenance" --at "2026-09-30 11:00 UTC" [--until "2026-09-30 11:15 UTC"]
# hall-announce --show
# hall-announce --clear
# --at is when it happens, told in each reader's own time; --until is when the
# notice stops showing (an hour after --at when not given).
set -euo pipefail
FILE=/var/lib/hall/announcement.json
case "${1:-}" in
--clear) rm -f "$FILE"; echo "cleared."; exit 0 ;;
--show) cat "$FILE" 2>/dev/null || echo "no announcement."; exit 0 ;;
''|-*) sed -n '2,9p' "$0" | sed 's/^# \{0,1\}//'; exit 2 ;;
esac
TEXT="$1"; shift
AT=""; UNTIL=""
while [ $# -gt 0 ]; do
case "$1" in
--at) AT="$(date -u -d "$2" +%Y-%m-%dT%H:%M:%SZ)"; shift 2 ;;
--until) UNTIL="$(date -u -d "$2" +%Y-%m-%dT%H:%M:%SZ)"; shift 2 ;;
*) echo "unknown option: $1" >&2; exit 2 ;;
esac
done
[ -n "$AT" ] && [ -z "$UNTIL" ] && UNTIL="$(date -u -d "$AT + 1 hour" +%Y-%m-%dT%H:%M:%SZ)"
mkdir -p "$(dirname "$FILE")"
# A new id each time, so a reader who dismissed the last notice still sees this one.
TEXT="$TEXT" AT="$AT" UNTIL="$UNTIL" ID="$(date -u +%Y%m%dT%H%M%S)" python3 -c '
import json, os
a = {"id": os.environ["ID"], "text": os.environ["TEXT"]}
if os.environ["AT"]: a["at"] = os.environ["AT"]
if os.environ["UNTIL"]: a["until"] = os.environ["UNTIL"]
print(json.dumps(a))' > "$FILE.tmp"
chmod 644 "$FILE.tmp"
mv "$FILE.tmp" "$FILE"
cat "$FILE"