diff --git a/gamehall/ops/hall-announce.sh b/gamehall/ops/hall-announce.sh index 87644ab..d54810f 100644 --- a/gamehall/ops/hall-announce.sh +++ b/gamehall/ops/hall-announce.sh @@ -10,9 +10,11 @@ set -euo pipefail FILE=/var/lib/hall/announcement.json +# No notice is an empty one, {}, never a missing file: a page's check for a missing file +# is a failed request, and the browser reports it in every visitor's console. case "${1:-}" in - --clear) rm -f "$FILE"; echo "cleared."; exit 0 ;; - --show) cat "$FILE" 2>/dev/null || echo "no announcement."; exit 0 ;; + --clear) mkdir -p "$(dirname "$FILE")"; echo '{}' > "$FILE.tmp"; chmod 644 "$FILE.tmp"; mv "$FILE.tmp" "$FILE"; echo "cleared."; exit 0 ;; + --show) if grep -q '"text"' "$FILE" 2>/dev/null; then cat "$FILE"; else echo "no announcement."; fi; exit 0 ;; ''|-*) sed -n '2,9p' "$0" | sed 's/^# \{0,1\}//'; exit 2 ;; esac