blob: d2f7c8f86e13b6758cd1e2f3b3b5b55323ae8bb1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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"
|