+EOF
+ # make sure we have the keys available for aptitude
+ gpg --keyserver subkeys.pgp.net --recv-keys F61E2E7CECDEA787
+ gpg --export F61E2E7CECDEA787 | apt-key add - || /bin/true # not yet sure
+ # why it's necessary, sometimes we get an error even though it works [mika]
+
+ # make sure we install packages from grml's pool only if not available
+ # from Debian!
+ if ! grep -q grml /etc/apt/preferences 2>/dev/null ; then
+ cat >> /etc/apt/preferences << EOF
+// debian pool (default):
+Package: *
+Pin: release o=Debian
+Pin-Priority: 996
+
+// main grml-repository:
+Package: *
+Pin: origin deb.grml.org
+Pin-Priority: 991
+EOF
+ fi
+ fi
+}
+# }}}
+
+# set up kernel-img.conf {{{
+kernelimg_conf() {
+ if ! [ -r /etc/kernel-img.conf ] ; then
+ echo "Setting up /etc/kernel-img.conf"
+ cat > /etc/kernel-img.conf << EOF
+# Kernel Image management overrides
+# See kernel-img.conf(5) for details
+do_initrd = Yes
+do_symlinks = Yes
+EOF
+ fi
+}
+# }}}
+
+# create default devices {{{
+makedev() {
+ if ! [ -r /dev/hda20 ] ; then
+ echo "Creating generic devices in /dev - this might take a while..."
+ cd /dev && MAKEDEV generic
+ fi
+}
+# }}}
+
+# install additional packages {{{
+packages() {
+ if [ "$PACKAGES" = 'yes' ] ; then
+ if ! [ -r /etc/debootstrap/packages ] ; then
+ echo "Error: /etc/debootstrap/packages not found, exiting."
+ exit 1
+ else
+ $APTUPDATE
+ DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $(cat /etc/debootstrap/packages) $GRMLPACKAGES
+ fi
+ fi
+}
+# }}}
+
+# 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
+}
+# }}}
+
+# sarge specific stuff: mkinitrd {{{
+mkinitrd() {
+ if [ "$RELEASE" = 'sarge' ] ; then
+ sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
+ fi
+}
+# }}}
+
+# install kernel packages {{{
+kernel() {
+ # do not override $KERNEL if set via config file
+ if [ -z "$KERNEL" ] ; then
+ if [ "$ARCH" = 'i386' ] ; then
+ KERNEL='2.6-686'
+ elif [ "$ARCH" = 'amd64' ] ; then
+ KERNEL='2.6-amd64'
+ fi
+ fi
+
+ if [ -n "$KERNEL" ] ; then
+ $APTUPDATE
+ if [ "$RELEASE" = 'sarge' ] ; then
+ KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
+ else
+ KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
+ fi
+ DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $KERNELPACKAGES
+ fi
+}
+# }}}
+
+# reconfigure packages {{{
+reconfigure() {
+ if [ -n "$RECONFIGURE" ] ; then
+ for package in $RECONFIGURE ; do
+ dpkg --list $package 1>/dev/null 2>/dev/null && \
+ DEBIAN_FRONTEND=$DEBIAN_FRONTEND dpkg-reconfigure $package || \
+ echo "Warning: $package does not exist, can not reconfigure it."
+ done
+ fi
+}
+# }}}
+
+# set password of user root {{{
+setpassword() {
+# Set a password, via chpasswd.
+# Use perl rather than echo, to avoid the password
+# showing in the process table. (However, this is normally
+# only called when first booting the system, when root has no
+# password at all, so that should be an unnecessary precaution).
+#
+# Pass in three arguments: the user, the password, and 'true' if the
+# password has been pre-crypted (by preseeding).
+#
+# Taken from /var/lib/dpkg/info/passwd.config
+ SETPASSWD_PW="$2"
+ export SETPASSWD_PW
+
+ # This is very annoying. chpasswd cannot handle generating md5
+ # passwords as it is not PAM-aware. Thus, I have to work around
+ # that by crypting the password myself if md5 is used.
+ USE_MD5=1
+ export USE_MD5
+
+ if [ "$3" = true ]; then
+ PRECRYPTED=1
+ else
+ PRECRYPTED=''
+ fi
+ export PRECRYPTED
+ LC_ALL=C LANGUAGE=C LANG=C perl -e '
+ sub CreateCryptSalt {
+ my $md5 = shift;
+
+ my @valid = split(//, "./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
+ my ($in, $out);
+
+ my $cryptsaltlen = ($md5 ? 8 : 2);
+
+ open (F, "</dev/urandom") || die "No /dev/urandom found!";
+ foreach (1..$cryptsaltlen) {
+ read(F, $in, 1);
+ $out .= $valid[ord($in) % ($#valid + 1)];
+ }
+ close F;
+ return ($md5 ? "\$1\$$out\$" : $out);
+ }
+
+ open(P,"| chpasswd -e");
+ if ($ENV{PRECRYPTED}) {
+ print P shift().":$ENV{SETPASSWD_PW}\n";
+ } else {
+ print P shift().":".
+ crypt($ENV{SETPASSWD_PW}, CreateCryptSalt($ENV{USE_MD5})).
+ "\n";
+ }
+ close P;
+ ' "$1"
+ SETPASSWD_PW=''
+ USE_MD5=''
+ PRECRYPTED=''
+}
+
+passwords() {
+ echo "Activating shadow passwords."
+ shadowconfig on
+
+ if [ -n "$ROOTPASSWORD" ] ; then
+ setpassword root "$ROOTPASSWD" false
+ export ROOTPASSWD=''
+ else
+ echo "Setting password for user root:"
+ set +e # do not exit if passwd returns error due to missmatching passwords
+ until passwd; do echo "Please try again to set the password:" ; done
+ echo
+ set -e # restore default behaviour again
+ fi
+}
+# }}}
+
+# set up /etc/hosts {{{
+hosts() {
+ if ! [ -f /etc/hosts ] ; then
+ echo "Setting up /etc/hosts"
+ echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
+ fi
+}
+# }}}
+
+# set up /etc/network/interfaces {{{
+interfaces() {
+ touch /etc/network/interfaces
+ # make sure we add the entries only once
+ if ! grep -q eth0 /etc/network/interfaces ; then
+ echo "Setting up /etc/network/interfaces"
+ cat >> /etc/network/interfaces << EOF
+
+# loopback device: