Better inform user about already executed stages
[grml-debootstrap.git] / grml-debootstrap
index 27955fb..d191161 100755 (executable)
@@ -4,13 +4,13 @@
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2.
-# Latest change: Mon Apr 16 20:39:13 CEST 2007 [mika]
+# Latest change: Sam Okt 06 18:01:53 CEST 2007 [mika]
 ################################################################################
 # http://www.debian.org/releases/stable/i386/index.html.en
 
 set -e # exit on any error
 
-VERSION='0.9'
+VERSION='0.11'
 
 # source core functions {{{
 . /etc/grml/lsb-functions
@@ -96,7 +96,7 @@ while [ "$#" -gt "0" ] ; do
             ;;
         -i|--iso)
             shift
-           [ -n "$MIRROR" ] && unset MIRROR
+            [ -n "$MIRROR" ] && unset MIRROR
             ISO=$1
             ;;
         -h|--help)
@@ -125,7 +125,7 @@ if [ -z "$STAGES" ] ; then
    [ -d "$STAGES" ] || mkdir -p "$STAGES"
 fi
 
-if [ -r $STAGES/grml-debootstrap ] ; then
+if [ -r "$STAGES"/grml-debootstrap ] ; then
    if grep -q done $STAGES/grml-debootstrap ; then
       eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
       eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
@@ -169,6 +169,7 @@ case $ISO in
     ;;
 esac
 ISODIR=${ISO##file:}
+ISODIR=${ISODIR%%/}
 
 # provide variables to chroot system
 touch /etc/debootstrap/variables
@@ -178,6 +179,7 @@ chmod 600 /etc/debootstrap/variables # make sure nobody except root can read it
 [ -n "$GROOT" ]  && echo "GROOT=$GROOT"   >> /etc/debootstrap/variables
 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> /etc/debootstrap/variables
 [ -n "$ISO" ]    && echo "ISO=$ISO"       >> /etc/debootstrap/variables
+[ -n "$ISODIR" ] && echo "ISODIR=$ISO"    >> /etc/debootstrap/variables
 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> /etc/debootstrap/variables
 [ -n "$MIRROR" ] && echo "CHROOTMIRROR=$MIRROR" >> /etc/debootstrap/variables
 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> /etc/debootstrap/variables
@@ -220,6 +222,9 @@ stage() {
      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
+     eindent
+       ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
+     eoutdent
      return 1
   fi
 }
@@ -298,8 +303,10 @@ mount_target() {
      fi
   fi
   if [ -n "$ISODIR" ] ; then
+     einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
      mkdir -p "$MNTPOINT/$ISODIR"
      mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
+     eend $?
   fi
 }
 # }}}
@@ -382,10 +389,19 @@ grub_install() {
 
 # unmount $MNTPOINRT {{{
 umount_chroot() {
-  if [ -n "$PARTITION" ] ; then
-     einfo "Unmount $MNTPOINT"
-     umount $MNTPOINT
-     eend $?
+  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
 }
 # }}}