#!/bin/sh
#
### BEGIN INIT INFO
# Provides: xboxdrv
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Short-Description: Xbox Driver.
# Description: xboxdrv is nothing. 
#              Really, nothing.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

DAEMON_NAME=xboxdrv
DAEMON_PROCESS=xboxdrv
DAEMON_BINARY=xboxdrv
LOCK_FILE=/var/lock/subsys/$DAEMON_NAME
RETVAL=0

# default option, they can be overriden in /etc/sysconfig/$DAEMON_NAME
# of course, you can place what you want.
OPTIONS=--silent --dpad-as-button
PORT=1234
# this file should be commented, with proper pointer to the doc, and you should use
# more than one line of option, if possible.
[ -f /etc/sysconfig/$DAEMON_NAME ] && . /etc/sysconfig/$DAEMON_NAME


# here, you can do what you want with the option

start() {
    # if you cannot start the daemon since something is missing ( like a path that cannot be set by default
    # , place the test here
    # if [ -z "$SOME_VAR" ]; then
    #     gprintf "You need to set %s in /etc/sysconfig/%s\n" "$SOME_VAR" "$DAEMON_NAME"
    #     RETVAL=1
    #     return
    # fi

    [ -f $LOCK_FILE ] && return

    gprintf "Starting %s: " "$DAEMON_NAME"
    # use --user to run the daemon under the specified uid
    daemon $DAEMON_BINARY $OPTIONS 
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $LOCK_FILE
}

stop() {
    gprintf "Shutting down %s: " "$DAEMON_NAME"
    killproc $DAEMON_PROCESS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
}

reload() {
    gprintf "Reloading %s configuration: " "$DAEMON_NAME"
    killproc $DAEMON_PROCESS -HUP
    RETVAL=$?
    echo
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status $DAEMON_PROCESS
        RETVAL=$?
        ;;
    reload)
        reload
        ;;
    restart)
        stop
        start
        ;;
    condrestart)
        if [ -f $LOCK_FILE ]; then
            stop
            start
        fi
        ;;
    *)
        gprintf "Usage: %s {start|stop|restart|reload|condrestart|status}\n" "$0"
        RETVAL=1
esac

exit $RETVAL


