/
mount
executable file
·169 lines (149 loc) · 6.19 KB
/
mount
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/sh
#BK 2006 www.puppylinux.com
#2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
#v407 fix for floppy drive icon.
#v409 gparted create ext3 part. failed, fixed by making /etc/mtab a symlink.
#120103 shinobar: need 'silent' option for ntfs-3g, avoid err msgs, permissions lost when copy.
#130203 change probedisk2 to probedisk.
#mount-FULL, umount-FULL, losetup-FULL are the full versions.
#The Busybox versions of mount and umount are available but only by:
# # busybox mount ...
# # busybox umount ...
#mount and umount are now scripts.
#if an ntfs partition, puppy uses user-mode ntfs-3g driver.
#the mount and umount scripts allow seamless mounting and unmounting of ntfs f.s.
[ ! $1 ] && exec busybox mount
[ "`whoami`" != "root" ] && exec sudo -A ${0} ${@}
if grep -q fido /etc/inittab ; then
USER_OTPS="uid=1001,gid=500," #fido
USER_OTPS_2="-o uid=1001,gid=500" #fido
fi
#i realised this script has to allow reentrancy. So, all temp file now unique,
#using ${$} which is pid of script.
MYPID=${$}
. /usr/local/pup_event/frontend_funcs #rox
#v2.12 discovered difference between $@ and $*. Replaced all $@ with $* in this script...
#extract all the '-' options, on separate lines... do NOT use $@!!!!...
#v3.93 eliminate ' -- ' and all past it...
DASHOPTS="`echo "$*" | tr '\t' ' ' | sed -e 's/ -- .*//' | tr ' ' '\n' | grep '^\-'`"
case "$*" in
*' vfat '*) VFAT_FLAG=yes ;;
*' exfat '*) EXFAT_FLAG=yes ;;
*' ntfs '*) NTFS_FLAG=yes ;;
*' crypto_LUKS '*) LUKS_FLAG=yes ;;
esac
if [ "$VFAT_FLAG" = "yes" ];then
case "$@" in
*"-o "*) #don't override -o
mount-FULL -n "${@}"
;;
*)
CMDPRMS="`echo -n "$*" | tr '\t' ' ' | tr -s ' ' | tr ' ' '\n' | grep '^/' | tr '\n' ' '`"
NLS_PARAM=""
if [ -f /etc/codepage ]; then
grep -q -i '850' /etc/codepage && [ "$(echo $LANG|cut -d'.' -f1)" != "en_US" ] && NLS_PARAM=",codepage=850"
grep -q -i '852' /etc/codepage && NLS_PARAM=",codepage=852,iocharset=iso8859-2"
fi
grep '^LANG=' /etc/profile | grep -q -i -E '\.utf|\.UTF' && NLS_PARAM="$NLS_PARAM,utf8"
OPT="-o ${USER_OTPS}shortname=mixed,quiet${NLS_PARAM}"
mount-FULL -t vfat ${OPT} -n $CMDPRMS
;;
esac
RETVAL=$?
elif [ "$EXFAT_FLAG" = "yes" ];then
#older mount version: exfat systems fail with mount-FULL -n
mount-FULL "${@}" || {
# musl static mount.exfat fails
# however it works if calling the right app directly
# note: filemnt still fails. but it has extra code to make it work..
wc=$(echo "${@}" | tr -s ' ' | wc -w)
args=$(echo "$@" | cut -f "$(($wc-1))-" -d ' ')
mount.exfat-fuse ${args}
}
RETVAL=$?
elif [ "$LUKS_FLAG" = "yes" ] ; then
exec mount.crypto_LUKS "$@" #mount.crypto_LUKS has specific rox code
elif [ "$NTFS_FLAG" = "yes" ];then
case "$@" in
*"-o "*) #don't override -o
ntfs-3g "${@}" || busybox mount "${@}"
RETVAL=$?
;;
*)
#screen out all the options...
CMDPRMS="`echo -n "$*" | tr '\t' ' ' | tr -s ' ' | tr ' ' '\n' | grep '^/' | tr '\n' ' '`"
#kirk advised these options so Rox will not complain about file
#permissions when copy a file to a ntfs partition...
[ -f /tmp/ntfsmnterr${MYPID}.txt ] && rm -f /tmp/ntfsmnterr${MYPID}.txt
ntfs-3g $CMDPRMS -o ${USER_OTPS}silent 2>/tmp/ntfsmnterr${MYPID}.txt
RETVAL=$?
#v2.16 ntfs-3g v1.417, part. scheduled for check, failed with value 10...
#v4.00 ntfs-3g v1.2412 does not have 4,10, has 15 for dirty f.s., 14 hiberneted...
case $RETVAL in 4|10|15) #14 = must mount read-only
ntfs-3g $CMDPRMS -o ${USER_OTPS}force,silent 2>/tmp/ntfsmnterr${MYPID}.txt
RETVAL=$?
ERRMSG1="`cat /tmp/ntfsmnterr${MYPID}.txt`"
echo "$ERRMSG1"
if [ $RETVAL -eq 0 ];then
echo "WARNING: NTFS f.s. mounted read/write but corrupted."
[ ! "`pidof X`" = "" ] && nohup gxmessage -bg red -center -title "NTFS WARNING" "The ntfs-3g driver was able to mount the NTFS
partition but returned this error message:
$ERRMSG1
It is mounted read/write, but advice is only write
to it in emergency situation. Recommendation is
boot Windows and fix the filesystem first!!!" &
fi
[ ! -s /tmp/ntfsmnterr${MYPID}.txt ] && rm -f /tmp/ntfsmnterr${MYPID}.txt
;;
esac
#ntfs-3g plays very safe and will not mount if thinks anything
#wrong with ntfs f.s. But, we may want to recover files from a
#damaged windows. So, fall back to the kernel ntfs driver...
if [ ! $RETVAL -eq 0 ];then
#mount read-only...
busybox mount -r -t ntfs $CMDPRMS
RETVAL=$?
ERRMSG1="`cat /tmp/ntfsmnterr${MYPID}.txt`"
echo "$ERRMSG1"
if [ $RETVAL -eq 0 ];then
echo "WARNING: NTFS f.s. mounted read-only."
[ ! "`pidof X`" = "" ] && nohup gxmessage -bg red -center -title "NTFS WARNING" "The ntfs-3g driver was unable to mount the NTFS
partition and returned this error message:
$ERRMSG1
So, the inbuilt kernel NTFS driver has been used
to mount the partition read-only." &
fi
fi
;;
esac
### everything else ###
else
#needs an explicit '-t ntfs', does not work with /etc/fstab...
# busybox mount does not support '--bind'
# as have mtab file (see below), can now use full mount...
# v409 put in '-n' option as now have /etc/mtab symlink to /proc/mounts...
mount-FULL -n "${@}" #SFR quotes
RETVAL=$?
fi
#v4.02 if there is a desktop icon (see pup_eventd), then refresh it...
if [ $RETVAL -eq 0 -a "$(pidof ROX-Filer)" != "" ];then
DEVNAME="`busybox mount | tail -n 1 | grep '^/dev/' | cut -f 1 -d ' ' | cut -f 3 -d '/'`"
if [ "$DEVNAME" != "" ];then
case $DEVNAME in #mmcblk0p1, nvme0n1p1
mmcblk*|nvme*) DRVNAME="${DEVNAME%p*}" ;; #remove trailing p*
*) DRVNAME="`echo -n "$DEVNAME" | cut -c 1-3`" ;;
esac
xDRVNAME="$DRVNAME" #v404
[ -d /root/.pup_event/drive_${DEVNAME} ] && DRVNAME="$DEVNAME" #icon for each partition.
if [ -d /root/.pup_event/drive_${DRVNAME} ];then
DRV_CATEGORY="`probedisk /dev/${xDRVNAME} | cut -f 2 -d '|'`"
icon_mounted_func $DRVNAME $DRV_CATEGORY #see frontend_funcs
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