upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts/verify-release.sh
diff options
context:
space:
mode:
authormtg0001 <106211915+mtg0001@users.noreply.github.com>2026-08-04 10:18:01 -0300
committerGitHub <noreply@github.com>2026-08-04 10:18:01 -0300
commitf6c5b813075cae4228d241a3567e70b210504749 (patch)
tree8d408438f3579a6a170be4d04cc68d33ab292782 /scripts/verify-release.sh
parent530f91910a4eceb6705d1212fa0e3ebe8418c6a3 (diff)
Add release verification tooling (#108)
Co-authored-by: Gilcimar Duarte <ti@gpm.infra>
Diffstat (limited to 'scripts/verify-release.sh')
-rwxr-xr-xscripts/verify-release.sh115
1 files changed, 115 insertions, 0 deletions
diff --git a/scripts/verify-release.sh b/scripts/verify-release.sh
new file mode 100755
index 0000000..23e71d1
--- /dev/null
+++ b/scripts/verify-release.sh
@@ -0,0 +1,115 @@
1#!/usr/bin/env bash
2set -euo pipefail
3
4repo="Bitflash-sh/bitflash"
5tag="${1:-latest}"
6require_signature=0
7
8usage() {
9 cat <<'EOF'
10Usage: scripts/verify-release.sh [tag|latest] [--require-signature]
11
12Downloads 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
16Use --require-signature for release audits. Without it, older releases that
17ship only SHA256SUMS are checked for integrity and reported as unsigned.
18EOF
19}
20
21for 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
27done
28
29if [ "$tag" = "-h" ] || [ "$tag" = "--help" ]; then
30 usage
31 exit 0
32fi
33
34need() {
35 if ! command -v "$1" >/dev/null 2>&1; then
36 echo "missing required command: $1" >&2
37 exit 1
38 fi
39}
40
41need sed
42need awk
43
44if command -v sha256sum >/dev/null 2>&1; then
45 sha_check=(sha256sum -c SHA256SUMS)
46elif command -v shasum >/dev/null 2>&1; then
47 sha_check=(shasum -a 256 -c SHA256SUMS)
48else
49 echo "missing required command: sha256sum or shasum" >&2
50 exit 1
51fi
52
53download() {
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
66if [ "$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
74fi
75
76workdir="$(mktemp -d "${TMPDIR:-/tmp}/bitflash-release-verify.XXXXXX")"
77cleanup() { rm -rf "$workdir"; }
78trap cleanup EXIT
79
80base_url="https://github.com/$repo/releases/download/$tag"
81
82echo "Verifying Bitflash $tag"
83echo "Working directory: $workdir"
84cd "$workdir"
85
86download "$base_url/SHA256SUMS" SHA256SUMS
87
88if 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"
95else
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"
101fi
102
103awk '{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"
112done
113
114"${sha_check[@]}"
115echo "Release assets OK"