#!/bin/sh # $Id: gmount,v 1.4 2009/03/20 07:57:54 friedman Exp $ set_defaults() { GMOUNT=${GMOUNT-gnome-mount} GMOUNT_UID=${GMOUNT_UID-${UID-`id -u`}} GMOUNT_GID=${GMOUNT_GID-${GID-`id -g`}} GMOUNT_USER=${GMOUNT_USER-${SUDO_USER-${LOGNAME-${USER-`whoami`}}}} } get_udi() { bdev=`readlink --canonicalize "$1"` hal-find-by-property --key block.device --string $bdev } get_udi_prop() { case $1 in /org/freedesktop/Hal/devices/* ) : ;; * ) set x `get_udi "$1"` "$2"; shift ;; esac hal-get-property --udi "$1" --key "$2" } get_fstype() { get_udi_prop "$1" volume.fstype } # TODO: validate mount options and filter those not allowed by the hal. get_allowed_mountopts() { get_udi_prop "$1" volume.mount.valid_options } set_fsopts() { _fsopts() { fsopts=$1 shift for o in "$@"; do fsopts=$fsopts,$o done } case $fstype:$fsopts in vfat: | fat: | msdos: ) _fsopts uid=$GMOUNT_UID \ gid=$GMOUNT_GID \ umask=000 \ iocharset=iso8859-1 \ shortname=mixed \ uni_xlate ;; hfs: | hfsplus: ) _fsopts uid=$GMOUNT_UID \ gid=$GMOUNT_GID \ umask=000 \ exec ;; xfs: | ext[234]: ) _fsopts noatime ;; cifs: ) _fsopts user=${GMOUNT_USER} \ uid=$GMOUNT_UID \ gid=$GMOUNT_GID \ file_mode=0777 \ dir_mode=02777 \ iocharset=iso8859-1 \ noperm \ nocase \ serverino \ user_xattr ;; esac } main() { set_defaults fstype= fsopts= xfsopts= unmount= while :; do case $1 in -t ) fstype=$2 ; shift 2 ;; -o ) fsopts=$2 ; shift 2 ;; -x ) xfsopts=$2 ; shift 2 ;; -u ) unmount=$1 ; shift ;; * ) break ;; esac done case $# in 1 ) device=$1 mountpoint= ; shift ;; 2 ) device=$1 mountpoint=$2 ; shift 2 ;; esac case $device in /* ) ;; * ) device=`find /dev/disk -path "*/$device" -print` ;; esac udi=`get_udi "$device"` case $fstype in '' ) fstype=`get_fstype "$udi"` ;; esac set_fsopts case ${fstype:+set} in set ) set x "$@" --fstype "$fstype" ; shift ;; esac case ${fsopts:+set} in set ) set x "$@" --mount-options "$fsopts" ; shift ;; esac case ${xfsopts:+set} in set ) set x "$@" --extra-mount-options "$xfsopts" ; shift ;; esac devalias=${device##*/} case $mountpoint in '' ) mountpoint=$devalias ;; esac set fnord \ $GMOUNT $unmount \ --block \ --text \ --device $device \ --mount-point $mountpoint \ "$@" shift echo + "$@" exec "$@" } main "$@" # eof