Repository navigation
Expand file tree
/
Copy pathverify-artifacts.sh
More file actions
executable file
·43 lines (42 loc) · 1.97 KB
/
Copy pathverify-artifacts.sh
File metadata and controls
executable file
·43 lines (42 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# verify-artifacts.sh <dir>: checks every artifact downloaded into <dir>/<name> against its SHA256SUMS and that it
# holds exactly the listed files. Artifacts made by sign jobs (sign-*) must also match the manifest digest their
# job reported (OPENCODE_DIGESTS="name=digest ..."), so an artifact replaced after that job finished is rejected.
# Deploy jobs set OPENCODE_REQUIRE_DIGESTS=true: every artifact must match a reported digest, because the digest
# is what ties the bytes to the build job that made them.
. "$(dirname "$0")/lib.sh"
root=$(posix "$1")
# download-artifact unpacks a lone matching artifact straight into <dir>; put it back under its name, found by
# its manifest's reported digest.
if [ -f "$root/SHA256SUMS" ]; then
lone=$(sha256 "$root/SHA256SUMS" | cut -c1-64)
name=""
for pair in ${OPENCODE_DIGESTS:-}; do
if [ "${pair#*=}" = "$lone" ]; then name=${pair%%=*}; fi
done
[ -n "$name" ] || die "The downloaded artifact's SHA256SUMS does not have a reported digest"
staging=$(mktemp -d)
find "$root" -mindepth 1 -maxdepth 1 -exec mv {} "$staging/" \;
mv "$staging" "$root/$name"
fi
shopt -s nullglob
for dir in "$root"/*/; do
name=$(basename "$dir")
digest=""
for pair in ${OPENCODE_DIGESTS:-}; do
if [ "${pair%%=*}" = "$name" ]; then digest=${pair#*=}; fi
done
if [ "${OPENCODE_REQUIRE_DIGESTS:-false}" = true ]; then
[[ "$digest" =~ ^[0-9a-f]{64}$ ]] || die "Missing digest for $name"
else
case "$name" in sign-*) [[ "$digest" =~ ^[0-9a-f]{64}$ ]] || die "Missing digest for $name" ;; esac
fi
(
cd "$dir"
if [ -n "$digest" ] && [ "$(sha256 SHA256SUMS | cut -c1-64)" != "$digest" ]; then die "SHA256SUMS digest mismatch in $name"; fi
sha256 -c SHA256SUMS > /dev/null || die "Checksum mismatch in $name"
diff <(find . -type f ! -name SHA256SUMS | sed 's|^\./||' | LC_ALL=C sort) <(cut -c67- SHA256SUMS | LC_ALL=C sort) ||
die "Unexpected files in $name"
)
echo "verified $name${digest:+ ($digest)}"
done