-
#!/bin/bash
-
###################################################################################
-
# Sun Ray USB UnMount Script - /opt/SUNWut/bin/utusbumount.sh #
-
# Copyright 2007 Christian Stottmeister - http://www.stottmeister.com #
-
# #
-
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #
-
# #
-
# See http://www.fsf.org/licensing/licenses/gpl.txs for the full license text. #
-
# #
-
###################################################################################
-
-
# RECOGNIZE CONNECTED USB DEVICES OF THE CURRENT USER
-
usbdevices=`/opt/SUNWut/bin/utdiskadm -l`
-
-
# COUNT CONNECTED USB DEVICES OF THE CURRENT USER
-
# count the lines of `utdiskadm -l` output
-
usbdevicescount=`echo "$usbdevices" | wc -l`
-
# substract 2 lines because they are only headings
-
usbdevicescount=$(($usbdevicescount-2))
-
-
# RECOGNIZE DISK AND MOUNT PATH OF THE USB DEVICE
-
usbdisk=`echo "$usbdevices" | grep "disk"`
-
usbdisk=`echo "$usbdisk" | cut -f1 -s -d' '`
-
-
# LINK THE USB DEVICE AND OPEN FILE BROWSER
-
# link to usb device will be placed into userdir, named usbdisk*
-
linklocation=~/usb$usbdisk
-
# try to eject the device
-
/opt/SUNWut/bin/utdiskadm -r $usbdisk
-
# check exit code of utdiskadm
-
if [ "$?" -eq "0" ]; then
-
# check if ~/usbdisk* exists
-
if [ -e $linklocation ]; then
-
# remove the link to /tmp/SUNWut/mnt/ *
-
rm $linklocation
-
fi
-
if [ -e /usr/bin/zenity ]; then
-
/usr/bin/zenity --info --title="USB UnMounting succeeded" --text="You can physically unmount the USB device now."
-
fi
-
exit 0
-
else
-
if [ -e /usr/bin/zenity ]; then
-
/usr/bin/zenity --error --title="USB UnMounting failed" --text="Something went wrong while unmounting $usbdisk."
-
else
-
echo ERROR. USB UnMounting of $usbdisk failed!
-
fi
-
exit 1
-
fi