#!/bin/sh
[ -n "${IPKG_INSTROOT}" ] && exit 0
if command -v uci >/dev/null; then
	IP="$(uci -q get dns-failsafe-proxy.main.listen_ip)"
	PORT="$(uci -q get dns-failsafe-proxy.main.listen_port)"
	if [ -n "$IP" ] && [ -n "$PORT" ]; then
		SERVER="${IP}#${PORT}"
		if ! uci -q get dhcp.@dnsmasq[0].server | grep -q "$SERVER"; then
			uci add_list dhcp.@dnsmasq[0].server="$SERVER"
			uci set dhcp.@dnsmasq[0].noresolv='1'
			uci commit dhcp
			/etc/init.d/dnsmasq restart 2>/dev/null
		fi
	fi
fi
exit 0
