Revision 448a829f

b/snf-image-host/common.sh.in
253 253

  
254 254
}
255 255

  
256
do_debootstrap() {
257
    local target=$1
258

  
259
    echo "Debootstraping to create a new root filesystem:"
260

  
261
    # Create a policy-rc.d file to deny init script execution
262
    mkdir -p "$target/usr/sbin"
263
    cat > "$target/usr/sbin/policy-rc.d" <<EOF
264
#!/bin/sh
265
exit 101
266
EOF
267
    chmod +x "$target/usr/sbin/policy-rc.d"
268

  
269
    debootstrap --arch $(dpkg --print-architecture) \
270
        --include "$HELPER_EXTRA_PKGS" --variant=minbase stable "$target" \
271
        "$HELPER_MIRROR" 2>&1 | sed -e 's/^/DEBOOTSTRAP: /g'
272

  
273
    rm "$target/usr/sbin/policy-rc.d"
274

  
275
    # remove the downloaded debs, as they are no longer needed
276
    find "$target/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
277
        xargs -r0 rm -f
278

  
279
    local tmp_cache=$(mktemp "$CACHE_FILE.XXXXXX")
280
    tar cf "$tmp_cache" --one-file-system -C "$target" . || \
281
        { rm "$tmp_cache"; false; }
282
    # Overwrite the default cache file. Not the user specified if present.
283
    mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
284
}
285

  
256 286
cleanup() {
257 287
# if something fails here, it souldn't call cleanup again...
258 288
    trap - EXIT
b/snf-image-host/snf-image-update-helper.in
57 57

  
58 58
while getopts "c:d:hp:y" opt; do
59 59
    case $opt in
60
        c) HELPER_CACHE_FILE="$OPTARG"
60
        c) CACHE_FILE="$OPTARG"
61
        OVERWRITTEN_CACHE_FILE="yes"
61 62
            ;;
62 63
        d) HELPER_DIR="$OPTARG"
63 64
            ;;
......
72 73
    esac
73 74
done
74 75

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

  
75 80
echo
76 81
echo "This is the update helper image script for snf-image."
77 82
echo "If you don't know what to do, use \`-h'."
......
143 148
mount "$root_dev" "$target"
144 149
add_cleanup umount "$root_dev"
145 150

  
146
echo -n "Checking for cached root filesystem file \`$HELPER_CACHE_FILE'..." 
147
if [  -f "$HELPER_CACHE_FILE" ]; then
151
echo -n "Checking for cached root filesystem file \`$CACHE_FILE'..."
152
if [  -f "$CACHE_FILE" ]; then
148 153
    echo "found"
149
    tar xf "$HELPER_CACHE_FILE" -C "$target"
150
else
151
    echo "not found"
152
    echo "Debootstraping to create a new root filesystem:"
153 154

  
154
    # Create a policy-rc.d file to deny init script execution
155
    mkdir -p "$target/usr/sbin"
156
    cat > "$target/usr/sbin/policy-rc.d" <<EOF
157
#!/bin/sh
158
exit 101
159
EOF
160
    chmod +x "$target/usr/sbin/policy-rc.d"
155
    while [[ 1 ]]; do
156
        echo -n "Use the cached file [Y/n]? "
157
        if [ "x$NO_PROMPT" = "xyes" ]; then
158
            echo "y";
159
            break;
160
        fi
161 161

  
162
    debootstrap --arch $(dpkg --print-architecture) \
163
        --include "$HELPER_EXTRA_PKGS" --variant=minbase stable "$target" \
164
        "$HELPER_MIRROR" 2>&1 | sed -e 's/^/DEBOOTSTRAP: /g'
165

  
166
    rm "$target/usr/sbin/policy-rc.d"
162
        read answer
167 163
    
168
    # remove the downloaded debs, as they are no longer needed
169
    find "$target/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
170
        xargs -r0 rm -f
171

  
172
    tmp_cache=$(mktemp "$HELPER_CACHE_FILE.XXXXXX")
173
    tar cf "$tmp_cache" --one-file-system -C "$target" . || \
174
        { rm "$tmp_cache"; false; }
175
    mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
164
        if [ -z "$answer" -o "$(tr [A-Z] [a-z] <<< "$answer")" = "y" ]; then
165
            break;
166
        elif [ "$(tr [A-Z] [a-z] <<< "$answer" )" = "n" ]; then
167
            do_debootstrap "$target"
168
            break;
169
        fi
170
    done
171
else
172
    echo "not found"
173
    do_debootstrap "$target"
176 174
fi
177 175

  
176
tar xf "$HELPER_CACHE_FILE" -C "$target"
177

  
178 178
echo -n "Configuring the helper image..."
179 179
echo snf-image-helper > "$target/etc/hostname"
180 180

  

Also available in: Unified diff