Guest User

promethean.sh

a guest
Nov 4th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # some distributions mount the root as read only until fsck has run,
  4. # so we cannot edit xorg and create .activdevices.
  5. # we need to wait until the root is writable, which happens
  6. # later.
  7. # however, udev is synchronous, so we must relaunch ourselves async and exit.
  8. DAEMON_FILE=/tmp/activboard/.activdevices
  9. if [ "$1" == "wait" ]; then
  10.     while [ ! -w /tmp ]; do
  11.         sleep 1
  12.     done
  13.     shift
  14. else
  15.     if [ ! -w /tmp ]; then
  16.         $0 wait $@ &
  17.         exit 0
  18.     fi
  19. fi
  20.  
  21. if [ "$1" == "add" ]; then
  22.  
  23. if [ "`id -u`" == "0" ]; then
  24.     #make sure evdev is loaded first
  25.     (/sbin/lsmod|grep -iq evdev) || modprobe evdev
  26.  
  27.     #add the promethean drivers if not there
  28.     (/sbin/lsmod|grep -iq promethean) || modprobe promethean
  29. fi
  30.  
  31. #reset the access rights for /dev/ACTIVBoard* (now done in udev)
  32. # chmod 644 /dev/ACTIVBoard*
  33.  
  34. if [ ! -e "/etc/promethean/calibration" ]; then
  35.     #create calibration directory with proper rights (user can write to it)
  36.     mkdir -p /etc/promethean/calibration
  37.     chmod -R 777 /etc/promethean/calibration
  38. fi
  39.  
  40. # since HAL, udev seems to be called before ACTIVBoard<n> is available (sometimes)
  41. [ "`ls /dev/ACTIVBoard* -1|wc -l`" == "0" ] && logger Promethean: No devices ready yet so sleep && sleep 3
  42.  
  43. logger ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Beeping boards $$ $2
  44.     if [ -e "/dev/$2" ]; then
  45.         # beep the board
  46.         logger Beeping Board /dev/$2
  47.         echo -e ":BP\r" > /dev/$2
  48.         #send the calibration to the device if activmgr is not running.
  49.         # if it is running, it will run activlc from activmgr
  50.         ps ax|grep activmgr|grep -vq grep || (activlc --load /dev/$2 | logger)
  51.     fi
  52.  
  53. logger ++++++++++++++++++++++++++++++ Done beeping boards $$ $2
  54.  
  55. if [ -f "$DAEMON_FILE" ]; then
  56.     rm "$DAEMON_FILE"
  57. fi
  58. echo add > "$DAEMON_FILE"
  59. chmod 666 "$DAEMON_FILE"
  60. logger "Promethean: device added"
  61. elif [ "$1" == "remove" ]; then
  62.    
  63.     # remove but file not present, this can happen at startup if tmp was erased.
  64.     # we need to create it first then delete so that gamin / fam picks it up.
  65.     if [ ! -f "$DAEMON_FILE" ]; then
  66.         echo add > "$DAEMON_FILE"
  67.         chmod 666 "$DAEMON_FILE"
  68.     fi
  69.     rm "$DAEMON_FILE"
  70.     rm /tmp/activboard*
  71.    
  72.     # if more devices, create the file again.
  73.     # libactivboardex uses 1 of 3 mechanisms to detect changes:
  74.     # FAM, Gamin and file polling.
  75.     # FAM usually fails, something to do with the library.
  76.     # Gamin checks for "$DAEMON_FILE" and is accurate
  77.     # file polling checks for any file called /tmp/.activboard*
  78.     for f in /dev/ACTIVBoard*
  79.     do
  80.         if [ -e $f ]; then
  81.             echo add > "$DAEMON_FILE"      
  82.             chmod 666 "$DAEMON_FILE"   
  83.             break
  84.         fi
  85.     done   
  86.  
  87.     logger "Promethean: device removed"
  88. else
  89.     logger "Promethean: invalid argument in promethean.sh "$1
  90. fi
  91.  
  92. # create the activboard[n] for file polling method
  93. for f in /dev/ACTIVBoard*
  94. do
  95.     if [ -e $f ]; then
  96.         BFILE="/tmp/`basename $f|tr [:upper:] [:lower:]`"
  97.         echo add > $BFILE
  98.         chmod 666 $BFILE
  99.     fi
  100. done
Advertisement
Add Comment
Please, Sign In to add comment