#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          fjio
# Required-Start:    $syslog $local_fs
# Should-Start: 
# Required-Stop:     $syslog 
# Should-Stop: 
# Default-Start:     5
# Default-Stop:      0 1 2 3 6
# Short-Description: fjio daemon providing app-key events 
# Description:       Start fjiod to use buttons on Stylistic ST4000 Fujitsu Tablet.
#	
### END INIT INFO

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
APPNAME=fjio
APP=/usr/bin/fjiod
test -x $APP || { echo "$APP not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

KEYINIT=/etc/fjio_run/key_init
MODULE=fjkey_st4000

PROCFILE=/proc/fjkey_st4000/event
if [ ! -f $PROCFILE ]; then 
	modprobe fjkey_st4000 >/dev/null &2>1
fi
if [ ! -f $PROCFILE ]; then
	echo "Error: $DAEMON daemon: File $PROCFILE not found!"
	echo "       Module $MODULE may not have loaded."
	exit 0
fi
PROCFILE=/proc/fjkey_st4000/config
if [ ! -f $PROCFILE ]; then
	echo "Error: $DAEMON daemon: File $PROCFILE not found!"
	echo "       Module $MODULE may not have loaded."
	exit 0
fi
		

#. /etc/rc.status

# Reset status of this service
# rc_reset


case "$1" in
    
	start)
	echo -n "Starting $APPNAME Daemon "
	$KEYINIT start
	start-stop-daemon --start --quiet --pidfile /var/run/fjiod.pid --name fjiod --startas $APP
#	rc_status -v
	;;
	
    stop)
	echo -n "Shutting down $APPNAME Daemon "
	echo END >$PROCFILE &
	$KEYINIT stop 
	start-stop-daemon --stop --quiet --pidfile /var/run/fjiod.pid --name fjiod --startas $APP
#	rc_status -v
	;;
	
    try-restart|condrestart)
	$0 restart
	;;
	restart)
	$0 stop
	$0 start
#	rc_status
	;;
    force-reload)
	;;
    reload)
	;;
    status)
	echo -n "Checking for service $APPNAME "
	checkproc $APP
#	rc_status -v
	;;
    probe)
	;;

    *)
	INITNAME=`basename $0`
	echo "Usage: $INITNAME {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
#rc_exit

