#!/bin/sh
# Created by: Mark Felder <feld@FreeBSD.org>

# PROVIDE: radicale
# REQUIRE: DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable radicale:
#  radicale_enable (bool):    Set to "NO" by default.
#                       Set it to "YES" to enable radicale.
#

. /etc/rc.subr

name=radicale
rcvar=radicale_enable

# set defaults

load_rc_config $name

: ${radicale_enable:=NO}
: ${radicale_config=%%ETCDIR%%/config}
: ${radicale_user=%%USERS%%}
: ${radicale_group=%%GROUPS%%}

pidfile=/var/run/radicale/radicale.pid
command=/usr/sbin/daemon
command_args="-P ${pidfile} -f -ST ${name} %%PREFIX%%/bin/radicale -C ${radicale_config}"
required_files=${radicale_config}
start_precmd=do_precmd

do_precmd()
{
	if [ ! -d ${pidfile%/*} ]; then
		install -d -o ${radicale_user} ${pidfile%/*}
	fi
}

run_rc_command "$1"
