#!/bin/sh
#
# $NetBSD: nullmailer.sh,v 1.5 2017/10/28 04:51:06 schmonz Exp $
#
# nullmailer-2.2nb19 script to control nullmailer (simple relay-only MTA).
#

# PROVIDE: mail

name="nullmailer"

# User-settable rc.conf variables and their default values:
: ${nullmailer_postenv:=""}
: ${nullmailer_logcmd:="logger -t nb${name} -p mail.info"}

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

rcvar=${name}
required_files="/usr/pkg/etc/nullmailer/remotes"
required_dirs="/var/spool/nullmailer/queue /var/spool/nullmailer/tmp"
command="/usr/pkg/libexec/nullmailer/nullmailer-send"
start_precmd="nullmailer_prestart"

nullmailer_prestart()
{
	command="/usr/pkg/bin/pgrphack /usr/bin/env - ${nullmailer_postenv}
/usr/pkg/bin/setuidgid nullmail /usr/pkg/libexec/nullmailer/nullmailer-send
2>&1 |
/usr/pkg/bin/pgrphack /usr/pkg/bin/setuidgid nullmail ${nullmailer_logcmd}"
	command_args="&"
	rc_flags=""
}

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