#!/bin/sh

# $FreeBSD$
#
# PROVIDE: netifyd
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# netifyd_enable (bool):    Set to NO by default.
#                           Set it to YES to enable netifyd.
# netifyd_opts (args):      Set manual configuration options.

. /etc/rc.subr

name="netifyd"
rcvar="${name}_enable"

command="/usr/local/sbin/${name}"
pidfile="/var/run/${name}/${name}.pid"

start_precmd="${name}_prestart"

export ASAN_OPTIONS=log_path=/var/run/${name}/${name}-asan.log:atexit=1

netifyd_prestart()
{
    . /usr/local/share/netifyd/functions.sh

    case "$(detect_os)" in
    opnsense | pfsense)
        # OPNsense/pfSense detected, enable auto-detect:
        export NETIFYD_AUTODETECT="yes"
        netifyd_opts=$(auto_detect_options)
        ;;
    esac

    rc_flags="${netifyd_opts} ${rc_flags}"

    return 0
}

load_rc_config $name

: ${netifyd_enable:=no}

run_rc_command "$1"
