- [ -n "$LOCALES" ] && cp /etc/debootstrap/locale.gen $MNTPOINT/etc/locale.gen
-
- # copy any existing existing files to chroot
- [ -d /etc/debootstrap/boot ] && cp -a /etc/debootstrap/boot/* $MNTPOINT/boot/
- [ -d /etc/debootstrap/etc ] && cp -a /etc/debootstrap/etc/* $MNTPOINT/etc/
- [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
- [ -d /etc/debootstrap/usr ] && cp -a /etc/debootstrap/usr/* $MNTPOINT/usr/
- [ -d /etc/debootstrap/var ] && cp -a /etc/debootstrap/var/* $MNTPOINT/var/
-eend 0
-
-einfo "Executing chroot-script now"
-chroot $MNTPOINT /bin/chroot-script
-eend $?
-
-# einfo "Removing chroot-script"
-# rm -f $MNTPOINT/bin/chroot-script
-# rm -rf $MNTPOINT/etc/debootstrap/
-# eend $?
-
-if [ -z "$MBR" ] ; then
- echo "Notice: \$MBR not set, will not install grub therefor."
-else
- einfo "Installing grub on ${MBR}:"
- grub-install --root-directory="$MNTPOINT" "(${MBR})"
+ [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
+
+ # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
+ ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
+
+ # copy any existing files to chroot
+ [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
+ [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
+ [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
+ [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
+ [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
+ [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
+ [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
+
+ # copy local network setup to chroot
+ if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
+ [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
+ cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
+ fi
+
+ eend 0
+}
+# }}}
+
+# execute all scripts in /etc/debootstrap/pre-scripts/ {{{
+execute_pre_scripts() {
+ # make sure we have $MNTPOINT available for our scripts
+ export MNTPOINT
+ if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
+ [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
+ for script in ${pre_scripts}/* ; do
+ if [ -x "$script" ] ; then
+ einfo "Executing pre-script $script"
+ $script ; eend $?
+ fi
+ done
+ fi
+}
+# }}}
+
+# execute all scripts in /etc/debootstrap/scripts/ {{{
+execute_scripts() {
+ # make sure we have $MNTPOINT available for our scripts
+ export MNTPOINT
+ if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
+ [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
+ for script in ${scripts}/* ; do
+ if [ -x "$script" ] ; then
+ einfo "Executing script $script"
+ $script ; eend $?
+ fi
+ done
+ fi
+}
+# }}}
+
+# execute chroot-script {{{
+chrootscript() {
+ if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
+ mount_target
+ fi
+
+ if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
+ einfo "Executing chroot-script now"
+ mount --bind /dev "$MNTPOINT"/dev
+ chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
+ umount "$MNTPOINT"/dev
+ eend $RC
+ else
+ eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
+ eend 1
+ fi
+}
+# }}}
+
+# install booloader grub {{{
+grub_install() {
+ if [ -z "$GRUB" ] ; then
+ echo "Notice: \$GRUB not defined, will not install grub therefore."
+ return 0
+ fi
+
+ if ! [ -x "$(which grub-install)" ] ; then
+ echo "Error: grub-install not available. (Error while installing grub package?)"
+ return 1
+ fi
+
+ if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
+ for device in $SELECTED_PARTITIONS ; do
+ GRUB="${device%%[0-9]}"
+ einfo "Installing grub on ${GRUB}:"
+ grub-install --no-floppy --root-directory="$MNTPOINT" "$GRUB"
+ eend $?
+ done
+ else
+ einfo "Installing grub on ${GRUB}:"
+ grub-install --no-floppy --root-directory="$MNTPOINT" "$GRUB"
+ eend $?
+ fi
+}
+# }}}
+
+# unmount $MNTPOINT {{{
+umount_chroot() {
+
+ # display installation notes:
+ if [ -n "$INSTALL_NOTES" ] ; then
+ [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
+ fi
+
+ if [ -n "$ISODIR" ] ; then
+ if grep -q "$ISODIR" /proc/mounts ; then
+ einfo "Unmount $MNTPOINT/$ISODIR"
+ umount "$MNTPOINT/$ISODIR"
+ eend $?
+ fi
+ fi
+
+ if grep -q "$MNTPOINT" /proc/mounts ; then
+ if [ -n "$PARTITION" ] ; then
+ einfo "Unmount $MNTPOINT"
+ umount $MNTPOINT
+ eend $?
+ fi
+ fi
+}
+# }}}
+
+# execute filesystem check {{{
+fscktool() {
+ if [ "$FSCK" = 'yes' ] ; then
+ [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
+ einfo "Checking filesystem on $TARGET using $FSCKTOOL"
+ $FSCKTOOL $TARGET
+ eend $?
+ fi
+}
+# }}}
+
+# now execute all the functions {{{
+for i in mkfs tunefs mount_target debootstrap_system preparechroot \
+ execute_pre_scripts chrootscript execute_scripts grub_install umount_chroot \
+ fscktool ; do
+ if stage "${i}" ; then
+ $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
+ fi
+done
+# }}}
+
+# finalize {{{
+if [ -n "$ISODIR" ] ; then
+ einfo "Unmounting Debian image loopback from $MNTPOINT/$ISODIR."
+ umount "$MNTPOINT/$ISODIR"