db989741dc06c9c4260c8fd0106d9cc72d45448a
[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 # 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))`
32 fi
33
34 TEST1=`mount | grep " $MNTPT "`
35
36 if [ "x$TEST1" != "x" ] ; then
37   echo "..Unmounting $MNTPT..." >/dev/stderr
38   umount -ld "$MNTPT"
39
40   TEST2=`mount | grep " $MNTPT "`
41
42   if [ "x$TEST2" != "x" ] ; then
43     echo "...$MNTPT didn't unmount!" >/dev/stderr
44     exit 8
45   fi
46 else
47   echo "$MNTPT is not mounted; Check for trailing slashes." >/dev/stderr
48 fi
49
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
58       sleep 5
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
62         exit 9
63       fi
64     fi
65     LOOPDEV=`mount | grep " $MNTPT " | cut -f1 -d' '`
66   done
67 fi
68
69 echo "successful unmount..." >/dev/stderr
70 exit 0