Revision 53a5929f snf-image-host/snf-image-update-helper.in

b/snf-image-host/snf-image-update-helper.in
35 35
ganeti's \`snf-image' guest OS type.
36 36

  
37 37
OPTIONS:
38
    -c CACHE_FILE
39
        Use this cache file, instead of the default
40
        [default: $HELPER_CACHE_FILE]
41

  
42 38
    -d DIRECTORY
43 39
        Use this directory to host the created files, instead of the default
44 40
        [default: $HELPER_DIR]
......
49 45
        Install this deb package in the helper image, instead of the default
50 46
        [default: $HELPER_PKG]
51 47

  
48
    -r  Don't use any existing cache
49

  
52 50
    -y  Assume Yes to all queries and do not prompt
53 51

  
54 52
EOF
......
56 54
    exit "$rc"
57 55
}
58 56

  
59
while getopts "c:d:hp:y" opt; do
57
while getopts "d:hp:ry" opt; do
60 58
    case $opt in
61
        c) CACHE_FILE="$OPTARG"
62
        OVERWRITTEN_CACHE_FILE="yes"
63
            ;;
64 59
        d) HELPER_DIR="$OPTARG"
65 60
            ;;
66 61
        h) usage 0
67 62
            ;;
68 63
        p) HELPER_PKG="$OPTARG"
69 64
            ;;
65
        r) NO_CACHE="yes"
66
            ;;
70 67
        y) NO_PROMPT="yes"
71 68
            ;;
72 69
        ?) log_error "Use \`-h' for help"; exit 1
......
74 71
    esac
75 72
done
76 73

  
77
if [ x"$OVERWRITTEN_CACHE_FILE" != "xyes" ] ; then
78
    CACHE_FILE="$HELPER_CACHE_FILE"
79
fi
80

  
81 74
echo
82 75
echo "This is the update helper image script for snf-image."
83 76
echo "If you don't know what to do, use \`-h'."
......
157 150
mount "$root_dev" "$target"
158 151
add_cleanup umount "$root_dev"
159 152

  
160
echo -n "Checking for cached root filesystem file \`$CACHE_FILE'..."
161
if [ -f "$CACHE_FILE" ]; then
153
echo -n "Checking for cached root filesystem in \`$HELPER_CACHE_DIR'..."
154
if [ "$NO_CACHE" == "yes" ]; then
155
    echo "don't use cache (option -r applied)"
156
    do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
157
elif [ -f "$HELPER_CACHE_DIR/root.tar" ]; then
162 158
    echo "found"
163 159

  
164

  
165 160
    missing_pkgs="no"
166
    if [ "$CACHE_FILE" == "$HELPER_CACHE_FILE" ]; then
167
        echo -n "Checking if needed packages are present..."
168
        if [ ! -f "$HELPER_CACHE_PKGS" ]; then
169
            missing_pkgs="yes"
170
            echo "packages file: \`$HELPER_CACHE_PKGS' does not exist"
171
        else
172
            extra_pkgs=$(grep ^packages= "$MULTISTRAP_CONFIG" | cut -d= -f2 | tr  '\n' ' ')
173
            for pkg in $extra_pkgs; do
174
                if ! grep "^$pkg\$" "$HELPER_CACHE_PKGS" > /dev/null; then
175
		    missing_pkgs="yes"
176
                    echo "$pkg is missing."
177
                    break
178
                fi
179
            done
180
            if [ "$missing_pkgs" == "no" ]; then
181
                echo "done"
161
    echo -n "Checking if needed packages are present..."
162
    if [ ! -f "$HELPER_CACHE_DIR/packages" ]; then
163
        missing_pkgs="yes"
164
        echo "packages file: \`$HELPER_CACHE_DIR/packages' does not exist"
165
    else
166
        extra_pkgs=$(grep ^packages= "$MULTISTRAP_CONFIG" | cut -d= -f2 | tr  '\n' ' ')
167
        for pkg in $extra_pkgs; do
168
            if ! grep "^$pkg\$" "$HELPER_CACHE_DIR/packages" > /dev/null; then
169
		missing_pkgs="yes"
170
                echo "$pkg is missing."
171
                break
182 172
            fi
183
	fi
184
        if [ "$missing_pkgs" == "yes" ]; then
185
                do_multistrap "$target"
173
        done
174
        if [ "$missing_pkgs" == "no" ]; then
175
            echo "done"
186 176
        fi
187 177
    fi
188

  
178
    if [ "$missing_pkgs" == "yes" ]; then
179
            do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
180
    fi
189 181

  
190 182
    test "$missing_pkgs" == "no" && while [[ 1 ]]; do
191 183
        echo -n "Use the cached file [Y/n]? "
......
199 191
        if [ -z "$answer" -o "$(tr [A-Z] [a-z] <<< "$answer")" = "y" ]; then
200 192
            break;
201 193
        elif [ "$(tr [A-Z] [a-z] <<< "$answer" )" = "n" ]; then
202
            do_multistrap "$target"
194
            do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
203 195
            break;
204 196
        fi
205 197
    done
206 198

  
207 199
else
208 200
    echo "not found"
209
    do_multistrap "$target"
201
    do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
210 202
fi
211 203

  
212
tar xf "$HELPER_CACHE_FILE" -C "$target"
204
tar xf "$HELPER_CACHE_DIR/root.tar" -C "$target"
213 205

  
214 206
echo -n "Configuring the helper image..."
215 207
echo snf-image-helper > "$target/etc/hostname"

Also available in: Unified diff