2026-07-08 19:10:11 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2026-09-21 21:15:53 +02:00
|
|
|
# Export the current OpenPGP public key as a dated snapshot
|
2026-07-08 19:10:11 +02:00
|
|
|
#
|
2026-09-21 21:15:53 +02:00
|
|
|
# Usage: ./scripts/snapshot.sh [DATE]
|
2026-07-08 19:10:11 +02:00
|
|
|
#
|
2026-09-21 21:15:53 +02:00
|
|
|
# DATE defaults to the current UTC date (YYYY-MM-DD)
|
2026-07-08 19:10:11 +02:00
|
|
|
#
|
2026-09-21 21:15:53 +02:00
|
|
|
# Writes snapshots/<KEYID>-public_<DATE>.asc and refreshes public-key.asc
|
2026-07-08 19:10:11 +02:00
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Internal [S] subkey; only used to look up the key
|
|
|
|
|
SIGNING_KEY='D6D1989DF1F6B23FD776293DB46EDB4DFC26805D'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REPO=$(cd "$(dirname "$0")/.." && pwd)
|
2026-09-21 21:15:53 +02:00
|
|
|
DATE=${1:-$(date -u +%F)}
|
2026-07-08 19:10:11 +02:00
|
|
|
|
|
|
|
|
# Notes:
|
|
|
|
|
# - the first "fpr" line is the primary key's fingerprint
|
|
|
|
|
# - a subkey resolves to it
|
|
|
|
|
FPR=$(gpg --list-keys --with-colons "$SIGNING_KEY" \
|
|
|
|
|
| awk -F: '$1 == "fpr" { print $10; exit }')
|
|
|
|
|
if [ -z "$FPR" ]; then
|
|
|
|
|
echo "Error: Key $SIGNING_KEY not found" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
# The last 16 hex chars, as used in OPENPGP.md
|
|
|
|
|
KEYID=${FPR#"${FPR%????????????????}"}
|
|
|
|
|
|
2026-09-21 21:15:53 +02:00
|
|
|
OUT="$REPO/snapshots/${KEYID}-public_$DATE.asc"
|
2026-07-08 19:10:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
mkdir -p "$REPO/snapshots"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Merge the repo copy in first, so a lagging keyring cannot shrink the export
|
|
|
|
|
gpg --quiet \
|
|
|
|
|
--import "$REPO/public-key.asc"
|
|
|
|
|
|
|
|
|
|
# The retired keys must be present,
|
|
|
|
|
# or "export-clean" below drops their certifications as unverifiable
|
|
|
|
|
gpg --quiet \
|
|
|
|
|
--import "$REPO"/history/*.asc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpg --armor \
|
|
|
|
|
--export-options export-clean \
|
|
|
|
|
--export "$FPR" \
|
|
|
|
|
> "$OUT" \
|
|
|
|
|
|| {
|
|
|
|
|
rm -f "$OUT"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ ! -s "$OUT" ]; then
|
|
|
|
|
rm -f "$OUT"
|
|
|
|
|
echo "Error: Nothing exported for $FPR" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cp "$OUT" "$REPO/public-key.asc"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpg --show-keys "$OUT" >&2
|
|
|
|
|
|
|
|
|
|
|
2026-09-21 21:15:53 +02:00
|
|
|
echo "Wrote snapshots/${KEYID}-public_$DATE.asc and public-key.asc"
|