/
umount
executable file
·62 lines (53 loc) · 2.12 KB
/
umount
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
#Barry Kauler 2006 www.puppylinux.com
#2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
#exec &> /tmp/umount.log
[ ! $1 ] && exec umount-FULL
#remove everything except the device or mntpt...
LASTPARAM="`echo -n "$*" | tr '\t' ' ' | tr -s ' ' | tr ' ' '\n' | grep '^/'`"
if [ "$LASTPARAM" != "" ] ; then
if [ -b "$1" ] ; then
# block device
DEVNAME=$(basename "$LASTPARAM")
else
# mountpoint
DEVNAME=$(mount-FULL -v | grep " $LASTPARAM " | cut -f 1 -d " ")
DEVNAME=$(basename "$DEVNAME")
fi
fi
umount-FULL -d "$@" #-d = free loop device
RETVAL=$?
if [ -z "$DEVNAME" -o ! -b /dev/${DEVNAME} ] ; then
exit $RETVAL
fi
#ROX: if there is a desktop icon (see pup_event_frontend_d), then refresh it...
if [ $RETVAL -eq 0 -a "$(pidof ROX-Filer)" != "" ];then
. /usr/local/pup_event/frontend_funcs #rox
case $DEVNAME in #mmcblk0p1, nvme0n1p1
mmcblk*|nvme*) DRVNAME="${DEVNAME%p*}" ;; #remove trailing p*
*) DRVNAME="`echo -n "$DEVNAME" | cut -c 1-3`" ;;
esac
DRV_CATEGORY="`probedisk /dev/${DRVNAME} | cut -f 2 -d '|'`"
[ -d /root/.pup_event/drive_${DEVNAME} ] && DRVNAME="$DEVNAME" #icon for each partition. ex: DRVNAME=sda1
if [ -d /root/.pup_event/drive_${DRVNAME} ];then
#if any partitions still mounted, leave "MNTD" on icon...
drvPATTERN='^/dev/'"${DRVNAME} "
#"MNTD" text is intended as a reminder to user that drive needs to be unmounted,
# but partitions in use by Puppy cannot be unmounted.
if [ "`mount-FULL -v | tr -s ' ' | cut -f 1,3 -d ' ' | grep "$drvPATTERN" | grep -v ' /initrd/' | grep -v ' /$'`" = "" ];then
if [ "`mount-FULL -v | tr -s ' ' | cut -f 1,3 -d ' ' | grep "$drvPATTERN" | grep -E ' /initrd/| /$'`" != "" ];then
#only a partition left mntd that is in use by puppy, change green->yellow...
icon_mounted_func $DRVNAME $DRV_CATEGORY #see frontend_funcs
else
#redraw icon without "MNTD" text...
icon_unmounted_func $DRVNAME $DRV_CATEGORY #see frontend_funcs
fi
fi
fi
fi
#v409, instead just make sure the symlink stays there...
if [ ! -L /etc/mtab ];then
rm -f /etc/mtab
ln -s /proc/mounts /etc/mtab
fi
exit $RETVAL