#!/bin/sh

# PROVIDE: spoofdpi
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf or /etc/rc.conf.local to
# enable spoofdpi:
# spoofdpi_args (str):	Custom additional arguments to be passed
#			spoofdpi (default empty).
# spoofdpi_user (str):	User to run spoofdpi as. Default
#			to "spoofdpi" created by the port.
# spoofdpi_log (path):	Console log file (default /var/log/spoofdpi.log or set to /dev/null to omit).

. /etc/rc.subr

case $0 in
/etc/rc*)
	# during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
	# so get the name of the script from $_file
	name=$_file
	;;
*)
	name=$0
	;;
esac

name=${name##*/}
rcvar="${name}_enable"

load_rc_config "${name}"

eval "${rcvar}=\${${rcvar}:-'NO'}"
eval "_args=\${${name}_args:-''}"
eval "_user=\${${name}_user:-'spoofdpi'}"
eval "_log=\${${name}_log:-/var/log/${name}.log}"

pidfile="/var/run/${name}.pid"

command="/usr/sbin/daemon"
command_args="-P ${pidfile} -u ${_user} -f -H -o ${_log} -m 3 /usr/local/bin/spoofdpi ${_args}"

run_rc_command "$1"
