diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2016-11-22 15:09:21 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2016-12-11 12:27:10 +0000 |
commit | 5557e970bdf2ae2b32e549b945bc336d180d17c2 (patch) | |
tree | 32e40bb0c9e46456b24da4a0a401d10d2644e0b2 /share/scripts/curl | |
parent | Adding upstream version 20161112. (diff) | |
download | open-infrastructure-compute-tools-5557e970bdf2ae2b32e549b945bc336d180d17c2.tar.xz open-infrastructure-compute-tools-5557e970bdf2ae2b32e549b945bc336d180d17c2.zip |
Adding upstream version 20161122.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'share/scripts/curl')
-rwxr-xr-x | share/scripts/curl | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/share/scripts/curl b/share/scripts/curl index 0cf38e9..b67cbd4 100755 --- a/share/scripts/curl +++ b/share/scripts/curl @@ -21,11 +21,11 @@ set -e SCRIPT="${0}" MACHINES="/var/lib/machines" -CACHE="/var/cache/container-tools/curl" +CACHE="/var/cache/container-tools/images" Parameters () { - LONG_OPTIONS="bind:,script:,name:,image:,server:,password:" + LONG_OPTIONS="bind:,script:,name:,clean,image:,server:,password:" OPTIONS="b:,s:,n:,p:" PARAMETERS="$(getopt --longoptions ${LONG_OPTIONS} --name=${SCRIPT} --options ${OPTIONS} --shell sh -- ${@})" @@ -61,6 +61,11 @@ Parameters () shift 2 ;; + --clean) + CLEAN="true" + shift 1 + ;; + --image) IMAGE="${2}" shift 2 @@ -91,7 +96,7 @@ Parameters () Usage () { - echo "Usage: container create -n|--name NAME -s|--script ${SCRIPT} -- [--image IMAGE] [--server SERVER] [-p|--password PASSWORD}" >&2 + echo "Usage: container create -n|--name NAME -s|--script ${SCRIPT} -- [--clean] [--image IMAGE] [--server SERVER] [-p|--password PASSWORD}" >&2 exit 1 } @@ -142,9 +147,38 @@ then CURL_OPTIONS="--time-cond ${CACHE}/${IMAGE}" fi -curl --http2 --location --progress-bar --user-agent container-tools/${VERSION} ${CURL_OPTIONS} \ +if curl -V | grep -qs http2 +then + CURL_OPTIONS="${CURL_OPTIONS} --http2" +fi + +curl --fail --location --progress-bar --user-agent container-tools/${VERSION} ${CURL_OPTIONS} \ "${SERVER}/${IMAGE}" -o "${CACHE}/${IMAGE}" +curl --fail --location --progress-bar --user-agent container-tools/${VERSION} ${CURL_OPTIONS} \ + "${SERVER}/${IMAGE}.sha512" -o "${CACHE}/${IMAGE}.sha512" + +echo -n "Verifying ${IMAGE}.sha512" +cd "${CACHE}" +set +e + +sha512sum --check "${IMAGE}.sha512" --status +SHA512SUM="${?}" + +case "${SHA512SUM}" in + 0) + echo " ok." + ;; + + *) + echo " failed." + exit 1 + ;; +esac + +set -e +cd "${OLDPWD}" + echo "Unpacking ${IMAGE}" mkdir -p "${MACHINES}/${NAME}" @@ -185,3 +219,11 @@ cp -L /etc/resolv.conf "${MACHINES}/${NAME}/etc/resolv.conf" # Setting root password echo root:${PASSWORD} | chroot "${MACHINES}/${NAME}" chpasswd echo "${NAME}: root password set to '${PASSWORD}'." + +# Reove cache +case "${CLEAN}" in + true) + rm -f "${CACHE}/${IMAGE}" + rm -f "${CACHE}/${IMAGE}.sha512" + ;; +esac |