diff options
| author | bitflash-coin <bookofshamers@outlook.com> | 2026-08-04 06:34:32 -0700 |
|---|---|---|
| committer | bitflash-coin <bookofshamers@outlook.com> | 2026-08-04 06:34:32 -0700 |
| commit | 5ce650382352c1503f40abf08129ada69402af55 (patch) | |
| tree | 6a18198901f1e2c4933f1ac53c9365eec512bf63 /scripts | |
| parent | f34113291da7e5e3dc7d2468d4f9c212c05c584b (diff) | |
public commit
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/make-release-checksums.sh | 78 | ||||
| -rw-r--r-- | scripts/verify-release.sh | 115 |
2 files changed, 193 insertions, 0 deletions
diff --git a/scripts/make-release-checksums.sh b/scripts/make-release-checksums.sh new file mode 100644 index 0000000..5b29e2d --- /dev/null +++ b/scripts/make-release-checksums.sh | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | set -euo pipefail | ||
| 3 | |||
| 4 | sign=0 | ||
| 5 | key="" | ||
| 6 | |||
| 7 | usage() { | ||
| 8 | cat <<'EOF' | ||
| 9 | Usage: scripts/make-release-checksums.sh [--sign] [--local-user KEYID] | ||
| 10 | |||
| 11 | Creates SHA256SUMS for release assets in the current directory: | ||
| 12 | Bitflash-*-windows.zip | ||
| 13 | Bitflash-*-x86_64.AppImage | ||
| 14 | bitflash-node-*-x86_64 | ||
| 15 | |||
| 16 | With --sign, also creates SHA256SUMS.asc as a detached ASCII-armored GPG | ||
| 17 | signature. Upload both files with the release assets. | ||
| 18 | EOF | ||
| 19 | } | ||
| 20 | |||
| 21 | while [ "$#" -gt 0 ]; do | ||
| 22 | case "$1" in | ||
| 23 | --sign) sign=1 ;; | ||
| 24 | --local-user) | ||
| 25 | [ "$#" -ge 2 ] || { echo "--local-user needs a key id" >&2; exit 2; } | ||
| 26 | key="$2" | ||
| 27 | shift | ||
| 28 | ;; | ||
| 29 | -h|--help) usage; exit 0 ;; | ||
| 30 | *) echo "unknown option: $1" >&2; usage >&2; exit 2 ;; | ||
| 31 | esac | ||
| 32 | shift | ||
| 33 | done | ||
| 34 | |||
| 35 | if command -v sha256sum >/dev/null 2>&1; then | ||
| 36 | sha_cmd=(sha256sum) | ||
| 37 | elif command -v shasum >/dev/null 2>&1; then | ||
| 38 | sha_cmd=(shasum -a 256) | ||
| 39 | else | ||
| 40 | echo "missing required command: sha256sum or shasum" >&2 | ||
| 41 | exit 1 | ||
| 42 | fi | ||
| 43 | |||
| 44 | assets=() | ||
| 45 | for pattern in \ | ||
| 46 | "Bitflash-*-windows.zip" \ | ||
| 47 | "Bitflash-*-x86_64.AppImage" \ | ||
| 48 | "bitflash-node-*-x86_64" | ||
| 49 | do | ||
| 50 | for file in $pattern; do | ||
| 51 | [ -e "$file" ] || continue | ||
| 52 | assets+=("$file") | ||
| 53 | done | ||
| 54 | done | ||
| 55 | |||
| 56 | if [ "${#assets[@]}" -eq 0 ]; then | ||
| 57 | echo "no release assets found in $(pwd)" >&2 | ||
| 58 | exit 1 | ||
| 59 | fi | ||
| 60 | |||
| 61 | printf '%s\n' "${assets[@]}" | LC_ALL=C sort | while IFS= read -r file; do | ||
| 62 | "${sha_cmd[@]}" "$file" | ||
| 63 | done > SHA256SUMS | ||
| 64 | |||
| 65 | echo "Wrote SHA256SUMS" | ||
| 66 | |||
| 67 | if [ "$sign" -eq 1 ]; then | ||
| 68 | if ! command -v gpg >/dev/null 2>&1; then | ||
| 69 | echo "missing required command: gpg" >&2 | ||
| 70 | exit 1 | ||
| 71 | fi | ||
| 72 | gpg_args=(--armor --detach-sign --output SHA256SUMS.asc) | ||
| 73 | if [ -n "$key" ]; then | ||
| 74 | gpg_args+=(--local-user "$key") | ||
| 75 | fi | ||
| 76 | gpg "${gpg_args[@]}" SHA256SUMS | ||
| 77 | echo "Wrote SHA256SUMS.asc" | ||
| 78 | fi | ||
diff --git a/scripts/verify-release.sh b/scripts/verify-release.sh new file mode 100644 index 0000000..c651e78 --- /dev/null +++ b/scripts/verify-release.sh | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | set -euo pipefail | ||
| 3 | |||
| 4 | repo="bitflash-coin/bitflash" | ||
| 5 | tag="${1:-latest}" | ||
| 6 | require_signature=0 | ||
| 7 | |||
| 8 | usage() { | ||
| 9 | cat <<'EOF' | ||
| 10 | Usage: scripts/verify-release.sh [tag|latest] [--require-signature] | ||
| 11 | |||
| 12 | Downloads the release checksum file and every asset named in it, then verifies: | ||
| 13 | 1. SHA256SUMS.asc, if present, against SHA256SUMS with gpg. | ||
| 14 | 2. SHA256SUMS against the downloaded assets. | ||
| 15 | |||
| 16 | Use --require-signature for release audits. Without it, older releases that | ||
| 17 | ship only SHA256SUMS are checked for integrity and reported as unsigned. | ||
| 18 | EOF | ||
| 19 | } | ||
| 20 | |||
| 21 | for arg in "${@:2}"; do | ||
| 22 | case "$arg" in | ||
| 23 | --require-signature) require_signature=1 ;; | ||
| 24 | -h|--help) usage; exit 0 ;; | ||
| 25 | *) echo "unknown option: $arg" >&2; usage >&2; exit 2 ;; | ||
| 26 | esac | ||
| 27 | done | ||
| 28 | |||
| 29 | if [ "$tag" = "-h" ] || [ "$tag" = "--help" ]; then | ||
| 30 | usage | ||
| 31 | exit 0 | ||
| 32 | fi | ||
| 33 | |||
| 34 | need() { | ||
| 35 | if ! command -v "$1" >/dev/null 2>&1; then | ||
| 36 | echo "missing required command: $1" >&2 | ||
| 37 | exit 1 | ||
| 38 | fi | ||
| 39 | } | ||
| 40 | |||
| 41 | need sed | ||
| 42 | need awk | ||
| 43 | |||
| 44 | if command -v sha256sum >/dev/null 2>&1; then | ||
| 45 | sha_check=(sha256sum -c SHA256SUMS) | ||
| 46 | elif command -v shasum >/dev/null 2>&1; then | ||
| 47 | sha_check=(shasum -a 256 -c SHA256SUMS) | ||
| 48 | else | ||
| 49 | echo "missing required command: sha256sum or shasum" >&2 | ||
| 50 | exit 1 | ||
| 51 | fi | ||
| 52 | |||
| 53 | download() { | ||
| 54 | local url="$1" | ||
| 55 | local out="$2" | ||
| 56 | if command -v curl >/dev/null 2>&1; then | ||
| 57 | curl -fsSL "$url" -o "$out" | ||
| 58 | elif command -v wget >/dev/null 2>&1; then | ||
| 59 | wget -q "$url" -O "$out" | ||
| 60 | else | ||
| 61 | echo "missing required command: curl or wget" >&2 | ||
| 62 | exit 1 | ||
| 63 | fi | ||
| 64 | } | ||
| 65 | |||
| 66 | if [ "$tag" = "latest" ]; then | ||
| 67 | tag="$(download "https://api.github.com/repos/$repo/releases/latest" - | | ||
| 68 | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | | ||
| 69 | head -1)" | ||
| 70 | if [ -z "$tag" ]; then | ||
| 71 | echo "could not resolve latest release tag" >&2 | ||
| 72 | exit 1 | ||
| 73 | fi | ||
| 74 | fi | ||
| 75 | |||
| 76 | workdir="$(mktemp -d "${TMPDIR:-/tmp}/bitflash-release-verify.XXXXXX")" | ||
| 77 | cleanup() { rm -rf "$workdir"; } | ||
| 78 | trap cleanup EXIT | ||
| 79 | |||
| 80 | base_url="https://github.com/$repo/releases/download/$tag" | ||
| 81 | |||
| 82 | echo "Verifying Bitflash $tag" | ||
| 83 | echo "Working directory: $workdir" | ||
| 84 | cd "$workdir" | ||
| 85 | |||
| 86 | download "$base_url/SHA256SUMS" SHA256SUMS | ||
| 87 | |||
| 88 | if download "$base_url/SHA256SUMS.asc" SHA256SUMS.asc 2>/dev/null; then | ||
| 89 | if ! command -v gpg >/dev/null 2>&1; then | ||
| 90 | echo "SHA256SUMS.asc exists, but gpg is not installed" >&2 | ||
| 91 | exit 1 | ||
| 92 | fi | ||
| 93 | gpg --verify SHA256SUMS.asc SHA256SUMS | ||
| 94 | echo "Signature OK" | ||
| 95 | else | ||
| 96 | if [ "$require_signature" -eq 1 ]; then | ||
| 97 | echo "release does not publish SHA256SUMS.asc" >&2 | ||
| 98 | exit 1 | ||
| 99 | fi | ||
| 100 | echo "WARNING: no SHA256SUMS.asc found; checking hashes only" | ||
| 101 | fi | ||
| 102 | |||
| 103 | awk '{print $2}' SHA256SUMS | while IFS= read -r file; do | ||
| 104 | file="${file#\*}" | ||
| 105 | file="${file#./}" | ||
| 106 | [ -z "$file" ] && continue | ||
| 107 | case "$file" in | ||
| 108 | */*|..*) echo "refusing unexpected checksum path: $file" >&2; exit 1 ;; | ||
| 109 | esac | ||
| 110 | echo "Downloading $file" | ||
| 111 | download "$base_url/$file" "$file" | ||
| 112 | done | ||
| 113 | |||
| 114 | "${sha_check[@]}" | ||
| 115 | echo "Release assets OK" | ||