Skip to content
Newer
Older
100755 165 lines (147 sloc) 5.76 KB
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
1 #!/bin/bash
2 ####################
3 # This utility searches for available HFS+, NTFS and FAT32 partitions, creates
4 # mount points for them and mounts the partitions
5 #
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
6 # (c)2008 Luigi Capriotti <l.capriotti@xbmc.org> for use in XBMCLive
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
7 # Base on "diskmount" by Dennis Kaarsemaker <dennis@ubuntu-nl.org>
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
13
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 ###################
23
24 VERBOSE='n'
25
26 # Root check
27 if [[ $UID != 0 ]]; then
28 echo 'You should run this program as root or using sudo'
29 exit 1
30 fi
31
32 OPTIONS='user,fmask=0133,dmask=0022,uid=1000,gid=1000'
33 MACOPTIONS='user,file_umask=0133,dir_umask=0022,uid=1000,gid=1000'
34 EXTOPTIONS=''
35
36 # Now for the real work
37 drivesntfs=`fdisk -l | grep -i 'ntfs' | awk -F '/| ' '{print $3}'`
38 drivesfat=`fdisk -l | grep -i 'fat32' | awk -F '/| ' '{print $3}'`
39 driveshfs=`fdisk -l | grep -i 'Apple_HFS' | awk -F '/| ' '{print $3}'`
40 drivesext=`fdisk -l | grep -i 'Linux' | grep -v 'swap' | awk -F '/| ' '{print $3}'`
41
42 if [ ! -d /media ]; then
43 mkdir /media
44 fi
45
46 donesomething='n'
47 for drive in $drivesntfs; do
48 if [[ ! `grep $drive /etc/fstab` && ! `pmount | grep $drive` && ! `mount | grep $drive` ]]; then
49 if [ -e /sys/block/${drive%?}/removable ]; then
50 if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
75ed068 fix for invalid UUID parsing
lcapriotti authored
51 uuid=`blkid -o udev /dev/$drive | grep UUID= | cut -d"=" -f2`
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
52 if [ ! -d /media/$uuid ] ; then
53 mkdir /media/$uuid
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
54 fi
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
55 mount -t ntfs -o rw,$OPTIONS /dev/$drive /media/$uuid
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
56
57 donesomething='y'
58 if [[ $VERBOSE == 'y' ]]; then
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
59 echo "Mounted /dev/$drive as '/media/$uuid' (read-only)"
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
60 fi
61 else
62 if [[ $VERBOSE == 'y' ]]; then
63 echo "Ignoring /dev/$drive - removable drive"
64 fi
65 fi
66 fi
67 else
68 if [[ $VERBOSE == 'y' ]]; then
69 echo "Ignoring /dev/$drive - already in /etc/fstab or mounted"
70 fi
71 fi
72 done
73
74 for drive in $drivesfat; do
75 if [[ ! `grep $drive /etc/fstab` && ! `pmount | grep $drive` && ! `mount | grep $drive` ]]; then
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
76 uuid=`blkid /dev/$drive | awk 'BEGIN{RS="UUID="}/-/{gsub(/ .*/,"");print}' | sed s/'"'/''/g`
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
77 if [ -e /sys/block/${drive%?}/removable ]; then
78 if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
75ed068 fix for invalid UUID parsing
lcapriotti authored
79 uuid=`blkid -o udev /dev/$drive | grep UUID= | cut -d"=" -f2`
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
80 if [ ! -d /media/$uuid ] ; then
81 mkdir /media/$uuid
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
82 fi
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
83 mount -t vfat -o rw,$OPTIONS /dev/$drive /media/$uuid
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
84
85 donesomething='y'
86 if [[ $VERBOSE == 'y' ]]; then
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
87 echo "Mounted /dev/$drive as '/media/$uuid' (read-only)"
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
88 fi
89 else
90 if [[ $VERBOSE == 'y' ]]; then
91 echo "Ignoring /dev/$drive - removable drive"
92 fi
93 fi
94 fi
95 else
96 if [[ $VERBOSE == 'y' ]]; then
97 echo "Ignoring /dev/$drive - already in /etc/fstab or mounted"
98 fi
99 fi
100 done
101
102
103 for drive in $driveshfs; do
104 if [[ ! `grep $drive /etc/fstab` && ! `pmount | grep $drive` && ! `mount | grep $drive` ]]; then
105 if [ -e /sys/block/${drive%?}/removable ]; then
106 if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
75ed068 fix for invalid UUID parsing
lcapriotti authored
107 uuid=`blkid -o udev /dev/$drive | grep UUID= | cut -d"=" -f2`
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
108 if [ ! -d /media/$uuid ] ; then
109 mkdir /media/$uuid
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
110 fi
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
111 mount -t hfsplus -o rw,$MACOPTIONS /dev/$drive /media/$uuid
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
112
113 donesomething='y'
114 if [[ $VERBOSE == 'y' ]]; then
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
115 echo "Mounted /dev/$drive as '/media/$uuid' (read-only)"
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
116 fi
117 else
118 if [[ $VERBOSE == 'y' ]]; then
119 echo "Ignoring /dev/$drive - removable drive"
120 fi
121 fi
122 fi
123 else
124 if [[ $VERBOSE == 'y' ]]; then
125 echo "Ignoring /dev/$drive - already in /etc/fstab or mounted"
126 fi
127 fi
128 done
129
130 for drive in $drivesext; do
131 if [[ ! `grep $drive /etc/fstab` && ! `pmount | grep $drive` && ! `mount | grep $drive` ]]; then
132 if [ -e /sys/block/${drive%?}/removable ]; then
133 if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
75ed068 fix for invalid UUID parsing
lcapriotti authored
134 uuid=`blkid -o udev /dev/$drive | grep UUID= | cut -d"=" -f2`
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
135 if [ ! -d /media/$uuid ] ; then
136 mkdir /media/$uuid
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
137 fi
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
138 mount -o rw,$EXTOPTIONS /dev/$drive /media/$uuid
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
139
140 donesomething='y'
141 if [[ $VERBOSE == 'y' ]]; then
0adf254 use uuid to get consistent mountpoints - tks bdkoepke (Ticket #9260)
lcapriotti authored
142 echo "Mounted /dev/$drive as '/media/$uuid' (read-only)"
24f6c45 step 3/4: Move linuxport to trunk. How'd I get roped into this?
AlTheKiller authored
143 fi
144 else
145 if [[ $VERBOSE == 'y' ]]; then
146 echo "Ignoring /dev/$drive - removable drive"
147 fi
148 fi
149 fi
150 else
151 if [[ $VERBOSE == 'y' ]]; then
152 echo "Ignoring /dev/$drive - already in /etc/fstab or mounted"
153 fi
154 fi
155 done
156
157 if [[ $VERBOSE == 'y' ]]; then
158 if [[ $donesomething == 'y' ]]; then
159 echo "All Linux, Windows and Mac partitions on non-removable disks have been mounted"
160 else
161 echo "No usable Linux, Windows or Mac partitions found on non-removable disks"
162 fi
163 fi
164
Something went wrong with that request. Please try again.