#!/bin/sh
#
# $Id: sc_createfreebusy 7151 2012-08-28 15:27:09Z joergs $
#
# Copyright (c) 2005-2010 dass IT GmbH, Cologne (Germany).  All rights reserved.
#
# Author: Phil Sutter <Phil.Sutter@dass-IT.de>
# Author: Joerg Steffens <joerg.steffens@dass-it.de>
#
# /etc/init.d/sc_createfreebusy
#
# System startup script for the Freebusy-List generator
#
### BEGIN INIT INFO
# Provides:          sc_createfreebusy
# Required-Start:    $network $remote_fs
# Should-Start:      waitfornm
# Required-Stop:     $null
# Should-Stop:       $null
# Default-Start:     5
# Default-Stop:      0 1 2 4 6
# Short-Description: creates Freebusy-URLs list
# Description:       creates a Freebusy-URL list for all users.
#	User information are taken from the LDAP-directory.
#       The list is used by KDE Kontact
### END INIT INFO

FREEBUSY_BIN=/usr/bin/sc_freebusy.pl
test -x $FREEBUSY_BIN || { echo "$FREEBUSY_BIN not found"; exit 5; }
FREEBUSY_DIR="/var/lib/kde-profiles/vermkv_kontact/share/apps/korganizer"
FREEBUSY_FILE="$FREEBUSY_DIR/freebusyurls"
mkdir -p "$FREEBUSY_DIR"

. /etc/rc.status
rc_reset

# source SmartClient config
test -r /etc/smartclient/base && source /etc/smartclient/base

base=${0##*/}
link=${base#*[SK][0-9][0-9]}

case "$1" in 
	start|restart|try-restart|condrestart|force-reload|reload)
        echo -n "Creating FreeBusy list "
        if ! /usr/bin/sc_check_net 2> $ALL_LOG_DIR/$base; then
            rc_status -s
            rc_exit
        fi
        $FREEBUSY_BIN > "$FREEBUSY_FILE" 2>$ALL_LOG_DIR/$base &
        rc_status -v
	;;
	stop)
		#echo -n "This script doesnt need to be stopped "
		#rc_status -v
		#rc_exit
	;;
	reload|restart|try-restart|condrestart)
		rc_active $0 || { echo "Service is not active, wont restart" ; exit 7; } 
		$0 start
		rc_status -v
	;;
    status)
        echo -n "Checking for FreeBusy list ($FREEBUSY_FILE) "
        if [ -r "$FREEBUSY_FILE" ]; then
            rc_status -v
        else
            rc_status -u
        fi
    ;;
	*)
		echo "Usage: $0 {start|status}"
		exit 1
	;;
esac
rc_exit

