Commit 621a9a34 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Replace debootstrap with multistrap

multistrap is more flexible allows as to define more that one
repository to retrieve packages from.
parent bf8df441
......@@ -34,7 +34,8 @@ edit = sed \
-e 's|@QEMU_IMG[@]|$(QEMU_IMG)|g' \
-e 's|@INSTALL_MBR[@]|$(INSTALL_MBR)|g' \
-e 's|@PROGRESS_MONITOR[@]|$(PROGRESS_MONITOR)|g' \
-e 's|@UNATTEND[@]|$(UNATTEND)|g'
-e 's|@UNATTEND[@]|$(UNATTEND)|g' \
-e 's|@MULTISTRAP_CONFIG[@]|$(MULTISTRAP_CONFIG)|g'
%:%.in Makefile
rm -f $@ $@.tmp
......
......@@ -323,6 +323,32 @@ EOF
mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
}
do_multistrap() {
local target="$1"
# 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"
multistrap -d "$target" -a $(dpkg --print-architecture) \
-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"
rm "$target/usr/sbin/policy-rc.d"
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"
}
report_and_cleanup(){
local err_file="$1"
......@@ -390,6 +416,7 @@ fi
: ${PITHOS_DATA:="@localstatedir@/lib/pithos/data/"}
: ${PROGRESS_MONITOR:="@PROGRESS_MONITOR@"}
: ${UNATTEND:="@UNATTEND@"}
: ${MULTISTRAP_CONFIG:="@MULTISTRAP_CONFIG@"}
SCRIPT_NAME=$(basename $0)
......
......@@ -39,6 +39,21 @@ AC_ARG_WITH([unattend-file],
fi]
)
# --with-multistrap-config
AC_ARG_WITH([multistrap-config],
[AS_HELP_STRING([--with-multistrap-config=MULTISTRAP_CONFIG_PATH],
[path to a multistrap configuration file
[SYSCONFDIR/snf-image/multistrap.conf]]
)],
[if test "$withval" != "yes" -a "$withval" != "no"; then
multistrap_config="$withval"
AC_MSG_NOTICE(using multistrap configuration file: $withval)
elif test "$withval" != "no"; then
AC_MSG_ERROR([you must specify an configuration file if --with-multistrap-config is specified])
fi],
[multistrap_config="$sysconfdir/snf-image/multistrap.conf"]
)
AC_SUBST(MULTISTRAP_CONFIG, $multistrap_config)
# --with-helper-dir
AC_ARG_WITH([helper-dir],
......
......@@ -50,15 +50,9 @@
# HELPER_CACHE_PKGS: Debian Packages the cache file contains.
# HELPER_CACHE_PKGS="${HELPER_DIR}/packages"
# HELPER_EXTRA_PKGS: Extra packages that will need to be supplied
# to debootstrap to make the resulting helper image workable.
# DO NOT OVERWRITE THIS UNLESS YOU KNOW WHAT YOU ARE DOING
# HELPER_EXTRA_PKGS="linux-image-amd64,e2fsprogs,ntfs-3g,ntfsprogs,xmlstarlet,python,parted,reglookup,chntpw,util-linux"
# HELPER_MIRROR: Debian mirror to use with debootstrap. Using a mirror close to
# you will speed up the whole debootstraping process. By default we do not
# define a mirror. Debootstrap will use it's default debian URL.
# HELPER_MIRROR="http://ftp.debian.org/debian"
# MULTISTRAP_CONFIG: Configuration file to be used with multistrap to create
# the rootfs of the helper image.
# MULTISTRAP_CONFIG="/etc/snf-image/multistrap.conf"
# PITHOS_DB: Pithos database in SQLAlchemy format
# PITHOS_DB="sqlite:////var/lib/pithos/backend.db"
......
# Example multistrap configuration file for the squeeze shortcut.
[General]
arch=
directory=
# same as --tidy-up option if set to true
cleanup=true
# same as --no-auth option if set to true
# keyring packages listed in each debootstrap will
# still be installed.
noauth=true
# whether to add the /suite to be explicit about where apt
# needs to look for packages. Default is false.
explicitsuite=false
# extract all downloaded archives (default is true)
unpack=true
# the order of sections is not important.
# the debootstrap option determines which repository
# is used to calculate the list of Priority: required packages.
debootstrap=Debian
aptsources=Debian
[Debian]
packages=linux-image-amd64 ntfs-3g ntfsprogs xmlstarlet python reglookup chntpw parted
source=http://ftp.gr.debian.org/debian
suite=stable
......@@ -91,11 +91,18 @@ fi
if [ ! -r "$HELPER_PKG" ]; then
log_error "ERROR:"
log_error "Helper package \`$HELPER_PKG' does not exist or is not " \
log_error "Helper package \`$HELPER_PKG' does not exist or is not" \
"readable by the script."
exit 1
fi
if [ ! -e "$MULTISTRAP_CONFIG" ]; then
log_error "ERROR:"
log_error "Multistrap configuration file: \`$MULTISTRAP_CONFIG' does not" \
"exist or is not readable by the script."
exit 1
fi
cat >&1 <<EOF
This program will overwrite the following files if present:
\`$HELPER_DIR/initrd'
......@@ -123,7 +130,7 @@ rm -f "$HELPER_DIR/initrd" "$HELPER_DIR/kernel" "$HELPER_DIR/image"
echo -n "Allocating space for helper disk image..."
helper_img=$(mktemp "$HELPER_DIR/image.XXXXXX")
dd if=/dev/zero of="$helper_img" bs=1k count=400000 &> /dev/null
dd if=/dev/zero of="$helper_img" bs=1k count=500000 &> /dev/null
echo "done"
echo "Creating partitions..."
......@@ -160,21 +167,20 @@ if [ -f "$CACHE_FILE" ]; then
missing_pkgs="yes"
echo "packages file: \`$HELPER_CACHE_PKGS' does not exist"
else
OLD_IFS="$IFS"
IFS=,; for pkg in $HELPER_EXTRA_PKGS; do
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
IFS="$OLD_IFS"
if [ "$missing_pkgs" == "no" ]; then
echo "done"
fi
fi
if [ "$missing_pkgs" == "yes" ]; then
do_debootstrap "$target"
do_multistrap "$target"
fi
fi
......@@ -191,14 +197,14 @@ if [ -f "$CACHE_FILE" ]; then
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"
do_multistrap "$target"
break;
fi
done
else
echo "not found"
do_debootstrap "$target"
do_multistrap "$target"
fi
tar xf "$HELPER_CACHE_FILE" -C "$target"
......@@ -243,34 +249,6 @@ pkg_name=$(basename "$HELPER_PKG")
add_cleanup rm "$target/tmp/$pkg_name"
chroot "$target" dpkg -i "/tmp/$pkg_name" 2>&1 | sed -e 's/^/DPKG: /g'
cat > "$target/etc/rc.local" <<EOF
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
if ! grep -q snf_image_activate_helper /proc/cmdline; then
echo "WARNING: NOT calling snf-image-helper, add snf_image_activate_helper"
echo "to the kernel command line if you want to do so."
else
/usr/bin/snf-image-helper --force
fi
exit 0
EOF
chmod +x "$target/etc/rc.local"
echo "done"
cleanup
mv "$helper_img" "$HELPER_DIR/image"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment