wrolpi/release/inat-upload.sh
lrnselfreliance 04ddc7c63c
Species: a monthly build of the packs, signed where the key is (#1036)
* Species: a monthly build of the packs, signed where the key is

The build host builds the packs unsigned (inat-build.sh, a systemd timer), and the machine with the signing key
signs the hashes and the manifest from manifest.json alone (inat-publish.sh), so the packs never leave the build host
and the key never goes to it. build_inat_regions.py --no-sign now still writes each pack's sha256, and --sign signs
such a build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Species: sign only a well-formed build manifest, written again where the key is

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Species: inat-publish.sh passes the bucket to the upload, so a try stays out of the live packs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Species: the monthly build publishes nothing older than what is published

The version is the observations' publication date; a build of the same (or older) observations would replace the
published packs with an older version, and the prune would delete the newer ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 15:05:22 -07:00

47 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
# Upload a signed species pack build to the CDN, or delete the versions before it. Run on the build host, by
# inat-publish.sh (over ssh), after it has signed the build.
#
# inat-upload.sh upload <version> the packs and meta4 files, then manifest.json and its signature
# inat-upload.sh prune <version> delete every other version from the CDN (after the manifest is flushed)
#
# Honors $S3CFG. Optional env vars:
# INAT_DIR where inat-build.sh left the build (default ~/inat-build)
# INAT_BUCKET where the packs are published (default s3://wrolpi/maps/inat)
set -euo pipefail
INAT_DIR=${INAT_DIR:-${HOME}/inat-build}
INAT_BUCKET=${INAT_BUCKET:-s3://wrolpi/maps/inat}
action=${1:?upload or prune}
version=${2:?the version}
out="${INAT_DIR}/out"
case "${action}" in
upload)
if [ "$(cat "${out}/READY" 2>/dev/null)" != "${version}" ]; then
echo "The build in ${out} is not version ${version}" >&2
exit 1
fi
if [ ! -s "${out}/manifest.json.sig" ]; then
echo "${out}/manifest.json is not signed" >&2
exit 1
fi
# The packs first: the manifest must never name a pack that is not there yet.
s3cmd put --acl-public --recursive --no-progress "${out}/${version}/" "${INAT_BUCKET}/${version}/"
s3cmd put --acl-public --no-progress "${out}/manifest.json" "${out}/manifest.json.sig" "${INAT_BUCKET}/"
mv "${out}/READY" "${out}/PUBLISHED"
;;
prune)
s3cmd ls "${INAT_BUCKET}/" | awk '$1 == "DIR" {print $2}' | while read -r dir; do
if [ "$(basename "${dir}")" != "${version}" ]; then
echo "Deleting ${dir}"
s3cmd del --recursive --force "${dir}"
fi
done
;;
*)
echo "Unknown action: ${action}" >&2
exit 1
;;
esac