#!/bin/sh
#
# $NetBSD: fetchmail.sh,v 1.4 2021/11/10 19:24:52 khorben Exp $
#
# PROVIDE: fetchmail
# REQUIRE: mail
#
# You will need to set some variables in /etc/rc.conf to start fetchmail:
#
# fetchmail=YES

if [ -f /etc/rc.subr ]; then
	$_rc_subr_loaded . /etc/rc.subr
fi

name="fetchmail"
rcvar=$name
command="/usr/pkg/bin/${name}"
pidfile="/var/run/${name}.pid"
required_files="/usr/pkg/etc/${name}.conf"
extra_commands="awaken reload"
command_args="-f - < /usr/pkg/etc/${name}.conf"
awaken_cmd="start_poll"

start_poll () 
{
	DAEMON_PID=`sed 1q ${pidfile}`
	: ${DAEMON_PID:=0}
	echo -n "Awakening ${name} daemon"
	if [ ${DAEMON_PID} -ne 0 ]; then
		kill -SIGUSR1 ${DAEMON_PID} >/dev/null 2>&1; 
	fi
	echo '.'
}

if [ -f /etc/rc.subr ]; then
	load_rc_config $name
	run_rc_command "$1"
else
	echo -n ' ${name}'
	${command} ${fetchmail_flags} ${command_args}
fi
