#!/bin/bash
# Created by: draggy
# Version: 1.1
# Date: 04/12/2011
#user that xboxdrv will run under
USER="root"
# screen name
WIRELESSDRV=wirelessdrv
WIREDDRV=wireddrv
# driver binary
DRV=xboxdrv
# specify how many controllers you will connect in the following 2 variables using 0-3 seperated by a space
# wireless controllers
WIRELESS=(0 1)
# wired controllers
WIRED=()
# arguements
ARGS="-c /usr/share/doc/xboxdrv/examples/xbmc.xboxdrv"
# start
start() {
if [ -z "$(lsmod | grep uinputl)" ]; then
echo "Loading uinput module"
modprobe uinput
fi
if [ -z "$(lsmod | grep joydev)" ]; then
echo "Loading joydev module"
modprobe joydev
fi
if [ -n "$(lsmod | grep xpad)" ]; then
echo "Unloading xpad module"
rmmod xpad
fi
for i in ${WIRELESS[@]}
do
if [ -n "$(su $USER -c "screen -ls |grep $WIRELESSDRV$i")" ];then
echo "Wireless Controller #$i is already running"
else
echo "Starting Wireless Controller #$i"
su $USER -c "screen -dmS $WIRELESSDRV$i $DRV --wid $i $ARGS"
fi
done
for i in ${WIRED[@]}
do
if [ -n "$(su $USER -c "screen -ls |grep $WIREDDRV$i")" ];then
echo "Wired Controller #$i is already running"
else
echo "Starting Wired Controller #$i"
su $USER -c "screen -dmS $WIREDDRV$i $DRV --id $i $ARGS"
fi
done
}
# stop
stop() {
for i in ${WIRELESS[@]}
do
if [ -n "$(su $USER -c "screen -ls |grep $WIRELESSDRV$i")" ];then
echo "Stopping Wireless Controller #$i"
su $USER -c "screen -S $WIRELESSDRV$i -X quit"
else
echo "Wireless Controller #$i is not running"
fi
done
for i in ${WIRED[@]}
do
if [ -n "$(su $USER -c "screen -ls |grep $WIREDDRV$i")" ];then
echo "Stopping Wired Controller #$i"
su $USER -c "screen -S $WIREDDRV$i -X quit"
else
echo "Wired Controller #$i is not running"
fi
done
}
# status
status() {
for i in ${WIRELESS[@]}
do
if [ -n "$(su $USER -c "screen -ls |grep $WIRELESSDRV$i")" ];then
echo "Wireless Controller #$i is running"
else
echo "Wireless Controller #$i is not running"
fi
done
for i in ${WIRED[@]}
do
if [ -n "$(su $USER -c "screen -ls |grep $WIREDDRV$i")" ];then
echo "Wired Controller #$i is running"
else
echo "Wired Controller #$i is not running"
fi
done
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
;;
esac
exit 0