usb mount script for sun rays

as you all know the sun ray ultrathin-clients support several types of devices connected to them, including serial and parallel devices, usb mass storage, pdas and so on. for a full list see the sun ray admin guide, chapter four. now when a usb mass storage device gets plugged in, the sun ray services mount it to /tmp/SUNWut/mnt/[username]/disk[integer]/. the user then needs to traverse the file system to get into the named directory which is applicable but quite a strange behavior for people who got used to windows (plug in usb-stick and it gets mounted as a lokal partition, then the user gets notified of it). because of this i have thought of a possibility to decrease user concerns and increase their positive experiences. yesterday i did a quick hack to check for mounted usb devices, link them to the users home directory and open a file browser to display the linked directory.

CODE:
  1. #!/bin/bash
  2. ###################################################################################
  3. # Sun Ray USB Mount Script - /opt/SUNWut/bin/utusbmount.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. usbmountpath=/tmp/SUNWut/mnt/`/usr/xpg4/bin/id -u -n`/
  37.  
  38. # LINK THE USB DEVICE AND OPEN FILE BROWSER
  39. # check if $usbmountpath exists and is a directory
  40. if [ -e $usbmountpath -a -d $usbmountpath ]; then
  41. # $usbmountpath is a directory and therefore exists
  42. # link to usb device will be placed into userdir, named usbdisk*
  43. linklocation=~/usb$usbdisk
  44. # check if ~/usbdisk* exists
  45. if [ ! -e $linklocation ]; then
  46. ln -s $usbmountpath $linklocation
  47. fi
  48. nautilus $linklocation
  49. fi

the script has a pitfall yet, because it supports only one usb device per user. so if the user connects two or more usb mass storage devices (should happen rarely) the scripts fails. i plan to code an option the select the desired device. perhaps some of my fellow readers want to supply this so i don't have to code it? :)

btw. using this script you have to unmount devices after usage of course. i will come up with the according script later.

3 Responses to “usb mount script for sun rays”

  1. stotti.blog() » Blog Archive » usb unmount script for sun rays Says:

    […] 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. PLAIN TEXT CODE: […]

  2. 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!

  3. stotti.blog() Says:

    usb drive deamon for sun ray environments…

    okay, time for more updates. as months went by, my usb mount/unmount script has been used by several sun ray admins, who have written me uplifting mails. thanks for your replies, dudes! but meanwhile daniel cifuentes came up with the “usb drive d…

Leave a Reply


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