+# define chroot mirror {{{
+chrootmirror() {
+ [ -n "$KEEP_SRC_LIST" ] && return
+ [ -z "$COMPONENTS" ] && COMPONENTS='main contrib non-free'
+
+ if [ -n "$ISO" ] ; then
+ echo "deb $ISO $RELEASE $COMPONENTS" > /etc/apt/sources.list
+ [ -n "$MIRROR" ] && echo "deb $MIRROR $RELEASE $COMPONENTS" >> /etc/apt/sources.list || true
+ else
+ if [ -n "$MIRROR" ] ; then
+ echo "deb $MIRROR $RELEASE $COMPONENTS" > /etc/apt/sources.list
+ fi
+ fi
+}
+# }}}
+
+# set up grml repository {{{
+grmlrepos() {
+ if [ -n "$GRMLREPOS" ] ; then
+ # user might have provided their own apt sources.list
+ if ! grep -q grml /etc/apt/sources.list 2>/dev/null ; 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
+ fi
+
+ # make sure we have the keys available for aptitude
+ gpg --keyserver subkeys.pgp.net --recv-keys F61E2E7CECDEA787
+ gpg --export F61E2E7CECDEA787 | apt-key add - || 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
+}
+# }}}
+
+# make sure services do not start up {{{
+install_policy_rcd() {
+ if ! [ -r /usr/sbin/policy-rc.d ] ; then
+ export POLICYRCD=1
+ cat > /usr/sbin/policy-rc.d << EOF
+#!/bin/sh
+exit 101
+EOF
+ chmod 775 /usr/sbin/policy-rc.d
+ fi
+}
+# }}}
+
+# remove now useless apt cache {{{
+remove_apt_cache() {
+ apt-get clean
+}
+# }}}
+
+# install additional packages {{{
+packages() {
+ # Pre-seed the debconf database with answers. Each question will be marked
+ # as seen to prevent debconf from asking the question interactively.
+ [ -f /etc/debootstrap/debconf-selections ] && {
+ echo "Preseeding the debconf database, some lines might be skipped..."
+ cat /etc/debootstrap/debconf-selections | debconf-set-selections
+ }
+
+ 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 $(grep -v '^#' /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
+}
+# }}}
+
+# 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
+ # note: install busybox to be able to debug initramfs
+ KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL busybox"
+ 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 {{{
+passwords()
+{
+ 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: "
+ read -s a
+ echo
+ echo -n "Retype new UNIX password for user root: "
+ read -s b
+ 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