#!/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 the packs and meta4 files, then manifest.json and its signature # inat-upload.sh prune 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