3 # Copyright (C) 2011 GRNET S.A.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 DEFAULT_FILE="@sysconfdir@/default/snf-image-update-helper"
27 if [ -f "$DEFAULT_FILE" ]; then
31 : ${HELPER_URL:="@HELPER_URL@"}
40 This script will download a suitable fixed snf-image-helper image and will
41 install it under $IMAGE_DIR.
47 Download URL to use for the helper image instead of $HELPER_URL
49 -y Assume Yes to all queries and do not prompt
51 -f Force the installation even if the snf-image and helper versions don't match
58 while getopts "hu:yf" opt; do
62 u) HELPER_URL="$OPTARG"
68 ?) log_error "User \`-h' for help"; exit 1
75 $(basename $0) will download a snf-image-helper image from:
76 \`$HELPER_URL' and will install it under $IMAGE_DIR.
77 The following files will be overwritten if present:
81 \`$HELPER_DIR/packages'
82 \`$HELPER_DIR/version'
86 echo -n "Do you want to continue [y/N]? "
87 if [ "x$NO_PROMPT" = "xyes" ]; then
93 [ "$(echo -n "$answer" | tr [A-Z] [a-z])" = "y" ] && break
94 if [ -z "$answer" -o "$(echo -n "$answer" | tr [A-Z] [a-z])" = "n" ]; then
100 IMAGE_DIR=$(mktemp -d)
101 add_cleanup rmdir "$IMAGE_DIR"
105 IMAGE=$(basename "$HELPER_URL")
107 echo "Downloading helper image from $HELPER_URL ..." >&2
108 $CURL -O -L -f "$HELPER_URL"
109 add_cleanup rm -f "$IMAGE_DIR/$IMAGE"
114 echo "Extracting helper image under \`$HELPER_DIR':" >&2
115 tar -xvf "$IMAGE_DIR/$IMAGE"
117 if [ "x$FORCE" != "xyes" ]; then
119 echo "Checking helper image version ..." >&2
120 if [ ! -f "$HELPER_DIR/version" ]; then
121 log_error "File: \`$HELPER_DIR/version' is missing!"
124 helper_version="$(cat $HELPER_DIR/version)"
125 if [ "x$SNF_IMAGE_VERSION" != "x$helper_version" ]; then
126 log_error "snf-image version (=$SNF_IMAGE_VERSION) and " \
127 "helper image version (=$helper_version) don't match!"
128 log_error "Use \`-f' to bypass the version check."
134 echo "Helper image was installed successfully!" >&2
137 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :