+ # finally install grub
+ if [ -x /usr/sbin/update-grub ] ; then
+ UPDATEGRUB='/usr/sbin/update-grub'
+ else
+ UPDATEGRUB='/sbin/update-grub'
+ fi
+ $UPDATEGRUB -y
+
+ if [ -f /boot/grub/menu.lst ] ; then
+ sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
+ case "$TARGET" in
+ # do NOT use uuid with SW-RAID
+ /dev/md*)
+ sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
+ ;;
+ *)
+ if [ -n "$TARGET_UUID" ] ; then
+ sed -i "s|^# kopt=root=.*|# kopt=root=UUID=${TARGET_UUID} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
+ else
+ sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
+ fi
+ ;;
+ esac
+
+ # not sure why savedefault does not work for me; any ideas?
+ sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
+ $UPDATEGRUB -y
+ fi
+ 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 || /bin/true
+ fi
+ done
+}
+# }}}
+
+# unmount all filesystems in chroot, 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 -a 1>/dev/null 2>/dev/null || true
+ umount /proc 1>/dev/null 2>/dev/null || true
+ umount /proc 1>/dev/null 2>/dev/null || true
+ umount -a 1>/dev/null 2>/dev/null || true
+}
+# }}}