#!/bin/ksh
#
# $OpenBSD: unbound,v 1.10 2025/11/16 13:27:50 kn Exp $

daemon="/usr/sbin/unbound"
daemon_flags="-c /var/unbound/etc/unbound.conf"

. /etc/rc.d/rc.subr

rc_pre() {
	local _anchor _config _opt

	while getopts :c: _opt $daemon_flags; do
		[[ $_opt == c ]] && _config=$OPTARG
	done

	_anchor=$($daemon-checkconf -o auto-trust-anchor-file $_config)

	if [[ -n $_anchor && ! -f $_anchor ]]; then
		$daemon-anchor -v -a $_anchor
	fi

	$daemon-checkconf $_config
}

rc_cmd $1
