diff options
| author | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
|---|---|---|
| committer | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
| commit | 898b52edcb47bcb3e9d6106e74ca73e74ea01e70 (patch) | |
| tree | 85c6ee5ad58b860144551184d4cf86b560c62b91 /tools/update_openbsd_version.sh | |
| download | www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.tar.gz www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.zip | |
Diffstat (limited to '')
| -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" |
