Unmount loopback device at the end too
[grml-debootstrap.git] / grml-debootstrap
index de15471..990566f 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: Die Jun 05 14:02:22 CEST 2007 [mika]
 ################################################################################
 # http://www.debian.org/releases/stable/i386/index.html.en
 
 set -e # exit on any error
 
-VERSION='0.9'
+VERSION='0.10'
 
 # 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)
@@ -163,11 +163,12 @@ fi
 # make sure we have the right syntax when using an iso image
 case $ISO in
    file*) # do nothing
-    ;
+    ;;
    *)
     ISO=file:$1
     ;;
 esac
+ISODIR=${ISO##file:}
 
 # provide variables to chroot system
 touch /etc/debootstrap/variables
@@ -177,6 +178,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
@@ -202,7 +204,7 @@ bailout(){
         [ -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
-        [ -d "$TARGET/$ISO" ] && umount "$TARGET/$ISO"
+        [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
         einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
      fi
   fi
@@ -296,9 +298,11 @@ mount_target() {
        eend $?
      fi
   fi
-  if [ -n "$ISO" ] ; then
-     mkdir "$TARGET/$ISO"
-     mount --bind "$ISO" "$TARGET/$ISO"
+  if [ -n "$ISODIR" ] ; then
+     einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
+     mkdir -p "$MNTPOINT/$ISODIR"
+     mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
+     eend $?
   fi
 }
 # }}}
@@ -381,6 +385,11 @@ grub_install() {
 
 # unmount $MNTPOINRT {{{
 umount_chroot() {
+  if [ -n "$ISODIR" ] ; then
+     einfo "Unmount $MNTPOINT/$ISODIR"
+     umount "$MNTPOINT/$ISODIR"
+     eend $?
+  fi
   if [ -n "$PARTITION" ] ; then
      einfo "Unmount $MNTPOINT"
      umount $MNTPOINT