+# install extra packages {{{
+extrapackages() {
+ if [ "$EXTRAPACKAGES" = 'yes' ] ; then
+ PACKAGELIST=$(find /etc/debootstrap/extrapackages -type f -name '*.deb')
+ if [ -n "$PACKAGELIST" ]; then
+ dpkg -i $PACKAGELIST
+ # run apt again to resolve any deps
+ DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL
+ fi
+ fi
+}
+# }}}
+
+# check if the specified Debian package exists
+package_exists() {
+ output=$(apt-cache show "$1" 2>/dev/null)
+ [ -n "$output" ]
+ return $?
+}
+
+
+# determine the kernel version postfix
+get_kernel_version() {
+ # do not override $KERNEL if set via config file
+ if [ -n "$KERNEL" ] ; then
+ echo "$KERNEL"
+ return 0
+ fi
+
+ case $ARCH in
+ i386) KARCH=686 ;;
+ amd64) KARCH=amd64 ;;
+ *)
+ echo "Only i386 and amd64 are currently supported" >&2
+ return 1
+ esac
+
+ for KPREFIX in "" "2.6-" ; do # iterate through the kernel prefixes,
+ # currently "" and "2.6-"
+ if package_exists linux-image-${KPREFIX}${KARCH} ; then
+ echo ${KPREFIX}${KARCH}
+ return 0
+ fi
+
+ done
+}
+
+# install kernel packages {{{
+kernel() {
+ if [ -n "$NOKERNEL" ] ; then
+ echo "Skipping installation of kernel packages as requested via --nokernel"
+ return 0
+ fi
+
+ $APTUPDATE
+ KVER=$(get_kernel_version)
+ if [ -n "$KVER" ] ; then
+ # note: install busybox to be able to debug initramfs
+ KERNELPACKAGES="linux-image-$KVER linux-headers-$KVER busybox firmware-linux-free firmware-linux"
+ DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $KERNELPACKAGES
+ else
+ echo "Warning: Could not find a kernel for your system. Your system won't be able to boot itself!"
+ fi
+}
+# }}}
+
+# reconfigure packages {{{
+reconfigure() {
+ if [ -n "$RECONFIGURE" ] ; then
+ for package in $RECONFIGURE ; do
+ if dpkg --list $package >/dev/null 2>&1 | grep -q '^ii' ; then
+ DEBIAN_FRONTEND=$DEBIAN_FRONTEND dpkg-reconfigure $package || \
+ echo "Warning: $package does not exist, can not reconfigure it."
+ fi
+ done
+ fi
+}
+# }}}
+
+# set password of user root {{{
+passwords()
+{
+ if [ -n "$NOPASSWORD" ] ; then
+ echo "Skip setting root password as requested."
+ return 0
+ fi
+
+ echo "Activating shadow passwords."
+ shadowconfig on
+
+ CHPASSWD_OPTION=
+ if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
+ CHPASSWD_OPTION='-m'
+ fi
+
+ if [ -n "$ROOTPASSWORD" ] ; then
+ echo root:"$ROOTPASSWORD" | chpasswd $CHPASSWD_OPTION
+ export ROOTPASSWORD=''
+ else
+ a='1'
+ b='2'
+ echo "Setting password for user root:"
+ while [ "$a" != "$b" ] ; do
+ echo -n "Enter new UNIX password for user root: "
+ askpass
+ a="$resp"
+ unset resp
+ echo
+ echo -n "Retype new UNIX password for user root: "
+ askpass
+ b="$resp"
+ unset resp
+ echo
+ if [ "$a" != "$b" ] ; then
+ echo "Sorry, passwords do not match. Retry."
+ a='1'
+ b='2'
+ else
+ echo root:"$a" | chpasswd $CHPASSWD_OPTION
+ unset a
+ unset b
+ fi
+ done
+ fi
+}
+# }}}
+
+# set up /etc/hosts {{{
+hosts() {
+ if [ -f /etc/hosts ] ; then
+ sed -i "s#127.0.0.1 .*#127.0.0.1 localhost $HOSTNAME#" /etc/hosts
+ [ -n "$HOSTNAME" ] && sed -i "s/grml/$HOSTNAME/g" /etc/hosts
+ else
+ cat > /etc/hosts << EOF
+127.0.0.1 localhost $HOSTNAME