Created
May 2, 2016 18:44
-
-
Save meska/381b63d0d9b25b12078b06d1fbab8929 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
### BEGIN INIT INFO | |
# Provides: xbox-controller | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start XBOX Controller Service | |
# Description: Start the xboxdrv daemon with several options | |
# support up to 4 Controllers | |
### END INIT INFO | |
# Author: MasteRehm | |
PATH=/sbin:/usr/sbin:/bin:/usr/bin | |
DESC="XBOX Controller Service" | |
NAME=xboxdrv | |
DAEMON=/usr/bin/$NAME | |
DAEMON_ARGS="-D -d --deadzone 4000 --dbus disabled --detach" | |
PIDFILE=/var/run/$NAME.pid | |
SCRIPTNAME=/etc/init.d/$NAME | |
# Exit if the package is not installed | |
[ -x "$DAEMON" ] || exit 0 | |
# Read configuration variable file if it is present | |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME | |
# Load the VERBOSE setting and other rcS variables | |
. /lib/init/vars.sh | |
# Define LSB log_* functions. | |
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present | |
# and status_of_proc is working. | |
. /lib/lsb/init-functions | |
do_start() | |
{ | |
if [ $CONTROLLER_NUM -gt 4 ] ; then | |
echo -e "\n$CONTROLLER"; exit 1; | |
fi | |
start-stop-daemon -S -q -x $DAEMON -- $DAEMON_ARGS $CONTROLLER | |
# -- This workaround only works with 4 controllers connected. It also is creating a name that | |
# does not match the minor device node. | |
# # Workaround: xboxdrv daemon creates /dev/input/js[4-7] device files, if /dev/input/js[0-3] created on startup. | |
# if [ -x /usr/bin/rename ]; then | |
# sleep 1 | |
# if [[ `ls /dev/input/js*` =~ /dev/input/js[4-7] ]]; then rename 's/js4/js0/;s/js5/js1/;s/js6/js2/;s/js7/js3/' /dev/input/js*; fi | |
# fi | |
# Rather than renaming files, it's better to clear the existing ones by stopping the driver | |
# and then when you start it again, everything will be correct. | |
sleep 3 | |
do_stop | |
sleep 3 | |
start-stop-daemon -S -q -x $DAEMON -- $DAEMON_ARGS $CONTROLLER | |
} | |
do_stop() | |
{ | |
start-stop-daemon -K -o -q -x $DAEMON | |
sleep 1 | |
} | |
case "$1" in | |
start) | |
log_daemon_msg "Starting $DESC" "$NAME" | |
do_start | |
status=$? | |
log_end_msg $status | |
;; | |
stop) | |
log_daemon_msg "Stopping $DESC" "$NAME" | |
do_stop | |
status=$? | |
log_end_msg $status | |
;; | |
status) | |
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? | |
;; | |
restart) | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) | |
do_start | |
case "$?" in | |
0) log_end_msg 0 ;; | |
1) log_end_msg 1 ;; # Old process is still running | |
*) log_end_msg 1 ;; # Failed to start | |
esac | |
;; | |
*) | |
# Failed to stop | |
log_end_msg 1 | |
;; | |
esac | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 | |
exit 3 | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment