summaryrefslogtreecommitdiffstats
path: root/share/scripts/curl
diff options
context:
space:
mode:
Diffstat (limited to 'share/scripts/curl')
-rwxr-xr-xshare/scripts/curl50
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