#!/usr/bin/env bash
# Downloads into
the standalone binaries a release already carries, and its sha256sums.txt,
# for release-binaries-sums.sh to check and extend.
#
# release-binaries-existing.sh
#
# The names come from the release's asset list, and each one is downloaded by its exact name, so
# a release with nothing attached downloads nothing, while a download that fails stops the
# backfill: carrying on with a partial would rewrite sha256sums.txt without the lines of the
# binaries it missed. Of the cosign bundles only sha256sums.txt's is kept, which
# release-binaries-sums.sh verifies before trusting the file; the backfill signs what it publishes.
set -euo pipefail
TAG=${1:?usage: release-binaries-existing.sh }
DIR=${2:?usage: release-binaries-existing.sh }
mkdir -p "$DIR"
names=$(gh release view "$TAG" --json assets --jq '.assets[].name')
while IFS= read -r name; do
case "$name" in
sha256sums.txt|sha256sums.txt.sigstore.json) gh release download "$TAG" -D "$DIR" -p "$name" ;;
*.sigstore.json) continue ;;
floci-aws-*) gh release download "$TAG" -D "$DIR" -p "$name" ;;
esac
done <<< "$names"