-
Notifications
You must be signed in to change notification settings - Fork 10
/
hda-diskmount
executable file
·274 lines (255 loc) · 13.2 KB
/
hda-diskmount
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
####################
# This utility searches for available HFS+, NTFS and FAT32 partitions, creates
# mount points for them and mounts the partitions
#
# Modified for Amahi by Carlos Puchol (cpg at amahi)
# Amahi cannot assume liability for any issues arising from using
# this script! You decline any warranty by using this script!
#
# (c)2008 Luigi Capriotti <[email protected]> for use in LiveXBMCV2
# Base on "diskmount" by Dennis Kaarsemaker <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###################
VERBOSE='y'
BASEDIR='/var/hda/files/drives'
SELECTED_DRIVE=''
if [ $# -gt 0 ]; then
if [[ $1 == "--silent" ]]; then
VERBOSE='n'
if [ $# -gt 1 ]; then
SELECTED_DRIVE=$2
fi
else
SELECTED_DRIVE=$1
fi
fi
# Root check
if [ $UID != 0 ]; then
echo 'You should run this program as root or using sudo'
exit 1
fi
NTFSOPTIONS='user,fmask=0113,dmask=0002,uid=500,gid=100,noatime'
FATOPTIONS='user,fmask=0113,dmask=0002,uid=500,gid=100,noatime'
HFSOPTIONS='user,uid=500,gid=100'
EXTOPTIONS=''
# Now for the real work
drivesntfs=`fdisk -l 2> /dev/null | grep -i 'ntfs' | awk -F '/| ' '{print $3}'`
drivesfat=`fdisk -l 2> /dev/null | grep -i 'fat32' | awk -F '/| ' '{print $3}'`
driveshfs=`fdisk -l 2> /dev/null | grep -i 'HFS' | awk -F '/| ' '{print $3}'`
drivesext=`fdisk -l 2> /dev/null | egrep -i 'Linux|GPT' | egrep -v 'swap|LVM' | awk -F '/| ' '{print $3}'`
if [ -f $BASEDIR ]; then
echo "Error: $BASEDIR is a file; needs to be a directory, or change the BASEDIR variable in `which hda-diskmount`"
exit 1
fi
if [ ! -d $BASEDIR ]; then
mkdir -p $BASEDIR
fi
NEXT_DRIVE='1'
DRIVE_MOUNTED='n'
for drive in $drivesntfs; do
if [[ $SELECTED_DRIVE != "" && $SELECTED_DRIVE != "/dev/$drive" ]]; then
continue
fi
[ $VERBOSE == 'y' ] && echo "****************************************************************"
uuid=`ls -l /dev/disk/by-uuid/ | grep "\.\./\.\./$drive" | awk '{print $(NF-2)}'`
if [[ `grep "/dev/$drive" /etc/fstab` || `grep "UUID=$uuid" /etc/fstab` || `pmount | grep $drive` || `mount | grep $drive` ]]; then
if [ $VERBOSE == 'y' ]; then
[[ `pmount | grep $drive` ]] && echo "Ignoring /dev/$drive - already mounted"
[[ `mount | grep $drive` ]] && echo "Ignoring /dev/$drive - already mounted"
[[ `grep "/dev/$drive" /etc/fstab` ]] && echo "Ignoring /dev/$drive - already in /etc/fstab as /dev/$drive"
[[ `grep "UUID=$uuid" /etc/fstab` ]] && echo "Ignoring /dev/$drive - already in /etc/fstab as UUID=$uuid"
if [[ `grep "/dev/$drive" /etc/fstab` || `grep "UUID=$uuid" /etc/fstab` ]]; then
if [[ `grep ".*#.*/dev/$drive" /etc/fstab` || `grep ".*#.*UUID=$uuid" /etc/fstab` ]]; then
echo "This device appears to be commented out of your /etc/fstab. You will need to remove it from there for hda-diskmount to be able to mount it."
fi
fi
fi
else
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" == "1" ]; then
[ $VERBOSE == 'y' ] && echo "Ignoring /dev/$drive - removable drive"
else
while [ -e $BASEDIR/drive$NEXT_DRIVE ]; do
NEXT_DRIVE=`echo $NEXT_DRIVE + 1 | bc`
done
mkdir $BASEDIR/drive$NEXT_DRIVE
mount -t ntfs-3g -o rw,$NTFSOPTIONS /dev/$drive $BASEDIR/drive$NEXT_DRIVE
DRIVE_MOUNTED='y'
if [ $VERBOSE == 'n' ]; then
echo "$BASEDIR/drive$NEXT_DRIVE"
else
echo "Mounted /dev/$drive as '$BASEDIR/drive$NEXT_DRIVE'"
echo -e "\tYou may want your system to mount it every time you boot."
echo -e "\tTo do so, add this line VERY CAREFULLY to /etc/fstab and reboot:"
if [ "$uuid" == "" ]; then
echo -e "\t/dev/$drive $BASEDIR/drive$NEXT_DRIVE ntfs-3g rw,$NTFSOPTIONS 1 2"
else
echo -e "\tUUID=$uuid $BASEDIR/drive$NEXT_DRIVE ntfs-3g rw,$NTFSOPTIONS 1 2"
fi
fi
fi
fi
fi
done
for drive in $drivesfat; do
if [[ $SELECTED_DRIVE != "" && $SELECTED_DRIVE != "/dev/$drive" ]]; then
continue
fi
[ $VERBOSE == 'y' ] && echo "****************************************************************"
uuid=`ls -l /dev/disk/by-uuid/ | grep "\.\./\.\./$drive" | awk '{print $(NF-2)}'`
if [[ `grep "/dev/$drive" /etc/fstab` || `grep "UUID=$uuid" /etc/fstab` || `pmount | grep $drive` || `mount | grep $drive` ]]; then
if [ $VERBOSE == 'y' ]; then
[[ `pmount | grep $drive` ]] && echo "Ignoring /dev/$drive - already mounted"
[[ `mount | grep $drive` ]] && echo "Ignoring /dev/$drive - already mounted"
[[ `grep "/dev/$drive" /etc/fstab` ]] && echo "Ignoring /dev/$drive - already in /etc/fstab as /dev/$drive"
[[ `grep "UUID=$uuid" /etc/fstab` ]] && echo "Ignoring /dev/$drive - already in /etc/fstab as UUID=$uuid"
if [[ `grep "/dev/$drive" /etc/fstab` || `grep "UUID=$uuid" /etc/fstab` ]]; then
if [[ `grep ".*#.*/dev/$drive" /etc/fstab` || `grep ".*#.*UUID=$uuid" /etc/fstab` ]]; then
echo "This device appears to be commented out of your /etc/fstab. You will need to remove it from there for hda-diskmount to be able to mount it."
fi
fi
fi
else
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" == "1" ]; then
[ $VERBOSE == 'y' ] && echo "Ignoring /dev/$drive - removable drive"
else
while [ -e $BASEDIR/drive$NEXT_DRIVE ]; do
NEXT_DRIVE=`echo $NEXT_DRIVE + 1 | bc`
done
mkdir $BASEDIR/drive$NEXT_DRIVE
mount -t vfat -o rw,$FATOPTIONS /dev/$drive $BASEDIR/drive$NEXT_DRIVE
DRIVE_MOUNTED='y'
if [ $VERBOSE == 'n' ]; then
echo "$BASEDIR/drive$NEXT_DRIVE"
else
echo "Mounted /dev/$drive as '$BASEDIR/drive$NEXT_DRIVE' (read-write)"
echo -e "\tYou may want your system to mount it every time you boot."
echo -e "\tTo do so, add this line VERY CAREFULLY to /etc/fstab and reboot:"
if [ "$uuid" == "" ]; then
echo -e "\t/dev/$drive $BASEDIR/drive$NEXT_DRIVE vfat rw,$FATOPTIONS 1 2"
else
echo -e "\tUUID=$uuid $BASEDIR/drive$NEXT_DRIVE vfat rw,$FATOPTIONS 1 2"
fi
fi
fi
fi
fi
done
for drive in $driveshfs; do
if [[ $SELECTED_DRIVE != "" && $SELECTED_DRIVE != "/dev/$drive" ]]; then
continue
fi
[ $VERBOSE == 'y' ] && echo "****************************************************************"
uuid=`ls -l /dev/disk/by-uuid/ | grep "\.\./\.\./$drive" | awk '{print $(NF-2)}'`
if [[ `grep "/dev/$drive" /etc/fstab` || `grep "UUID=$uuid" /etc/fstab` || `pmount | grep $drive` || `mount | grep $drive` ]]; then
if [ $VERBOSE == 'y' ]; then
[[ `pmount | grep $drive` ]] && echo "Ignoring /dev/$drive - already mounted"
[[ `mount | grep $drive` ]] && echo "Ignoring /dev/$drive - already mounted"
[[ `grep "/dev/$drive" /etc/fstab` ]] && echo "Ignoring /dev/$drive - already in /etc/fstab as /dev/$drive"
[[ `grep "UUID=$uuid" /etc/fstab` ]] && echo "Ignoring /dev/$drive - already in /etc/fstab as UUID=$uuid"
if [[ `grep "/dev/$drive" /etc/fstab` || `grep "UUID=$uuid" /etc/fstab` ]]; then
if [[ `grep ".*#.*/dev/$drive" /etc/fstab` || `grep ".*#.*UUID=$uuid" /etc/fstab` ]]; then
echo "This device appears to be commented out of your /etc/fstab. You will need to remove it from there for hda-diskmount to be able to mount it."
fi
fi
fi
else
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" == "1" ]; then
[ $VERBOSE == 'y' ] && echo "Ignoring /dev/$drive - removable drive"
else
while [ -e $BASEDIR/drive$NEXT_DRIVE ]; do
NEXT_DRIVE=`echo $NEXT_DRIVE + 1 | bc`
done
mkdir $BASEDIR/drive$NEXT_DRIVE
mount -t hfsplus -o rw,$HFSOPTIONS /dev/$drive $BASEDIR/drive$NEXT_DRIVE
DRIVE_MOUNTED='y'
if [ $VERBOSE == 'n' ]; then
echo "$BASEDIR/drive$NEXT_DRIVE"
else
echo "Mounted /dev/$drive as '$BASEDIR/drive$NEXT_DRIVE' (read-write)"
echo -e "\tYou may want your system to mount it every time you boot."
echo -e "\tTo do so, add this line VERY CAREFULLY to /etc/fstab and reboot:"
if [ "$uuid" == "" ]; then
echo -e "\t/dev/$drive $BASEDIR/drive$NEXT_DRIVE hfsplus $HFSOPTIONS 1 2"
else
echo -e "\tUUID=$uuid $BASEDIR/drive$NEXT_DRIVE hfsplus $HFSOPTIONS 1 2"
fi
fi
fi
fi
fi
done
for drive in $drivesext; do
if [[ $SELECTED_DRIVE != "" && $SELECTED_DRIVE != "/dev/$drive" ]]; then
continue
fi
[ $VERBOSE == 'y' ] && echo "****************************************************************"
uuid=`ls -l /dev/disk/by-uuid/ | grep "\.\./\.\./$drive" | awk '{print $(NF-2)}'`
if [[ `grep "/dev/$drive" /etc/fstab` || `grep "UUID=$uuid" /etc/fstab` || `pmount | grep $drive` || `mount | grep $drive` ]]; then
if [ $VERBOSE == 'y' ]; then
[[ `pmount | grep $drive` ]] && echo "Ignoring /dev/$drive - already mounted"
[[ `mount | grep $drive` ]] && echo "Ignoring /dev/$drive - already mounted"
[[ `grep "/dev/$drive" /etc/fstab` ]] && echo "Ignoring /dev/$drive - already in /etc/fstab as /dev/$drive"
[[ `grep "UUID=$uuid" /etc/fstab` ]] && echo "Ignoring /dev/$drive - already in /etc/fstab as UUID=$uuid"
if [[ `grep "/dev/$drive" /etc/fstab` || `grep "UUID=$uuid" /etc/fstab` ]]; then
if [[ `grep ".*#.*/dev/$drive" /etc/fstab` || `grep ".*#.*UUID=$uuid" /etc/fstab` ]]; then
echo "This device appears to be commented out of your /etc/fstab. You will need to remove it from there for hda-diskmount to be able to mount it."
fi
fi
fi
else
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" == "1" ]; then
[ $VERBOSE == 'y' ] && echo "Ignoring /dev/$drive - removable drive"
else
while [ -e $BASEDIR/drive$NEXT_DRIVE ]; do
NEXT_DRIVE=`echo $NEXT_DRIVE + 1 | bc`
done
mkdir $BASEDIR/drive$NEXT_DRIVE
mount -o rw,$EXTOPTIONS /dev/$drive $BASEDIR/drive$NEXT_DRIVE
DRIVE_MOUNTED='y'
if [ $VERBOSE == 'n' ]; then
echo "$BASEDIR/drive$NEXT_DRIVE"
else
echo "Mounted /dev/$drive as '$BASEDIR/drive$NEXT_DRIVE' (read-write)"
echo -e "\tYou may want your system to mount it every time you boot."
echo -e "\tTo do so, add this line VERY CAREFULLY to /etc/fstab and reboot:"
if [ "$uuid" == "" ]; then
echo -e "\t/dev/$drive $BASEDIR/drive$NEXT_DRIVE ext4 ${EXTOPTIONS:-defaults} 1 2"
else
echo -e "\tUUID=$uuid $BASEDIR/drive$NEXT_DRIVE ext4 ${EXTOPTIONS:-defaults} 1 2"
fi
fi
fi
fi
fi
done
if [ $VERBOSE == 'y' ]; then
echo "****************************************************************"
if [ $DRIVE_MOUNTED == 'y' ]; then
echo "All Linux, Windows and Mac partitions on your disks have been mounted."
else
echo "No usable Linux, Windows or Mac partitions found on your disks."
result=`mount | awk -F' type ' '{print $1}' | awk -F' on ' '{print $2}' | grep /media`
if [ "$result" != "" ]; then
echo "If the drive you want to mount is already mounted as "
for d in $result; do echo $d; done
echo "You'll need to unmount it from there first (right-click > Eject, from the Fedora desktop), then re-run this script."
fi
fi
fi