#!/bin/sh
#
# $NetBSD: canna.sh,v 1.2 2006/07/05 04:48:28 jlam Exp $
#
# PROVIDE: canna
# REQUIRE: DAEMON

. /etc/rc.subr

name="canna"
rcvar=$name
command="/usr/pkg/sbin/cannaserver"
start_precmd="canna_prestart"
stop_cmd="/usr/pkg/sbin/cannakill"

mkdir_perms() {
	dir="$1"; user="$2"; group="$3"; mode="$4"
	test -d $dir || /bin/mkdir -p $dir
	/usr/sbin/chown $user $dir
	/usr/bin/chgrp $group $dir
	/bin/chmod $mode $dir
}

canna_prestart()
{
	mkdir_perms /var/spool/canna daemon daemon 0755
	mkdir_perms /var/dict/canna daemon daemon 0775
	mkdir_perms /var/dict/canna/canna daemon daemon 0775

	srcdictdir="/usr/pkg/libdata/canna"
	dictdir="/var/dict/canna/canna"
	if test -d $srcdictdir; then
		( cd $srcdictdir; for f in *; do
			test "$f" != "*" || continue
			/bin/rm -f $dictdir/$f
			/bin/ln -fs $srcdictdir/$f $dictdir/$f
		done )
	fi
}

load_rc_config $name
run_rc_command "$1"
