Textley / website / tools / stage-installer.sh
| 1 | #!/bin/bash |
| 2 | # Stage the released download during a GitHub-triggered Vercel build. |
| 3 | set -euo pipefail |
| 4 | cd "$(dirname "$0")/.." |
| 5 | |
| 6 | version="$(sed -nE 's/.*<sparkle:shortVersionString>([0-9]+\.[0-9]+\.[0-9]+)<\/sparkle:shortVersionString>.*/\1/p' appcast.xml)" |
| 7 | checksum="$(sed -nE 's/.*<code>([0-9a-f]{64})<\/code>.*/\1/p' download/index.html)" |
| 8 | if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ || ! "$checksum" =~ ^[0-9a-f]{64}$ ]]; then |
| 9 | echo 'Expected a release version in appcast.xml and a SHA-256 on the download page.' >&2 |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
| 13 | mkdir -p downloads |
| 14 | release_base="${TEXTLEY_RELEASE_BASE_URL:-https://github.com/protomota/textley/releases/download}" |
| 15 | |
| 16 | stage_installer() ( |
| 17 | local version="$1" checksum="$2" |
| 18 | local installer="Textley-${version}.dmg" staged |
| 19 | local actual |
| 20 | staged="$(mktemp "downloads/.${installer}.XXXXXX")" |
| 21 | trap 'rm -f "$staged"' EXIT |
| 22 | curl --fail --show-error --silent --location --retry 3 \ |
| 23 | "${release_base}/v${version}/${installer}" -o "$staged" |
| 24 | if command -v sha256sum >/dev/null 2>&1; then |
| 25 | actual="$(sha256sum "$staged")" |
| 26 | else |
| 27 | actual="$(shasum -a 256 "$staged")" |
| 28 | fi |
| 29 | if [[ "${actual%% *}" != "$checksum" ]]; then |
| 30 | printf 'SHA-256 mismatch for %s\n' "$installer" >&2 |
| 31 | exit 1 |
| 32 | fi |
| 33 | mv "$staged" "downloads/$installer" |
| 34 | ) |
| 35 | |
| 36 | stage_installer "$version" "$checksum" |
| 37 | |
| 38 | # Keep the signed key-rotation release available to Textley 1.0.4 through 1.0.6. |
| 39 | if [[ "$version" != 1.1.1 ]]; then |
| 40 | stage_installer 1.1.1 9bf23d691743841f15a42528b36d6c84972cb7c8438ac35cbf3eec133871cda6 |
| 41 | fi |