#! /bin/sh
#
# PROVIDE: trircd
# REQUIRE: DAEMON NETWORKING SERVERS
#
# Add the following line to /etc/rc.conf to enable trircd:
#
# trircd_enable="YES"
#
# Tweakable parameters for users to override in rc.conf

. "/etc/rc.subr"

name=trircd

load_rc_config ${name}
: ${trircd_enable="NO"}
: ${trircd_user="trircd"}
: ${trircd_group="trircd"}
: ${trircd_confdir=/usr/local/etc/tr-ircd}
: ${trircd_conf=${trircd_confdir}/ircd.conf}
: ${trircd_pidfile=/var/run/tr-ircd/ircd.pid}
: ${trircd_flags="-d ${trircd_confdir} -c ${trircd_conf} >/dev/null 2>&1"}

rcvar=`set_rcvar`
command=/usr/local/bin/tr-ircd
pidfile=${trircd_pidfile}
required_files="${trircd_conf}"
start_precmd="start_precmd"

irandom=/usr/local/share/tr-ircd/tools/irandom.sh
trircd_rundir=/var/run/tr-ircd
trircd_logdir=/var/log/tr-ircd
trircd_randfile=${trircd_rundir}/ircd.rand

start_precmd()
{
	[ -d "${trircd_logdir}" ] || {
		/bin/mkdir -p ${trircd_logdir}
		/usr/sbin/chown ${trircd_user}:${trircd_group} ${trircd_logdir}
		/bin/chmod 770 ${trircd_logdir}
	}
	[ -d "${trircd_rundir}" ] || {
		/bin/mkdir -p ${trircd_rundir}
		/usr/sbin/chown ${trircd_user}:${trircd_group} ${trircd_rundir}
		/bin/chmod 770 ${trircd_rundir}
	}
	[ -f "${trircd_randfile}" ] || ${irandom}
}

run_rc_command "$1"
