diff options
Diffstat (limited to 'tools/update_openbsd_version.sh')
| -rwxr-xr-x | tools/update_openbsd_version.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/update_openbsd_version.sh b/tools/update_openbsd_version.sh new file mode 100755 index 0000000..d2f7c8f --- /dev/null +++ b/tools/update_openbsd_version.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Fetch the current OpenBSD release from openbsd.org and cache it for the +# startpage boot banner. Safe to run from cron (idempotent; only rewrites +# the cache when the version string is valid and changed or missing). +set -euo pipefail + +OUT="${OUT:-/mnt/slab/www.sillylaird.ca/startpage/openbsd_version.txt}" +URL="${URL:-https://www.openbsd.org/}" +TMP="$(mktemp)" +trap 'rm -f "$TMP"' EXIT + +if ! curl -fsSL --max-time 25 -A 'sillylaird-openbsd-version/1.0' -o "$TMP" "$URL"; then + echo "update_openbsd_version: fetch failed: $URL" >&2 + exit 1 +fi + +# Prefer the puffy banner alt text: [OpenBSD 7.9] +ver="$(sed -n 's/.*\[OpenBSD \([0-9][0-9]*\.[0-9][0-9]*\)\].*/\1/p' "$TMP" | head -n1 || true)" + +# Fallback: first "OpenBSD X.Y" mention that is not a year-range copyright. +if [[ -z "$ver" ]]; then + ver="$(grep -oE 'OpenBSD [0-9]+\.[0-9]+' "$TMP" | head -n1 | awk '{print $2}' || true)" +fi + +if [[ ! "$ver" =~ ^[0-9]+\.[0-9]+$ ]]; then + echo "update_openbsd_version: could not parse version from $URL" >&2 + exit 1 +fi + +mkdir -p "$(dirname "$OUT")" +if [[ -f "$OUT" ]] && [[ "$(tr -d '[:space:]' < "$OUT")" == "$ver" ]]; then + echo "openbsd $ver (unchanged)" + exit 0 +fi + +printf '%s\n' "$ver" > "$OUT" +chmod 644 "$OUT" +echo "openbsd $ver -> $OUT" |
