|
Hi, I suppose you all know of the utdomount script that Peter Downs wrote at 2005 to do the automount of USB flash, disks etc. I have worked a bit with it and here is a newer version which supports multiple USB devices and works fine both for adding and removing the device. Check it out for your self, I would appreciate any comments. |
#!/bin/bash # # /opt/SUNWut/lib/utdomount.sh # # Shell wrapper around /opt/SUNWut/lib/utdomount # Detect GNOME and put Icon on users desktop pointing to the USB mountpoint. # # Version: 0.1 -- Initial writing # Version: 0.2 -- Manages more USB devices and allows you to see their real names # # Change Log # # 2005/08/23, Peter Downs, <[EMAIL PROTECTED]> # 2008/01/11, Stratos Margaritis # # This script may be used under the terms of the GNU General # Public License v2 (http://www.gnu.org/licenses/gpl.html)
DEBUG=1
if [ "$DEBUG" == "1" ]; then
echo "### Environment ###" > /tmp/domount.log
set | sort >> /tmp/domount.log
echo "" >> /tmp/domount.log
echo "" >> /tmp/domount.log
echo "" >> /tmp/domount.log
echo "### Command Line ###" >> /tmp/domount.log
echo $* >> /tmp/domount.log
fi
cmdopt=$*
while [ $# -gt 0 ]; do
arg=$1
case $arg in
-b)
shift
dev=$1
;;
-i)
shift
id=$1
;;
-m)
shift
flg=0
action=mount
;;
-u)
shift
flg=1
# We get the args from the command line in order to find the
name of the usb device
argsv=$*
# We filter everything so that we can only keep the name of
the device
name=`echo $argsv | awk '{print $2}' | awk -F/ '{print $6}'`
if [ "$DEBUG" == "1" ]; then
echo argsv=$argsv >> /tmp/domount.log
echo args=$args >> /tmp/domount.log
fi
action=unmount
;;
*)
shift
;;
esac
done
if [ "$DEBUG" == "1" ]; then
echo "Processed command line arguments" >>/tmp/domount.log
echo dev=$dev >>/tmp/domount.log
echo id=$id >> /tmp/domount.log
echo action=$action >> /tmp/domount.log
fi
if [ "$id" != "" ]; then
uid=`getent passwd $id | cut -d: -f1`
fi
if [ "$DEBUG" == "1" ]; then
echo uid=$uid >> /tmp/domount.log
fi
if [ "$DEBUG" == "1" ]; then
echo "Passing control to utdomount.original" >>/tmp/domount.log
fi
/opt/SUNWut/lib/utdomount.original $cmdopt >> /tmp/domount.log
if [ "$DEBUG" == "1" ]; then
echo "Done with utdomount.original" >>/tmp/domount.log
fi
if [ "$flg" == "0" ]
then
# We sleep for 10 seconds since it will take about 7-9 secs before the
utdiskadm
# will be able to report the newly attached usb
sleep 10
bname=`basename $dev | sed -e 's/s2//'`
name=`/opt/SUNWut/bin/utdiskadm -l -a | grep $bname | awk '{print $3}'
| awk -F/ '{print $6}'`
fi
desc="$name"
icon=`eval echo ~$uid`/Desktop/usb-$name.desktop
echo name=$name >>/tmp/domount.log
echo icon=$icon >>/tmp/domount.log
case $action in
mount)
# Create icon
echo "Begin Create icon" >>/tmp/domount.log
#mpath=/tmp/SUNWut/mnt/$uid/$name
mpath=$name
cat > $icon <<EOM
[Desktop Entry]
Encoding=UTF-8
Name=$desc
Exec=nautilus $mpath
TryExec=nautilus
Icon=gnome-dev-removable
Terminal=false
Type=Application
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=nautilus
X-GNOME-Bugzilla-Component=general
EOM
chown $uid $icon
chmod 755 $icon
ln -s $mpath `eval echo ~$uid`/USB
;;
unmount)
rm $icon
rm `eval echo ~$uid`/USB
;;
esac
if [ "$DEBUG" == "1" ]; then
echo uid=$uid >> /tmp/domount.log
echo err=$err >> /tmp/domount.log
fi
exit $?
_______________________________________________ SunRay-Users mailing list [email protected] http://www.filibeto.org/mailman/listinfo/sunray-users
