-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathgetChecksums.sh
executable file
·71 lines (62 loc) · 1.65 KB
/
getChecksums.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
#
# A script that outputs a mapping of arch to checksum for a given release.
#
# Usage:
# ./getChecksums.sh repo version
#
# Example:
# ./getChecksums.sh caddy 2.7.5
#
# repo can be either caddy or xcaddy, and version should be the raw semver,
# without a leading 'v'
#
REPO=$1
VERSION=$2
# Parse semver
SEMVER_RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z\.-]*\)'
VERSION_MAJOR=`echo ${VERSION} | sed -e "s#$SEMVER_RE#\1#"`
VERSION_MINOR=`echo ${VERSION} | sed -e "s#$SEMVER_RE#\2#"`
VERSION_PATCH=`echo ${VERSION} | sed -e "s#$SEMVER_RE#\3#"`
VERSION_SPECIAL=`echo ${VERSION} | sed -e "s#$SEMVER_RE#\4#"`
# Get the checksums file from the tagged release
curl -sSL -o checksums.txt https://github.com/caddyserver/${REPO}/releases/download/v${VERSION}/${REPO}_${VERSION}_checksums.txt
# architecture keys
arches=(
amd64
arm32v6
arm32v7
arm64v8
ppc64le
riscv64
s390x
windows_amd64
)
# archives suffixes as they appear in the checksums file
archive_names=(
linux_amd64.tar.gz
linux_armv6.tar.gz
linux_armv7.tar.gz
linux_arm64.tar.gz
linux_ppc64le.tar.gz
linux_riscv64.tar.gz
linux_s390x.tar.gz
windows_amd64.zip
)
# Get the last index for the loop
last=$(expr "${#arches[@]}" - 1)
echo "{"
for i in $(seq 0 $last); do
# Grab the current arch from the list
arch="${arches[i]}"
# Get the checksum of the archive for this arch
checksum=$(awk "/${archive_names[i]}/{print \$1}" checksums.txt)
# Skip if we don't have the checksum
[ -z "${checksum}" ] && continue
if [ $i -lt $last ]; then
echo " \"${arch}\": \"${checksum}\","
else
echo " \"${arch}\": \"${checksum}\""
fi
done
echo "}"