#!/bin/sh
# keytouch - a program to configure the extra function keys of the keyboard
### BEGIN INIT INFO
# Provides:          keytouch
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Should-Start:      
# Should-Stop:       
# Default-Start:     2
# Default-Stop:      0 6
# Short-Description: Initialize extra function keys in multimedia keyboards
# Description:       Initializes kernel keymappings for multimedia keyboard's
#                    extra function keys. This mappings are used by the keytouch
#                    daemon inside an X session to assign actions to those keys.
#                    It also initializes resending of ACPID keypresses as events
#                    for keytouchd.
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/keytouch-init
ACPID_DAEMON=/usr/bin/keytouch-acpid
KEYBOARD_FILE=/etc/keytouch/current_keyboard.xml
NAME=keytouch-init
DESC=keytouch

set -e

test -x $DAEMON || exit 0
test -f $KEYBOARD_FILE || exit 0

case "$1" in
  start)
	echo -n "Initializing $DESC:"
	echo -n " keytouch-init";  start-stop-daemon --start --quiet --oknodo --exec $DAEMON
        echo -n " keytouch-acpid"; start-stop-daemon --start --quiet --oknodo --background --exec $ACPID_DAEMON
	echo "."
	;;
  stop)
        echo -n "Stopping $DESC:"
        # Try to stop keytouch-acpid only if it is running
        if /sbin/start-stop-daemon --stop --test --quiet --exec $ACPID_DAEMON; then  
            echo -n " keytouch-acpid"; start-stop-daemon --stop --quiet --exec $ACPID_DAEMON
            echo "."
        else
            echo " nothing to do."
        fi
	;;
  restart|force-reload)
        $0 stop
        $0 start
        ;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
