Bump version to 0.9.3next
[snf-image] / snf-image-host / snf-image-update-helper.in
1 #!/bin/bash
2
3 # Copyright (C) 2011 GRNET S.A. 
4 #
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.
9 #
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.
14 #
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
18 # 02110-1301, USA.
19
20 set -e
21 set -o errtrace
22
23 . @osdir@/common.sh
24
25 usage() {
26     local rc="$1"
27
28     cat <<EOF
29
30 Usage: $0 [options]
31
32 This script will download a suitable fixed snf-image-helper image and will
33 install it under $IMAGE_DIR.
34
35 OPTIONS:
36     -h Print this message
37
38     -u URL
39        Download URL to use for the helper image instead of $HELPER_URL
40
41     -y Assume Yes to all queries and do not prompt
42
43 EOF
44
45     exit "$rc"
46 }
47
48 while getopts "hu:y" opt; do
49     case $opt in
50         h) usage 0
51             ;;
52         u) HELPER_URL="$OPTARG"
53             ;;
54         y) NO_PROMPT="yes"
55             ;;
56         ?) log_error "User \`-h' for help"; exit 1
57             ;;
58     esac
59 done
60
61 cat >&1 <<EOF
62
63 $(basename $0) will download a suitable snf-image-helper image and will install
64 it under $IMAGE_DIR. The following files will be overwritten if present:
65   \`$HELPER_DIR/initrd'
66   \`$HELPER_DIR/kernel'
67   \`$HELPER_DIR/initrd-xen'
68   \`$HELPER_DIR/kernel-xen'
69   \`$HELPER_DIR/image'
70   \`$HELPER_DIR/packages'
71 EOF
72
73 while [[ 1 ]]; do
74     echo -n "Do you want to continue [y/N]? "
75     if [ "x$NO_PROMPT" = "xyes" ]; then
76         echo "y";
77         break;
78     fi
79
80     read answer
81     [ "$(echo -n "$answer" | tr [A-Z] [a-z])" = "y" ] && break
82     if [ -z "$answer" -o "$(echo -n "$answer" | tr [A-Z] [a-z])" = "n" ]; then
83         log_error "Abort."
84         exit 1
85     fi
86 done
87
88 IMAGE_DIR=$(mktemp -d)
89 add_cleanup rmdir "$IMAGE_DIR"
90
91 cd "$IMAGE_DIR"
92
93 IMAGE=$(basename "$HELPER_URL")
94 echo >&2
95 echo "Downloading helper image from $HELPER_URL ..." >&2
96 $CURL -O -L -f "$HELPER_URL"
97 add_cleanup rm -f "$IMAGE_DIR/$IMAGE"
98
99 cd "$HELPER_DIR"
100
101 echo >&2
102 echo "Extracting helper image under \`$HELPER_DIR':" >&2
103 tar -xvf "$IMAGE_DIR/$IMAGE"
104
105 echo >&2
106 echo "Helper image was installed successfully!" >&2
107 exit 0
108
109 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :