#!/bin/sh

# update odhcpd uci to use unbound's script as leasetrigger
uci -q get dhcp.odhcpd >/dev/null 2>&1 && {
	maindhcp="$(uci -q get dhcp.odhcpd.maindhcp)"

	# if odhcpd is the main dhcp
	[ "$maindhcp" = "1" ] || [ "$maindhcp" = "true" ] || [ "$maindhcp" = "on" ] && {
		# if unbound daemon and unbound script file is present
		[ -e /usr/lib/unbound/odhcpd.sh ] && [ -e /usr/sbin/unbound ] && {
			# then set unbound script as leasetrigger in dhcp UCI
			uci -q set dhcp.odhcpd.leasetrigger='/usr/lib/unbound/odhcpd.sh'
		}
	}
}

exit 0
