@@ -91,25 +91,18 @@ json-field() {
9191}
9292{{- end }}
9393
94- # Retry a download until we get it. sha covers the uncompressed binary . args: name, sha, urls
94+ # Retry until a compressed archive is downloaded, validated, and decompressed . args: name, sha, urls
9595download-or-bust() {
9696 echo "== Downloading $1 with hash $2 from $3 =="
9797 local -r file="$1"
9898 local -r hash="$2"
9999 local -a urls
100100 IFS=, read -r -a urls <<< "$3"
101101
102- if [[ -f "${file}" ]]; then
103- if ! validate-hash "${file}" "${hash}"; then
104- rm -f "${file}"
105- else
106- return 0
107- fi
108- fi
109-
110102 while true; do
111103 for url in "${urls[@]}"; do
112- echo "== Downloading ${url}.xz =="
104+ echo "== Downloading ${url} =="
105+ rm -f "${file}.xz"
113106{{- if UseGCSDownload }}
114107 local response token
115108 # Use the IP of the metadata server, to not depend on DNS this early in boot
@@ -118,8 +111,8 @@ download-or-bust() {
118111 elif ! token=$(json-field "${response}" access_token); then
119112 echo "== Failed to parse the service account token =="
120113 # Pass the token through stdin so it does not appear in files, logs, or process arguments.
121- elif ! echo "Authorization: Bearer ${token}" | curl -f -Lo "${file}.xz" --connect-timeout 20 --retry 6 --retry-delay 10 -H @- "https://storage.googleapis.com/${url#gs://}.xz "; then
122- echo "== Failed to download ${url}.xz =="
114+ elif ! echo "Authorization: Bearer ${token}" | curl -f -Lo "${file}.xz" --connect-timeout 20 --retry 6 --retry-delay 10 -H @- "https://storage.googleapis.com/${url#gs://}"; then
115+ echo "== Failed to download ${url} =="
123116 rm -f "${file}.xz"
124117{{- else if UseBlobDownload }}
125118 local rest account response token
@@ -135,8 +128,8 @@ download-or-bust() {
135128 # Pass the token through stdin so it does not appear in files, logs, or process arguments.
136129 elif ! printf 'Authorization: Bearer %s\nx-ms-version: 2017-11-09\n' "${token}" |
137130 curl -f -Lo "${file}.xz" --connect-timeout 20 --retry 6 --retry-delay 10 -H @- \
138- "https://${account}.blob.core.windows.net/${rest}.xz "; then
139- echo "== Failed to download ${url}.xz =="
131+ "https://${account}.blob.core.windows.net/${rest}"; then
132+ echo "== Failed to download ${url} =="
140133 rm -f "${file}.xz"
141134{{- else if UseS3Download }}
142135 local imds_token profile creds access_key secret_key session_token
@@ -153,22 +146,25 @@ download-or-bust() {
153146 elif ! printf 'user "%s:%s"\nheader "x-amz-security-token: %s"\n' "${access_key}" "${secret_key}" "${session_token}" |
154147 curl -f -Lo "${file}.xz" --connect-timeout 20 --retry 6 --retry-delay 10 \
155148 --config - --aws-sigv4 "aws:amz:{{ S3Region }}:s3" \
156- "https://s3.{{ S3Region }}.amazonaws.com/${url#s3://}.xz "; then
157- echo "== Failed to download ${url}.xz =="
149+ "https://s3.{{ S3Region }}.amazonaws.com/${url#s3://}"; then
150+ echo "== Failed to download ${url} =="
158151 rm -f "${file}.xz"
159152{{- else }}
160- if ! curl -f -Lo "${file}.xz" --connect-timeout 20 --retry 6 --retry-delay 10 "${url}.xz "; then
161- echo "== Failed to download ${url}.xz =="
153+ if ! curl -f -Lo "${file}.xz" --connect-timeout 20 --retry 6 --retry-delay 10 "${url}"; then
154+ echo "== Failed to download ${url} =="
162155 rm -f "${file}.xz"
163156{{- end }}
164- elif ! xz -d "${file}.xz"; then
165- echo "== Failed to decompress ${url}.xz =="
157+ elif ! validate-hash "${file}.xz" "${hash}"; then
158+ echo "== Failed to validate compressed hash for ${url} =="
159+ rm -f "${file}.xz"
160+ elif ! xz -df "${file}.xz"; then
161+ echo "== Failed to decompress ${url} =="
166162 rm -f "${file}" "${file}.xz"
167- elif ! validate-hash "${file}" "${hash }"; then
168- echo "== Failed to validate decompressed hash for ${url}.xz =="
163+ elif ! chmod +x "${file }"; then
164+ echo "== Failed to make ${file} executable =="
169165 rm -f "${file}"
170166 else
171- echo "== Downloaded ${url}.xz and validated decompressed hash ${hash} =="
167+ echo "== Downloaded ${url}, validated hash ${hash} and decompressed =="
172168 return 0
173169 fi
174170 done
@@ -209,8 +205,6 @@ function download-release() {
209205 cd ${INSTALL_DIR}/bin
210206 download-or-bust nodeup "${NODEUP_HASH}" "${NODEUP_URL}"
211207
212- chmod +x nodeup
213-
214208 echo "== Running nodeup =="
215209 # We can't run in the foreground because of https://github.com/docker/docker/issues/23793
216210 ( cd ${INSTALL_DIR}/bin; ./nodeup --install-systemd-unit --conf=${INSTALL_DIR}/conf/kube_env.yaml --v=8 )
0 commit comments