Branchwell

Textley / website / tools / set-release.sh

1#!/bin/bash
2# Usage: tools/set-release.sh VERSION SHA256
3# Points the download page at downloads/Textley-VERSION.dmg and shows its checksum.
4set -euo pipefail
5version="${1:?Usage: tools/set-release.sh VERSION SHA256}"
6sha="${2:?Usage: tools/set-release.sh VERSION SHA256}"
7[[ "$sha" =~ ^[0-9a-f]{64}$ ]] || { echo 'Pass the 64-character SHA-256 of the DMG.' >&2; exit 1; }
8cd "$(dirname "$0")/.."
9[[ -f "downloads/Textley-$version.dmg" ]] || { echo "Stage downloads/Textley-$version.dmg first." >&2; exit 1; }
10[[ "$(shasum -a 256 "downloads/Textley-$version.dmg" | cut -d' ' -f1)" == "$sha" ]] || { echo 'Checksum does not match the staged DMG.' >&2; exit 1; }
11perl -0pi -e "s/Textley-\d+\.\d+\.\d+\.dmg/Textley-$version.dmg/g; s/Version \d+\.\d+\.\d+/Version $version/g; s/(<code>)(?:TEXTLEY_DMG_SHA256|[0-9a-f]{64})(<\/code>)/\${1}$sha\${2}/" download/index.html
12perl -0pi -e "s/Version \d+\.\d+\.\d+/Version $version/" index.html
13grep -n "Textley-$version.dmg\|$sha" download/index.html