}
+do_debootstrap() {
+ local target=$1
+
+ echo "Debootstraping to create a new root filesystem:"
+
+ # Create a policy-rc.d file to deny init script execution
+ mkdir -p "$target/usr/sbin"
+ cat > "$target/usr/sbin/policy-rc.d" <<EOF
+#!/bin/sh
+exit 101
+EOF
+ chmod +x "$target/usr/sbin/policy-rc.d"
+
+ debootstrap --arch $(dpkg --print-architecture) \
+ --include "$HELPER_EXTRA_PKGS" --variant=minbase stable "$target" \
+ "$HELPER_MIRROR" 2>&1 | sed -e 's/^/DEBOOTSTRAP: /g'
+
+ rm "$target/usr/sbin/policy-rc.d"
+
+ # remove the downloaded debs, as they are no longer needed
+ find "$target/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
+ xargs -r0 rm -f
+
+ local tmp_cache=$(mktemp "$CACHE_FILE.XXXXXX")
+ tar cf "$tmp_cache" --one-file-system -C "$target" . || \
+ { rm "$tmp_cache"; false; }
+ # Overwrite the default cache file. Not the user specified if present.
+ mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
+}
+
cleanup() {
# if something fails here, it souldn't call cleanup again...
trap - EXIT
while getopts "c:d:hp:y" opt; do
case $opt in
- c) HELPER_CACHE_FILE="$OPTARG"
+ c) CACHE_FILE="$OPTARG"
+ OVERWRITTEN_CACHE_FILE="yes"
;;
d) HELPER_DIR="$OPTARG"
;;
esac
done
+if [ x"$OVERWRITTEN_CACHE_FILE" != "xyes" ] ; then
+ CACHE_FILE="$HELPER_CACHE_FILE"
+fi
+
echo
echo "This is the update helper image script for snf-image."
echo "If you don't know what to do, use \`-h'."
mount "$root_dev" "$target"
add_cleanup umount "$root_dev"
-echo -n "Checking for cached root filesystem file \`$HELPER_CACHE_FILE'..."
-if [ -f "$HELPER_CACHE_FILE" ]; then
+echo -n "Checking for cached root filesystem file \`$CACHE_FILE'..."
+if [ -f "$CACHE_FILE" ]; then
echo "found"
- tar xf "$HELPER_CACHE_FILE" -C "$target"
-else
- echo "not found"
- echo "Debootstraping to create a new root filesystem:"
- # Create a policy-rc.d file to deny init script execution
- mkdir -p "$target/usr/sbin"
- cat > "$target/usr/sbin/policy-rc.d" <<EOF
-#!/bin/sh
-exit 101
-EOF
- chmod +x "$target/usr/sbin/policy-rc.d"
+ while [[ 1 ]]; do
+ echo -n "Use the cached file [Y/n]? "
+ if [ "x$NO_PROMPT" = "xyes" ]; then
+ echo "y";
+ break;
+ fi
- debootstrap --arch $(dpkg --print-architecture) \
- --include "$HELPER_EXTRA_PKGS" --variant=minbase stable "$target" \
- "$HELPER_MIRROR" 2>&1 | sed -e 's/^/DEBOOTSTRAP: /g'
-
- rm "$target/usr/sbin/policy-rc.d"
+ read answer
- # remove the downloaded debs, as they are no longer needed
- find "$target/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
- xargs -r0 rm -f
-
- tmp_cache=$(mktemp "$HELPER_CACHE_FILE.XXXXXX")
- tar cf "$tmp_cache" --one-file-system -C "$target" . || \
- { rm "$tmp_cache"; false; }
- mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
+ if [ -z "$answer" -o "$(tr [A-Z] [a-z] <<< "$answer")" = "y" ]; then
+ break;
+ elif [ "$(tr [A-Z] [a-z] <<< "$answer" )" = "n" ]; then
+ do_debootstrap "$target"
+ break;
+ fi
+ done
+else
+ echo "not found"
+ do_debootstrap "$target"
fi
+tar xf "$HELPER_CACHE_FILE" -C "$target"
+
echo -n "Configuring the helper image..."
echo snf-image-helper > "$target/etc/hostname"