-e 's|@osname[@]|$(osname)|g' \
-e 's|@defaultdir[@]|$(defaultdir)|g' \
-e 's|@HELPER_DIR[@]|$(HELPER_DIR)|g' \
+ -e 's|@HELPER_CACHE_DIR[@]|$(HELPER_CACHE_DIR)|g' \
-e 's|@HELPER_IMG[@]|$(HELPER_IMG)|g' \
-e 's|@HELPER_KERNEL[@]|$(HELPER_KERNEL)|g' \
-e 's|@HELPER_INITRD[@]|$(HELPER_INITRD)|g' \
do_debootstrap() {
local target="$1"
+ local cache="$2"
+ local pkgs="$3"
echo "Debootstraping to create a new root filesystem:"
"$HELPER_MIRROR" 2>&1 | sed -e 's/^/DEBOOTSTRAP: /g'
# Save the package list
- chroot "$target" dpkg-query -W -f "\${Package}\n" > "$HELPER_CACHE_PKGS"
+ chroot "$target" dpkg-query -W -f "\${Package}\n" > "$pkgs"
rm "$target/usr/sbin/policy-rc.d"
find "$target/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
xargs -r0 rm -f
- local tmp_cache=$(mktemp "$CACHE_FILE.XXXXXX")
+ local tmp_cache=$(mktemp "$cache.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"
+ mv -f "$tmp_cache" "$cache"
}
do_multistrap() {
local target="$1"
+ local cache="$2"
+ local pkgs="$3"
# Create a policy-rc.d file to deny init script execution
mkdir -p "$target/usr/sbin"
-f "$MULTISTRAP_CONFIG" 2>&1 | sed -u -e 's/^/MULTISTRAP: /g'
# Save the package list
- chroot "$target" dpkg-query -W -f "\${Package}\n" > "$HELPER_CACHE_PKGS"
+ chroot "$target" dpkg-query -W -f "\${Package}\n" > "$pkgs"
rm "$target/usr/sbin/policy-rc.d"
- local tmp_cache=$(mktemp "$CACHE_FILE.XXXXXX")
+ local tmp_cache=$(mktemp "$cache.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"
+ mv -f "$tmp_cache" "$cache"
}
report_and_cleanup(){
: ${IMAGE_DIR:="@localstatedir@/lib/snf-image"}
: ${IMAGE_DEBUG:="no"}
: ${HELPER_DIR:="@HELPER_DIR@"}
+: ${HELPER_CACHE_DIR:="@HELPER_CACHE_DIR@"}
: ${HELPER_IMG:="@HELPER_IMG@"}
: ${HELPER_KERNEL:="@HELPER_KERNEL@"}
: ${HELPER_INITRD:="@HELPER_INITRD@"}
: ${HELPER_SOFT_TIMEOUT:=20}
: ${HELPER_HARD_TIMEOUT:=5}
: ${HELPER_USER:="nobody"}
-: ${HELPER_CACHE_FILE:="@HELPER_DIR@/cache.tar"}
-: ${HELPER_CACHE_PKGS:="@HELPER_DIR@/packages"}
: ${HELPER_EXTRA_PKGS:="linux-image-amd64,e2fsprogs,ntfs-3g,ntfsprogs,xmlstarlet,python,parted,reglookup,chntpw,util-linux"}
: ${HELPER_MIRROR:=""}
: ${PITHOS_DB:="sqlite:////@localstatedir@/lib/pithos/backend.db"}
[helper_dir="$localstatedir/lib/snf-image/helper"])
AC_SUBST(HELPER_DIR, $helper_dir)
+# --with-helper-cache-dir
+AC_ARG_WITH([helper-cache-dir],
+ [AS_HELP_STRING([--with-helper-cache-dir=DIR],
+ [top-level directory to host the helper VM cache files
+ [LOCALSTATEDIR/cache/snf-image/helper]]
+ )],
+ [helper_cache_dir="$withval"],
+ [helper_cache_dir="$localstatedir/cache/snf-image/helper"])
+AC_SUBST(HELPER_CACHE_DIR, $helper_cache_dir)
+
# --with-helper-img
AC_ARG_WITH([helper-img],
[AS_HELP_STRING([--with-helper-img=IMG_PATH],
# HELPER_DIR: Directory hosting the helper files
# HELPER_DIR="/var/lib/snf-image/helper/"
+# HELPER_CACHE_DIR: Directory hosting the helper cache files
+# HELPER_CACHE_DIR="/var/cache/snf-image/helper/"
+
# HELPER_IMG: Path to the helper VM image
# HELPER_IMG="${HELPER_DIR}/image"
# HELPER_USER imeddiately before starting execution of the helper VM.
# HELPER_USER="nobody"
-# HELPER_CACHE_FILE: Cache file update-helper script uses to avoid running
-# `debootstrap' all the time.
-# HELPER_CACHE_FILE="${HELPER_DIR}/cache.tar"
-
-# HELPER_CACHE_PKGS: Debian Packages the cache file contains.
-# HELPER_CACHE_PKGS="${HELPER_DIR}/packages"
-
# MULTISTRAP_CONFIG: Configuration file to be used with multistrap to create
# the rootfs of the helper image.
# MULTISTRAP_CONFIG="/etc/snf-image/multistrap.conf"
ganeti's \`snf-image' guest OS type.
OPTIONS:
- -c CACHE_FILE
- Use this cache file, instead of the default
- [default: $HELPER_CACHE_FILE]
-
-d DIRECTORY
Use this directory to host the created files, instead of the default
[default: $HELPER_DIR]
Install this deb package in the helper image, instead of the default
[default: $HELPER_PKG]
+ -r Don't use any existing cache
+
-y Assume Yes to all queries and do not prompt
EOF
exit "$rc"
}
-while getopts "c:d:hp:y" opt; do
+while getopts "d:hp:ry" opt; do
case $opt in
- c) CACHE_FILE="$OPTARG"
- OVERWRITTEN_CACHE_FILE="yes"
- ;;
d) HELPER_DIR="$OPTARG"
;;
h) usage 0
;;
p) HELPER_PKG="$OPTARG"
;;
+ r) NO_CACHE="yes"
+ ;;
y) NO_PROMPT="yes"
;;
?) log_error "Use \`-h' for help"; exit 1
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 \`$CACHE_FILE'..."
-if [ -f "$CACHE_FILE" ]; then
+echo -n "Checking for cached root filesystem in \`$HELPER_CACHE_DIR'..."
+if [ "$NO_CACHE" == "yes" ]; then
+ echo "don't use cache (option -r applied)"
+ do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
+elif [ -f "$HELPER_CACHE_DIR/root.tar" ]; then
echo "found"
-
missing_pkgs="no"
- if [ "$CACHE_FILE" == "$HELPER_CACHE_FILE" ]; then
- echo -n "Checking if needed packages are present..."
- if [ ! -f "$HELPER_CACHE_PKGS" ]; then
- missing_pkgs="yes"
- echo "packages file: \`$HELPER_CACHE_PKGS' does not exist"
- else
- extra_pkgs=$(grep ^packages= "$MULTISTRAP_CONFIG" | cut -d= -f2 | tr '\n' ' ')
- for pkg in $extra_pkgs; do
- if ! grep "^$pkg\$" "$HELPER_CACHE_PKGS" > /dev/null; then
- missing_pkgs="yes"
- echo "$pkg is missing."
- break
- fi
- done
- if [ "$missing_pkgs" == "no" ]; then
- echo "done"
+ echo -n "Checking if needed packages are present..."
+ if [ ! -f "$HELPER_CACHE_DIR/packages" ]; then
+ missing_pkgs="yes"
+ echo "packages file: \`$HELPER_CACHE_DIR/packages' does not exist"
+ else
+ extra_pkgs=$(grep ^packages= "$MULTISTRAP_CONFIG" | cut -d= -f2 | tr '\n' ' ')
+ for pkg in $extra_pkgs; do
+ if ! grep "^$pkg\$" "$HELPER_CACHE_DIR/packages" > /dev/null; then
+ missing_pkgs="yes"
+ echo "$pkg is missing."
+ break
fi
- fi
- if [ "$missing_pkgs" == "yes" ]; then
- do_multistrap "$target"
+ done
+ if [ "$missing_pkgs" == "no" ]; then
+ echo "done"
fi
fi
-
+ if [ "$missing_pkgs" == "yes" ]; then
+ do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
+ fi
test "$missing_pkgs" == "no" && while [[ 1 ]]; do
echo -n "Use the cached file [Y/n]? "
if [ -z "$answer" -o "$(tr [A-Z] [a-z] <<< "$answer")" = "y" ]; then
break;
elif [ "$(tr [A-Z] [a-z] <<< "$answer" )" = "n" ]; then
- do_multistrap "$target"
+ do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
break;
fi
done
else
echo "not found"
- do_multistrap "$target"
+ do_multistrap "$target" "$HELPER_CACHE_DIR/root.tar" "$HELPER_CACHE_DIR/packages"
fi
-tar xf "$HELPER_CACHE_FILE" -C "$target"
+tar xf "$HELPER_CACHE_DIR/root.tar" -C "$target"
echo -n "Configuring the helper image..."
echo snf-image-helper > "$target/etc/hostname"