#!/bin/bash # Stage the released download during a GitHub-triggered Vercel build. set -euo pipefail cd "$(dirname "$0")/.." version="$(sed -nE 's/.*([0-9]+\.[0-9]+\.[0-9]+)<\/sparkle:shortVersionString>.*/\1/p' appcast.xml)" checksum="$(sed -nE 's/.*([0-9a-f]{64})<\/code>.*/\1/p' download/index.html)" if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ || ! "$checksum" =~ ^[0-9a-f]{64}$ ]]; then echo 'Expected a release version in appcast.xml and a SHA-256 on the download page.' >&2 exit 1 fi mkdir -p downloads release_base="${TEXTLEY_RELEASE_BASE_URL:-https://github.com/protomota/textley/releases/download}" stage_installer() ( local version="$1" checksum="$2" local installer="Textley-${version}.dmg" staged local actual staged="$(mktemp "downloads/.${installer}.XXXXXX")" trap 'rm -f "$staged"' EXIT curl --fail --show-error --silent --location --retry 3 \ "${release_base}/v${version}/${installer}" -o "$staged" if command -v sha256sum >/dev/null 2>&1; then actual="$(sha256sum "$staged")" else actual="$(shasum -a 256 "$staged")" fi if [[ "${actual%% *}" != "$checksum" ]]; then printf 'SHA-256 mismatch for %s\n' "$installer" >&2 exit 1 fi mv "$staged" "downloads/$installer" ) stage_installer "$version" "$checksum" # Keep the signed key-rotation release available to Textley 1.0.4 through 1.0.6. if [[ "$version" != 1.1.1 ]]; then stage_installer 1.1.1 9bf23d691743841f15a42528b36d6c84972cb7c8438ac35cbf3eec133871cda6 fi