+bailout(){
+ # make sure $TARGET is not mounted when exiting grml-debootstrap
+ if [ -n "$TARGET" ] ; then
+ if grep -q $TARGET /proc/mounts ; then
+ [ -x "$TARGET"/etc/init.d/ssh ] && "$TARGET"/etc/init.d/ssh stop
+ [ -x "$TARGET"/etc/init.d/mdadm ] && "$TARGET"/etc/init.d/mdadm stop
+ echo "Unmounting $TARGET"
+ umount "$TARGET"
+ fi
+ fi
+ [ -n "$1" ] && EXIT="$1" || EXIT="1"
+ exit "$EXIT"
+}
+
+stage() {
+ # error handling
+ if [ -z "$1" ] ; then
+ eerror 'Error: stage() requires at least one argument.'
+ eend 1
+ return 1
+ fi
+ if [ -z "$STAGES" ] ; then
+ eerror 'Error: $STAGES not set.'
+ eend 1
+ return 1
+ fi
+ # main function
+ if [ -f "$STAGES/$1" ] ; then
+ if grep -q done "$STAGES/$1" ; then
+ ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
+ fi
+ else
+ echo "$2" > "$STAGES/$1"
+ fi
+}
+
+trap bailout 1 2 3 15
+
+PARTITION=''
+DIRECTORY=''
+
+case $TARGET in
+ /dev/*)
+ PARTITION=1
+ ;;
+ *)
+ # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
+ DIRECTORY=1
+ MNTPOINT="$TARGET"
+ MKFS=''
+ TUNE2FS=''
+ FSCK=''
+ GRUB=''
+ GROOT=''
+ ;;
+esac
+
+# user should recheck his configuration
+einfo "$0 - Please recheck configuration before execution:"
+echo "
+ Target: $TARGET"
+ case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount-point: $MNTPOINT" ;; esac
+ [ -n "$GRUB" ] && echo " Install grub to: $GROOT / $GRUB"
+ case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
+ echo
+einfon "Is this ok for you? [y/N] "
+
+read a
+if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
+ eerror "Exiting as requested." ; eend 1
+ exit 1
+fi
+