#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          zarafa-ical
# Required-Start:    $syslog $network $remote_fs
# Required-Stop:     $syslog $network $remote_fs
# Should-Start:      zarafa-server
# Should-Stop:       zarafa-server
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# X-UnitedLinux-Default-Enabled:   yes
# Short-Description: Zarafa Collaboration Platoform's iCal Gateway
# Description:       The Zarafa iCal Gateway allows users
#                    to access their calender using the iCal or CalDAV protocol.
### END INIT INFO

. /etc/rc.status
rc_reset

ICALCONFIG=/etc/zarafa/ical.cfg
ICALPROGRAM=/usr/sbin/zarafa-ical

# Sanity checks.
#[ -f $CALDAVCONFIG ] || exit 0
[ -x $ICALPROGRAM ] || exit 0

ICALCONFIG_OPT=""
[ ! -z $ICALCONFIG -a -f $ICALCONFIG ] && ICALCONFIG_OPT="-c $ICALCONFIG"

[ -f /etc/sysconfig/zarafa ] && . /etc/sysconfig/zarafa
if [ -z "$ZARAFA_LOCALE" ]; then
	ZARAFA_LOCALE="C"
fi

ical=`basename $ICALPROGRAM`

case "$1" in
    start)
		echo -n "Starting Zarafa ical "
		install -dm0775 -o zarafa -g zarafa /var/run/zarafad
		export LC_ALL=$ZARAFA_LOCALE
		export LANG=$ZARAFA_LOCALE
		$ICALPROGRAM $ICALCONFIG_OPT
		rc_status -v
		unset LC_ALL LANG
		;;

    stop)
		echo -n "Stopping Zarafa ical "
		killproc $ical
		rc_status -v
		;;

    restart)
		$0 stop
		$0 start
		;;

    reload)
		echo -n "Restarting zarafa ical "
		killproc $ical -SIGHUP
		rc_status -v
		;;

    status)
		echo -n "Checking for Zarafa ical "
		checkproc $ical
		rc_status -v
		;;

    *)
		;;
esac

rc_exit
