From 3cce7eac1e56e30761b46aa383d1eb8582f6a5fb Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 22 Jul 2017 14:26:27 +0200 Subject: Making sha512 checksum optional for image downloads in curl container create script. Signed-off-by: Daniel Baumann --- share/scripts/curl | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/share/scripts/curl b/share/scripts/curl index f7419e9..3d81807 100755 --- a/share/scripts/curl +++ b/share/scripts/curl @@ -172,32 +172,39 @@ then CURL_OPTIONS="${CURL_OPTIONS} --http2" fi -curl --fail --location --progress-bar --user-agent container-tools/${VERSION} ${CURL_OPTIONS} \ - "${SERVER}/${IMAGE}" -o "${CACHE}/${IMAGE}" +for FILE in "${SERVER}/${IMAGE}" "${SERVER}/${IMAGE}.sha512" +do + if curl --fail --head --output /dev/null --silent "${FILE}" + then + curl --fail --location --progress-bar --user-agent container-tools/${VERSION} ${CURL_OPTIONS} \ + "${FILE}" -o "${CACHE}/$(basename ${FILE})" + fi +done -curl --fail --location --progress-bar --user-agent container-tools/${VERSION} ${CURL_OPTIONS} \ - "${SERVER}/${IMAGE}.sha512" -o "${CACHE}/${IMAGE}.sha512" +if [ -e "${CACHE}/${IMAGE}.sha512" ] && [ -e "${CACHE}/${IMAGE}" ] +then + echo -n "Verifying ${IMAGE}.sha512" -echo -n "Verifying ${IMAGE}.sha512" -cd "${CACHE}" -set +e + cd "${CACHE}" + set +e -sha512sum --check "${IMAGE}.sha512" --status -SHA512SUM="${?}" + sha512sum --check "${IMAGE}.sha512" --status + SHA512SUM="${?}" -case "${SHA512SUM}" in - 0) - echo " ok." - ;; + case "${SHA512SUM}" in + 0) + echo " ok." + ;; - *) - echo " failed." - exit 1 - ;; -esac + *) + echo " failed." + exit 1 + ;; + esac -set -e -cd "${OLDPWD}" + set -e + cd "${OLDPWD}" +fi echo "Unpacking ${IMAGE}" mkdir -p "${MACHINES}/${NAME}" -- cgit v1.2.3