Skip to content

Commit 1b4d76a

Browse files
authored
Merge pull request #488 from infosiftr/defensive-curl
Update "versions" curl invocation to be more defensive
2 parents 9329f88 + 8114f46 commit 1b4d76a

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

versions.sh

+19-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,22 @@ else
2323
fi
2424
versions=( "${versions[@]%/}" )
2525

26+
scriptPid="$$" # so we can kill the script even from a subshell
27+
_curl() {
28+
exec 42>&1
29+
local code
30+
code="$(curl --silent --location -o /dev/fd/42 --write-out '%{http_code}' "$@")"
31+
case "$code" in
32+
200) return 0 ;;
33+
404) return 1 ;;
34+
esac
35+
echo >&2 "error: unexpected status code $code while fetching: $*"
36+
kill "$scriptPid"
37+
exit 1
38+
}
39+
2640
dindLatest="$(
27-
curl -fsSL -H 'Accept: application/json' 'https://github.com/docker/docker/commits/master/hack/dind.atom' \
41+
_curl -H 'Accept: application/json' 'https://github.com/docker/docker/commits/master/hack/dind.atom' \
2842
| jq -r '.payload | first(.commitGroups[].commits[].oid)'
2943
)"
3044

@@ -75,7 +89,7 @@ buildxVersions="$(
7589
buildx=
7690
buildxVersion=
7791
for buildxVersion in $buildxVersions; do
78-
if checksums="$(curl -fsSL "https://github.com/docker/buildx/releases/download/v${buildxVersion}/checksums.txt")"; then
92+
if checksums="$(_curl "https://github.com/docker/buildx/releases/download/v${buildxVersion}/checksums.txt")"; then
7993
buildx="$(jq <<<"$checksums" -csR --arg version "$buildxVersion" '
8094
rtrimstr("\n") | split("\n")
8195
| map(
@@ -127,7 +141,7 @@ composeVersions="$(
127141
compose=
128142
composeVersion=
129143
for composeVersion in $composeVersions; do
130-
if checksums="$(curl -fsSL "https://github.com/docker/compose/releases/download/v${composeVersion}/checksums.txt")"; then
144+
if checksums="$(_curl "https://github.com/docker/compose/releases/download/v${composeVersion}/checksums.txt")"; then
131145
compose="$(jq <<<"$checksums" -csR --arg version "$composeVersion" '
132146
rtrimstr("\n") | split("\n")
133147
| map(
@@ -223,7 +237,7 @@ for version in "${versions[@]}"; do
223237
windows-*) url="https://download.docker.com/win/static/$channel/$arch/docker-$fullVersion.zip"; windows=1 ;;
224238
*) url="https://download.docker.com/linux/static/$channel/$arch/docker-$fullVersion.tgz"; windows= ;;
225239
esac
226-
if wget --quiet --spider "$url" &> /dev/null; then
240+
if _curl --head "$url" > /dev/null; then
227241
export bashbrewArch url
228242
doc="$(
229243
jq <<<"$doc" -c '.arches[env.bashbrewArch] = {
@@ -245,7 +259,7 @@ for version in "${versions[@]}"; do
245259
case "$bashbrewArch" in
246260
amd64 | arm64v8)
247261
rootlessExtrasUrl="https://download.docker.com/linux/static/$channel/$arch/docker-rootless-extras-$fullVersion.tgz"
248-
if wget --quiet --spider "$rootlessExtrasUrl" &> /dev/null; then
262+
if _curl --head "$rootlessExtrasUrl" > /dev/null; then
249263
export rootlessExtrasUrl
250264
doc="$(jq <<<"$doc" -c '
251265
.arches[env.bashbrewArch].rootlessExtrasUrl = env.rootlessExtrasUrl

0 commit comments

Comments
 (0)