usb unmount script for sun rays

as promised here comes part two of the usb scripts for sun ray ultrathin-clients. this is yet simpler but fancier than the mount script because it uses zenity to display the result of the unmounting operation.

CODE:
  1. #!/bin/bash
  2. ###################################################################################
  3. # Sun Ray USB UnMount Script - /opt/SUNWut/bin/utusbumount.sh                     #
  4. # Copyright 2007 Christian Stottmeister - http://www.stottmeister.com             #
  5. #                                                                                 #
  6. # This program is free software; you can redistribute it and/or modify            #
  7. # it under the terms of the GNU General Public License as published by            #
  8. # the Free Software Foundation; either version 2 of the License, or               #
  9. # (at your option) any later version.                                             #
  10. #                                                                                 #
  11. # This program is distributed in the hope that it will be useful,                 #
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of                  #
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   #
  14. # GNU General Public License for more details.                                    #
  15. #                                                                                 #
  16. # You should have received a copy of the GNU General Public License               #
  17. # along with this program; if not, write to the Free Software                     #
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA  #
  19. #                                                                                 #
  20. # See http://www.fsf.org/licensing/licenses/gpl.txs for the full license text.    #
  21. #                                                                                 #
  22. ###################################################################################
  23.  
  24. # RECOGNIZE CONNECTED USB DEVICES OF THE CURRENT USER
  25. usbdevices=`/opt/SUNWut/bin/utdiskadm -l`
  26.  
  27. # COUNT CONNECTED USB DEVICES OF THE CURRENT USER
  28. # count the lines of `utdiskadm -l` output
  29. usbdevicescount=`echo "$usbdevices" | wc -l`
  30. # substract 2 lines because they are only headings
  31. usbdevicescount=$(($usbdevicescount-2))
  32.  
  33. # RECOGNIZE DISK AND MOUNT PATH OF THE USB DEVICE
  34. usbdisk=`echo "$usbdevices" | grep "disk"`
  35. usbdisk=`echo "$usbdisk" | cut -f1 -s -d' '`
  36.  
  37. # LINK THE USB DEVICE AND OPEN FILE BROWSER
  38. # link to usb device will be placed into userdir, named usbdisk*
  39. linklocation=~/usb$usbdisk
  40. # try to eject the device
  41. /opt/SUNWut/bin/utdiskadm -r $usbdisk
  42. # check exit code of utdiskadm
  43. if [ "$?" -eq "0" ]; then
  44. # check if ~/usbdisk* exists
  45. if [ -e $linklocation ]; then
  46. # remove the link to /tmp/SUNWut/mnt/ *
  47. rm $linklocation
  48. fi
  49. if [ -e /usr/bin/zenity ]; then
  50. /usr/bin/zenity --info --title="USB UnMounting succeeded" --text="You can physically unmount the USB device now."
  51. fi
  52. exit 0
  53. else
  54. if [ -e /usr/bin/zenity ]; then
  55. /usr/bin/zenity --error --title="USB UnMounting failed" --text="Something went wrong while unmounting $usbdisk."
  56. else
  57. echo ERROR. USB UnMounting of $usbdisk failed!
  58. fi
  59. exit 1
  60. fi

so this is what you should get after executing the script:

Sun Ray USB Umount Dialog

of course there is an appropriate dialog if something fails.

by the way i have recognized that the scripts do work only if executed in a terminal. to make sure that it is run in a terminal use the checkbox in the starters' preferences dialog. to be true i don't know why this is necessary.

please let me know if you find some errors while using this script. i'ld love to know if it helps you in your sun ray environment. leaving a comment would be nice. thanks!

One Response to “usb unmount script for sun rays”

  1. stotti Says:

    the script described here has been topped by another solution. please refer to http://www.stottmeister.com/blog/2007/09/03/usb-drive-deamon-for-sun-ray-environments/ to read about the usb drive deamon. thanks!

Leave a Reply


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0 License.