Easy Chroot 0.3.1
[easy-deb-chroot] / fremantle / easy-chroot / src / sbin / qchroot
index 799ae5b..8955351 100755 (executable)
@@ -23,6 +23,13 @@ shift 1
 
 # echo ezchroot $IMGFILE $CHROOT $*
 
+# Strip off a trailing slash
+LASTCHAR=`echo $CHROOT | cut -c ${#CHROOT}`
+if [ "$LASTCHAR" = "/" ] ; then
+   echo "..stripping trailing slash..." >/dev/stderr
+   CHROOT=`echo $CHROOT | cut -c 0-$((${#CHROOT}-1))`
+fi
+
 qmount $IMGFILE $CHROOT
 MOUNTSUCCESS=$?
 
@@ -126,14 +133,18 @@ fi
 trap "rm -f $CHROOT/var/lock/chroot-complete ; echo -ne '\033]0;osso_xterm\007' ; exit" INT TERM EXIT
 echo $IMGFILE $@ > "$CHROOT/var/lock/chroot-complete"
 
-#If the file is mounted on loop, use that label.
-
 #Custom prompt and xterm title. Reduces confusion.
 CHRLABEL=`blkid -s LABEL $IMGFILE | cut -d' ' -f2 | cut -d'=' -f2 | sed 's/"//g'`
 
 #If the file is mounted on loop, use that label.
 if [ "x$CHRLABEL" = "x" ] ; then
-  CHRLABEL=`blkid -s LABEL /dev/loop0 | cut -d' ' -f2 | cut -d'=' -f2 | sed 's/"//g'`
+
+  # first find the loop
+  LOOPNO=`mount | grep loop | grep $CHROOT | awk '{print $1}'`
+
+  if [ "x$LOOPNO" != "x" ] ; then
+     CHRLABEL=`blkid -s LABEL $LOOPNO | cut -d' ' -f2 | cut -d'=' -f2 | sed 's/"//g'`
+  fi
 fi
 
 if [ "x$CHRLABEL" = "x" ] ; then