Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: maverick
Fetching contributors…

Cannot retrieve contributors at this time

executable file 165 lines (147 sloc) 5.899 kb
#!/bin/bash
####################
# This utility searches for available HFS+, NTFS and FAT32 partitions, creates
# mount points for them and mounts the partitions
#
# (c)2008 Luigi Capriotti <l.capriotti@xbmc.org> for use in XBMCLive
# Base on "diskmount" by Dennis Kaarsemaker <dennis@ubuntu-nl.org>
#
# 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='n'
# Root check
if [[ $UID != 0 ]]; then
echo 'You should run this program as root or using sudo'
exit 1
fi
OPTIONS='user,fmask=0133,dmask=0022,uid=1000,gid=1000'
MACOPTIONS='user,file_umask=0133,dir_umask=0022,uid=1000,gid=1000'
EXTOPTIONS=''
# Now for the real work
drivesntfs=`fdisk -l | grep -i 'ntfs' | awk -F '/| ' '{print $3}'`
drivesfat=`fdisk -l | grep -i 'fat32' | awk -F '/| ' '{print $3}'`
driveshfs=`fdisk -l | grep -i 'Apple_HFS' | awk -F '/| ' '{print $3}'`
drivesext=`fdisk -l | grep -i 'Linux' | grep -v 'swap' | awk -F '/| ' '{print $3}'`
if [ ! -d /media ]; then
mkdir /media
fi
donesomething='n'
for drive in $drivesntfs; do
if [[ ! `grep $drive /etc/fstab` && ! `pmount | grep $drive` && ! `mount | grep $drive` ]]; then
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
uuid=`blkid -o udev /dev/$drive | grep UUID= | cut -d"=" -f2`
if [ ! -d /media/$uuid ] ; then
mkdir /media/$uuid
fi
mount -t ntfs -o rw,$OPTIONS /dev/$drive /media/$uuid
donesomething='y'
if [[ $VERBOSE == 'y' ]]; then
echo "Mounted /dev/$drive as '/media/$uuid' (read-only)"
fi
else
if [[ $VERBOSE == 'y' ]]; then
echo "Ignoring /dev/$drive - removable drive"
fi
fi
fi
else
if [[ $VERBOSE == 'y' ]]; then
echo "Ignoring /dev/$drive - already in /etc/fstab or mounted"
fi
fi
done
for drive in $drivesfat; do
if [[ ! `grep $drive /etc/fstab` && ! `pmount | grep $drive` && ! `mount | grep $drive` ]]; then
uuid=`blkid /dev/$drive | awk 'BEGIN{RS="UUID="}/-/{gsub(/ .*/,"");print}' | sed s/'"'/''/g`
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
uuid=`blkid -o udev /dev/$drive | grep UUID= | cut -d"=" -f2`
if [ ! -d /media/$uuid ] ; then
mkdir /media/$uuid
fi
mount -t vfat -o rw,$OPTIONS /dev/$drive /media/$uuid
donesomething='y'
if [[ $VERBOSE == 'y' ]]; then
echo "Mounted /dev/$drive as '/media/$uuid' (read-only)"
fi
else
if [[ $VERBOSE == 'y' ]]; then
echo "Ignoring /dev/$drive - removable drive"
fi
fi
fi
else
if [[ $VERBOSE == 'y' ]]; then
echo "Ignoring /dev/$drive - already in /etc/fstab or mounted"
fi
fi
done
for drive in $driveshfs; do
if [[ ! `grep $drive /etc/fstab` && ! `pmount | grep $drive` && ! `mount | grep $drive` ]]; then
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
uuid=`blkid -o udev /dev/$drive | grep UUID= | cut -d"=" -f2`
if [ ! -d /media/$uuid ] ; then
mkdir /media/$uuid
fi
mount -t hfsplus -o rw,$MACOPTIONS /dev/$drive /media/$uuid
donesomething='y'
if [[ $VERBOSE == 'y' ]]; then
echo "Mounted /dev/$drive as '/media/$uuid' (read-only)"
fi
else
if [[ $VERBOSE == 'y' ]]; then
echo "Ignoring /dev/$drive - removable drive"
fi
fi
fi
else
if [[ $VERBOSE == 'y' ]]; then
echo "Ignoring /dev/$drive - already in /etc/fstab or mounted"
fi
fi
done
for drive in $drivesext; do
if [[ ! `grep $drive /etc/fstab` && ! `pmount | grep $drive` && ! `mount | grep $drive` ]]; then
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
uuid=`blkid -o udev /dev/$drive | grep UUID= | cut -d"=" -f2`
if [ ! -d /media/$uuid ] ; then
mkdir /media/$uuid
fi
mount -o rw,$EXTOPTIONS /dev/$drive /media/$uuid
donesomething='y'
if [[ $VERBOSE == 'y' ]]; then
echo "Mounted /dev/$drive as '/media/$uuid' (read-only)"
fi
else
if [[ $VERBOSE == 'y' ]]; then
echo "Ignoring /dev/$drive - removable drive"
fi
fi
fi
else
if [[ $VERBOSE == 'y' ]]; then
echo "Ignoring /dev/$drive - already in /etc/fstab or mounted"
fi
fi
done
if [[ $VERBOSE == 'y' ]]; then
if [[ $donesomething == 'y' ]]; then
echo "All Linux, Windows and Mac partitions on non-removable disks have been mounted"
else
echo "No usable Linux, Windows or Mac partitions found on non-removable disks"
fi
fi
Jump to Line
Something went wrong with that request. Please try again.