#!/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"