#!/bin/bash # Copyright (C) 2011 GRNET S.A. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. set -e set -o errtrace . @osdir@/common.sh DEFAULT_FILE="@sysconfdir@/default/snf-image-update-helper" if [ -f "$DEFAULT_FILE" ]; then . "$DEFAULT_FILE" fi : ${HELPER_URL:="@HELPER_URL@"} usage() { local rc="$1" cat <&1 <&2 echo "Downloading helper image from $HELPER_URL ..." >&2 add_cleanup rm -f "$IMAGE_DIR/$IMAGE" set +e $CURL -O -L -f "$HELPER_URL" RET=$? set -e # Treat SIGPIPE as SUCCESS. There is a cURL bug that may trigger SIGPIPE even # if the download was successful: # http://sourceforge.net/p/curl/bugs/1180/ if [ $RET -ne 0 -a $RET -ne 141 ]; then log_error "Downloading "$IMAGE" from "$HELPER_URL" failed" exit 1 fi if [ "x$NO_CHECKSUM" != "xyes" ]; then echo "Checking the helper image checksum ..." >&2 add_cleanup rm -f "$IMAGE_DIR/$IMAGE.md5sum" set +e $CURL -O -L -f "$HELPER_URL.md5sum" RET=$? set -e # See above for an explanation if [ $RET -ne 0 -a $RET -ne 141 ]; then log_error "Downloading "$IMAGE.md5sum" from "$HELPER_URL.md5sum" failed" exit 1 fi # The filename listed inside the md5sum file may be different than the one # of the image we have downloaded. This is due to redirections and the fact # that we are not using --remote-header-name which would use the # server-specified Content-Disposition filename instead of extracting a # filename from the URL. This option is not used because some versions of # curl will not attempt to decode %-sequences which may lead to unexpected # filenames. It's better if we just replace the filename inside the md5sum # file with the one we know. sed -i 's/ .\+$/'" $IMAGE"'/' "$IMAGE_DIR/$IMAGE.md5sum" $MD5SUM -c "$IMAGE_DIR/$IMAGE.md5sum" fi cd "$HELPER_DIR" echo >&2 echo "Extracting helper image under \`$HELPER_DIR':" >&2 tar -xvf "$IMAGE_DIR/$IMAGE" if [ "x$FORCE" != "xyes" ]; then echo >&2 echo "Checking helper image version ..." >&2 if [ ! -f "$HELPER_DIR/version" ]; then log_error "File: \`$HELPER_DIR/version' is missing!" exit 1 fi helper_version="$(cat $HELPER_DIR/version)" if [ "x$SNF_IMAGE_VERSION" != "x$helper_version" ]; then log_error "snf-image version (=$SNF_IMAGE_VERSION) and " \ "helper image version (=$helper_version) don't match!" log_error "Use \`-f' to bypass the version check." exit 1 fi fi echo >&2 echo "Helper image was installed successfully!" >&2 exit 0 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :