Don't like ads? PRO users don't see any ads ;-)
Guest

draggy's xboxdrv startup script

By: a guest on Apr 13th, 2011  |  syntax: Bash  |  size: 2.60 KB  |  hits: 1,069  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. # Created by: draggy
  4. # Version: 1.1
  5. # Date: 04/12/2011
  6.  
  7. #user that xboxdrv will run under
  8. USER="root"
  9.  
  10. # screen name
  11. WIRELESSDRV=wirelessdrv
  12. WIREDDRV=wireddrv
  13.  
  14. # driver binary
  15. DRV=xboxdrv
  16.  
  17. # specify how many controllers you will connect in the following 2 variables using 0-3 seperated by a space
  18.  
  19. # wireless controllers
  20. WIRELESS=(0 1)
  21.  
  22. # wired controllers
  23. WIRED=()
  24.  
  25. # arguements
  26. ARGS="-c /usr/share/doc/xboxdrv/examples/xbmc.xboxdrv"
  27.  
  28. # start
  29. start() {
  30.         if [ -z "$(lsmod | grep uinputl)" ]; then
  31.                 echo "Loading uinput module"
  32.                 modprobe uinput
  33.         fi
  34.         if [ -z "$(lsmod | grep joydev)" ]; then
  35.                 echo "Loading joydev module"
  36.                 modprobe joydev
  37.         fi
  38.         if [ -n "$(lsmod | grep xpad)" ]; then
  39.                 echo "Unloading xpad module"
  40.                 rmmod xpad
  41.         fi
  42.  
  43.         for i in ${WIRELESS[@]}
  44.         do
  45.                 if [ -n "$(su $USER -c "screen -ls |grep $WIRELESSDRV$i")" ];then
  46.                         echo "Wireless Controller #$i is already running"
  47.                 else
  48.                         echo "Starting Wireless Controller #$i"
  49.                         su $USER -c "screen -dmS $WIRELESSDRV$i $DRV --wid $i $ARGS"
  50.                 fi
  51.         done
  52.  
  53.         for i in ${WIRED[@]}
  54.         do
  55.                 if [ -n "$(su $USER -c "screen -ls |grep $WIREDDRV$i")" ];then
  56.                         echo "Wired Controller #$i is already running"
  57.                 else
  58.                         echo "Starting Wired Controller #$i"
  59.                         su $USER -c "screen -dmS $WIREDDRV$i $DRV --id $i $ARGS"
  60.                 fi
  61.         done
  62. }
  63.  
  64. # stop
  65. stop() {
  66.         for i in ${WIRELESS[@]}
  67.         do
  68.                 if [ -n "$(su $USER -c "screen -ls |grep $WIRELESSDRV$i")" ];then
  69.                         echo "Stopping Wireless Controller #$i"
  70.                         su $USER -c "screen -S $WIRELESSDRV$i -X quit"
  71.                 else
  72.                         echo "Wireless Controller #$i is not running"
  73.                 fi
  74.         done
  75.  
  76.         for i in ${WIRED[@]}
  77.         do
  78.                 if [ -n "$(su $USER -c "screen -ls |grep $WIREDDRV$i")" ];then
  79.                         echo "Stopping Wired Controller #$i"
  80.                         su $USER -c "screen -S $WIREDDRV$i -X quit"
  81.                 else
  82.                         echo "Wired Controller #$i is not running"
  83.                 fi
  84.         done
  85. }
  86.  
  87. # status
  88. status() {
  89.         for i in ${WIRELESS[@]}
  90.         do
  91.                 if [ -n "$(su $USER -c "screen -ls |grep $WIRELESSDRV$i")" ];then
  92.                         echo "Wireless Controller #$i is running"
  93.                 else
  94.                         echo "Wireless Controller #$i is not running"
  95.                 fi
  96.         done
  97.  
  98.         for i in ${WIRED[@]}
  99.         do
  100.                 if [ -n "$(su $USER -c "screen -ls |grep $WIREDDRV$i")" ];then
  101.                         echo "Wired Controller #$i is running"
  102.                 else
  103.                         echo "Wired Controller #$i is not running"
  104.                 fi
  105.         done
  106. }
  107.  
  108. ### main logic ###
  109. case "$1" in
  110.   start)
  111.         start
  112.         ;;
  113.   stop)
  114.         stop
  115.         ;;
  116.   status)
  117.         status
  118.         ;;
  119.   restart|reload|condrestart)
  120.         stop
  121.         start
  122.         ;;
  123.   *)
  124.         echo $"Usage: $0 {start|stop|restart|reload|status}"
  125.         exit 1
  126.         ;;
  127. esac
  128.  
  129. exit 0