+if [ -n "$ARCH" ] ; then
+ ARCHCMD="--arch $ARCH"
+ ARCHINFO=" (${ARCH})"
+else
+ ARCH="$(dpkg --print-architecture)"
+ ARCHCMD="--arch $ARCH"
+ ARCHINFO=" (${ARCH})"
+fi
+
+# provide variables to chroot system
+[ -n "$ARCH" ] && echo "ARCH=$ARCH" > /etc/debootstrap/variables
+[ -n "$GRUB" ] && echo "GRUB=$GRUB" >> /etc/debootstrap/variables
+[ -n "$GROOT" ] && echo "GROOT=$GROOT" >> /etc/debootstrap/variables
+[ -n "$TARGET" ] && echo "TARGET=$TARGET" >> /etc/debootstrap/variables
+[ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> /etc/debootstrap/variables
+[ -n "$CHROOTMIRROR" ] && echo "CHROOTMIRROR=$CHROOTMIRROR" >> /etc/debootstrap/variables
+
+# make sure at least $TARGET is set [the partition for the new system]
+if [ -z "$TARGET" ] ; then
+ eerror "Please adjust /etc/debootstrap/config before running ${0}" ; eend 1
+ exit 1
+fi
+# }}}
+
+# helper functions {{{
+# we want to exit smoothly and clean:
+bailout(){
+ # make sure $TARGET is not mounted when exiting grml-debootstrap
+ if [ -n "$MNTPOINT" ] ; then
+ if grep -q $MNTPOINT /proc/mounts ; then
+ # make sure nothing is left inside chroot so we can unmount it
+ [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
+ [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
+ # ugly, but make sure we really don't leav anything
+ [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
+ [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
+ [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
+ [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
+ einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
+ fi
+ fi
+ [ -n "$1" ] && EXIT="$1" || EXIT="1"
+ [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
+ exit "$EXIT"
+}
+trap bailout 1 2 3 15
+
+# we want to execute all the functions only once, simple check for it:
+stage() {
+ if [ -n "$2" ] ; then
+ echo "$2" > "$STAGES/$1"
+ return 0
+ elif grep -q done "$STAGES/$1" 2>/dev/null ; then
+ ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
+ return 1
+ fi
+}
+# }}}
+
+# user should recheck his configuration {{{