As successfully uploaded to Extras-devel from my N900
[easy-deb-chroot] / fremantle / easy-chroot / .py2deb_build_folder / easy-chroot / src / sbin / qumount
1 #!/bin/sh
2 #Unmount a mounted MNTPT.
3 # By Alan M Bruce (qole)
4 #
5 # GPL licensed; keep code free!
6
7 if [ "`whoami`" != "root" ] ; then
8   echo "please run me as root!"
9   exit 9
10 fi
11
12 #Try to get the MNTPT location from the first parameter
13 MNTPT=$1
14
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
19   MNTPT=$CHROOT
20   #Still not set? FAIL
21   if [ "x$MNTPT" != x ] ; then
22     echo "No mountpoint to unmount!" >/dev/stderr
23     exit 8
24   fi
25 fi
26
27
28 TEST1=`mount | grep " $MNTPT "`
29
30 if [ "x$TEST1" != "x" ] ; then
31   echo "..Unmounting $MNTPT..." >/dev/stderr
32   umount -ld "$MNTPT"
33
34   TEST2=`mount | grep " $MNTPT "`
35
36   if [ "x$TEST2" != "x" ] ; then
37     echo "...$MNTPT didn't unmount!" >/dev/stderr
38     exit 8
39   fi
40 else
41   echo "$MNTPT is not mounted; Check for trailing slashes." >/dev/stderr
42 fi
43
44 if [ ! "x`grep device-mapper /proc/misc`" = "x" ] ; then
45   LOOPDEV=`echo $TEST1 | cut -f1 -d' '`
46   while [ "x`echo $LOOPDEV | grep dm-`" != "x" ] ; do
47     LOOPNO=`echo $LOOPDEV | awk -F '-' '{print $NF}'`
48     echo "..Unmounting turbo loop ($LOOPNO)..." >/dev/stderr
49     dmlosetup -d /dev/loop$LOOPNO
50     if [ "$?" != 0 ] || [ "x`dmsetup status | grep loop$LOOPNO`" != "x" ] ; then
51       echo "Waiting for apps to terminate, will try again." >/dev/stderr
52       sleep 5
53       dmlosetup -d /dev/loop$LOOPNO 
54       if [ "$?" != 0 ] ; then
55         echo "Can't unmount turbo-loop! Try dmlosetup -d /dev/loop$LOOPNO manually." >/dev/stderr
56         exit 9
57       fi
58     fi
59     LOOPDEV=`mount | grep " $MNTPT " | cut -f1 -d' '`
60   done
61 fi
62
63 echo "successful unmount..." >/dev/stderr
64 exit 0