2 #Unmount a mounted MNTPT.
3 # By Alan M Bruce (qole)
5 # GPL licensed; keep code free!
7 if [ "`whoami`" != "root" ] ; then
8 echo "please run me as root!"
12 #Try to get the MNTPT location from the first parameter
15 #Try to get the MNTPT location from the config file...
16 if [ "x$MNTPT" = x ] ; then
17 #Pull in the config, if possible...
18 [ -f /home/user/.chroot ] && . /home/user/.chroot
21 if [ "x$MNTPT" != x ] ; then
22 echo "No mountpoint to unmount!" >/dev/stderr
27 # Strip off a trailing slash
28 LASTCHAR=`echo $MNTPT | cut -c ${#MNTPT}`
29 if [ "$LASTCHAR" = "/" ] ; then
30 echo "..stripping trailing slash..." >/dev/stderr
31 MNTPT=`echo $MNTPT | cut -c 0-$((${#MNTPT}-1))`
34 TEST1=`mount | grep " $MNTPT "`
36 if [ "x$TEST1" != "x" ] ; then
37 echo "..Unmounting $MNTPT..." >/dev/stderr
40 TEST2=`mount | grep " $MNTPT "`
42 if [ "x$TEST2" != "x" ] ; then
43 echo "...$MNTPT didn't unmount!" >/dev/stderr
47 echo "$MNTPT is not mounted; Check for trailing slashes." >/dev/stderr
50 if [ ! "x`grep device-mapper /proc/misc`" = "x" ] ; then
51 LOOPDEV=`echo $TEST1 | cut -f1 -d' '`
52 while [ "x`echo $LOOPDEV | grep dm-`" != "x" ] ; do
53 LOOPNO=`echo $LOOPDEV | awk -F '-' '{print $NF}'`
54 echo "..Unmounting turbo loop ($LOOPNO)..." >/dev/stderr
55 dmlosetup -d /dev/loop$LOOPNO
56 if [ "$?" != 0 ] || [ "x`dmsetup status | grep loop$LOOPNO`" != "x" ] ; then
57 echo "Waiting for apps to terminate, will try again." >/dev/stderr
59 dmlosetup -d /dev/loop$LOOPNO
60 if [ "$?" != 0 ] ; then
61 echo "Can't unmount turbo-loop! Try dmlosetup -d /dev/loop$LOOPNO manually." >/dev/stderr
65 LOOPDEV=`mount | grep " $MNTPT " | cut -f1 -d' '`
69 echo "successful unmount..." >/dev/stderr