#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian 
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=hotkeyd
DESC=hotkeyd
DAEMON=/usr/sbin/hotkeyd
OPTIONS=""
CONFFILE=/etc/hotkeydrc
DEVICE=/dev/input/event0
PIDFILE=/var/run/$NAME.pid

test -x $DAEMON || exit 0

test -r $CONFFILE || exit 0

# Include hotkeyd defaults if available
if [ -f /etc/default/hotkeyd ] ; then
	. /etc/default/hotkeyd
fi

OPTIONS="--pidfile=$PIDFILE \
    --config=$CONFFILE \
    --device=$DEVICE \
    $OPTIONS"

set -e

die() {
  echo "$@"
  return 1
}

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON -- $OPTIONS &&
		echo "$NAME." || die failed.
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --pidfile $PIDFILE &&
		echo "$NAME." || die failed.
	;;
  restart|force-reload)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --pidfile $PIDFILE &&
		echo "$NAME." || die failed. || true
	sleep 1
	echo -n "Starting $DESC: "
	start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON -- $OPTIONS &&
		echo "$NAME." || die failed.
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
