#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          ICAP
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: IKU ICAP
# Description:       Start IKU ICAP
#	needed for Squid ICAP capabilities
### END INIT INFO
# 
ICAP_BIN=/usr/lib/iku-av/bin/av-icapd
test -x $ICAP_BIN || { echo "$ICAP_BIN not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

# Check for existence of needed config file and read it
ICAP_CONFIG=/usr/lib/iku-av/bin/avira-icap.conf
test -r $ICAP_CONFIG || { echo "$ICAP_CONFIG not existing";
	if [ "$1" = "stop" ]; then exit 0;
	else exit 6; fi; }

[ -e /etc/rc.status ] && . /etc/rc.status

# Reset status of this service
#rc_reset

case "$1" in
    start)
	echo -n "Starting ICAP "
	/usr/lib/iku-av/bin/license-tool
	start-stop-daemon --start --exec $ICAP_BIN -- --config-file=$ICAP_CONFIG
	;;
    stop)
	echo -n "Shutting down ICAP "
	start-stop-daemon --stop --exec $ICAP_BIN
	;;
    restart)
	echo -n "Restarting ICAP"
	$0 stop
	sleep 1
	$0 start
	;;
    *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac
echo
#rc_exit
