#!/bin/bash
#
# Startup script for Scanbuttond
#
# chkconfig: - 98 54
# description: scanbuttond is a small daemon which checks for supported scanners \
#              when attached to system, it loads that respective backend so that \
#              buttons on that scanners gets activated for their functionings defined \
#              in /etc/scanbuttond/buttonpressed.sh file.
# processname: scanbuttond
# config: /etc/scanbuttond

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

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Some definitions.
scanbuttond=/usr/bin/scanbuttond
prog=scanbuttond
RETVAL=0

#
start() {
        echo -n $"Starting $prog: "
        daemon $scanbuttond $OPTIONS
        RETVAL=$?
        echo
        if [ $RETVAL = 0 ] ; then
           touch /var/lock/subsys/scanbuttond
        else
           RETVAL=1
        fi
        return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc $scanbuttond
	RETVAL=$?
	echo
	if [ $RETVAL = 0 ] ; then
           rm -f /var/lock/subsys/scanbuttond
        else
           RETVAL=1
        fi
        return $RETVAL
}

reload() {
	echo -n $"Reloading $prog: "
	killproc $scanbuttond -HUP
	RETVAL=$?
	echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status $scanbuttond
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  condrestart)
        [ -f /var/lock/subsys/scanbuttond ] && restart
        ;;
  *)
	echo $"Usage: $prog {start|stop|restart|status|condrestart}"
	exit 1
esac

exit $RETVAL
