+# define chroot mirror {{{
+chrootmirror() {
+ if [ -n "$CHROOTMIRROR" ] ; then
+ echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /etc/apt/sources.list
+ fi
+}
+# }}}
+
+# set up grml repository {{{
+grmlrepos() {
+ if [ -n "$GRMLREPOS" ] ; then
+ cat >> /etc/apt/sources.list << EOF
+
+# grml: stable repository:
+ deb http://deb.grml.org/ grml-stable main
+ deb-src http://deb.grml.org/ grml-stable main
+
+# grml: testing/development repository:
+ deb http://deb.grml.org/ grml-testing main
+ deb-src http://deb.grml.org/ grml-testing main
+
+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]
+
+ 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
+}
+# }}}
+
+# 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