-if [ -z "$GROOT" ] ; then
- echo "Warning: \$GROOT is not defined, can not adjust grub configuration therefor."
-else
- echo "Adjusting grub configuration for use on ${GROOT}."
-
- # copy stage-files to /boot/grub/
- [ -d /boot/grub/ ] || mkdir /boot/grub
- if [ -d /usr/lib/grub/i386-pc/ ] ; then
- cp /usr/lib/grub/i386-pc/* /boot/grub/
- else
- # sarge ships grub files in another directory
- cp /lib/grub/i386-pc/* /boot/grub/
- fi
-
- # finally install grub
- update-grub -y
- sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
- sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro|g" /boot/grub/menu.lst
- # not sure why savedefault does not work for me; any ideas?
- sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
- update-grub -y
-fi
+ # listen on loopback interface only:
+ sed -i "s/^inet_interfaces = .*/inet_interfaces = loopback-only/" /etc/postfix/main.cf
+ grep -q inet_interfaces /etc/postfix/main.cf || echo 'inet_interfaces = loopback-only' >> /etc/postfix/main.cf
+ fi
+ fi
+}
+# }}}
+
+# generate initrd/initramfs {{{
+initrd() {
+ # assume the first available kernel as our main kernel
+ KERNELIMG=$(ls -1 /boot/vmlinuz-* 2>/dev/null | head -1)
+ if [ -z "$KERNELIMG" ] ; then
+ echo 'No kernel image found, skipping initrd stuff.'>&2
+ return
+ fi
+
+ KERNELVER=${KERNELIMG#/boot/vmlinuz-}
+
+ # generate initrd
+ if [ -n "$INITRD" ] ; then
+ echo "Generating initrd."
+ update-initramfs -c -t -k $KERNELVER
+ fi
+}
+# }}}
+
+# grub configuration/installation {{{
+grub_config() {
+ if [ -z "$GRUB" ] ; then
+ echo "Warning: \$GRUB is not defined, will not adjust grub configuration therefore."
+ else
+ echo "Adjusting grub configuration for use on ${GRUB}."
+
+ # finally install grub
+ if [ -x /usr/sbin/update-grub ] ; then
+ UPDATEGRUB='/usr/sbin/update-grub'
+ elif [ -x /sbin/update-grub ] ; then
+ UPDATEGRUB='/sbin/update-grub'
+ else
+ echo "Error: update-grub not available, can not execute it."
+ return 1
+ fi
+
+ # grub2:
+ $UPDATEGRUB
+ fi
+}
+# }}}
+
+# execute all scripts present in /etc/debootstrap/chroot-scripts/ {{{
+custom_scripts() {
+ [ -d /etc/debootstrap/chroot-scripts/ ] || return 0
+
+ for script in /etc/debootstrap/chroot-scripts/* ; do
+ echo "Executing script $script"
+ $script && echo "done" || echo "failed"
+ done
+}
+# }}}
+
+# make sure we don't have any running processes left {{{
+services() {
+ for service in ssh mdadm mdadm-raid ; do
+ if [ -x /etc/init.d/"$service" ] ; then
+ /etc/init.d/"$service" stop || true
+ fi
+ done
+}
+# }}}
+
+# unmount /proc and make sure nothing is left {{{
+finalize() {
+ # make sure we don't leave any sensible data
+ rm -f /etc/debootstrap/variables
+
+ [ -n "$POLICYRCD" ] && rm -f /usr/sbin/policy-rc.d
+
+ umount /proc >/dev/null 2>/dev/null || true
+}
+# }}}
+
+# signal handler {{{
+signal_handler() {
+ finalize
+ [ -n "$1" ] && EXIT="$1" || EXIT="1"
+ exit "$EXIT"
+}
+# }}}
+
+# set signal handler {{{
+trap signal_handler HUP INT QUIT TERM
+# }}}
+
+# execute the functions {{{