Re: Nieuwe harde schijf
Posted: Wed Jul 15, 2009 1:32 pm
Hmm, try it without being root.
Code: Select all
#!/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@tiscali.it> for use in LiveXBMCV2
# 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
if [ ! -d /media/$drive ] ; then
mkdir /media/$drive
fi
mount -t ntfs -o rw,$OPTIONS /dev/$drive /media/$drive
donesomething='y'
if [[ $VERBOSE == 'y' ]]; then
echo "Mounted /dev/$drive as '/media/$drive' (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
if [ -e /sys/block/${drive%?}/removable ]; then
if [ "$(cat /sys/block/${drive%?}/removable)" = "0" ]; then
if [ ! -d /media/$drive ]; then
mkdir /media/$drive
fi
mount -t vfat -o rw,$OPTIONS /dev/$drive /media/$drive
donesomething='y'
if [[ $VERBOSE == 'y' ]]; then
echo "Mounted /dev/$drive as '/media/$drive' (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
if [ ! -d /media/$drive ]; then
mkdir /media/$drive
fi
mount -t hfsplus -o rw,$MACOPTIONS /dev/$drive /media/$drive
donesomething='y'
if [[ $VERBOSE == 'y' ]]; then
echo "Mounted /dev/$drive as '/media/$drive' (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
if [ ! -d /media/$drive ]; then
mkdir /media/$drive
fi
mount -o rw,$EXTOPTIONS /dev/$drive /media/$drive
donesomething='y'
if [[ $VERBOSE == 'y' ]]; then
echo "Mounted /dev/$drive as '/media/$drive' (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