diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2016-11-22 15:09:51 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2016-11-22 15:09:51 +0000 |
commit | f0966c697855767e3cd7d92f96f0801099e14f38 (patch) | |
tree | e6469fee633b4bd92946c99d5f1f587913d95354 /share/scripts/curl | |
parent | Releasing debian version 20161112-1. (diff) | |
download | open-infrastructure-compute-tools-f0966c697855767e3cd7d92f96f0801099e14f38.tar.xz open-infrastructure-compute-tools-f0966c697855767e3cd7d92f96f0801099e14f38.zip |
Merging 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 |