#!/bin/sh

. /lib/functions.sh

cfg=mapcontroller
config_load $cfg

uci -q get $cfg.controller.debug >/dev/null 2>&1 && \
	uci set $cfg.controller.debug='2'

allow_bgdfs=$(uci -q get $cfg.controller.allow_bgdfs || echo "0")
channel_plan_val=$(uci -q get $cfg.controller.channel_plan || echo "0")

uci -q delete $cfg.controller.allow_bgdfs
uci -q delete $cfg.controller.channel_plan

uci -q get $cfg.controller.stale_sta_timeout >/dev/null 2>&1 || \
	uci set $cfg.controller.stale_sta_timeout='30d'

if [ -f /usr/lib/mapcontroller/zerotouch.so ]; then
	uci -q del_list $cfg.controller.plugin='zerotouch'
	uci -q add_list $cfg.controller.plugin='zerotouch'
fi

if ! uci show $cfg 2>/dev/null | grep -q "=channel_plan"; then
	section=$(uci add $cfg channel_plan)
	uci set $cfg.$section.preclear_dfs="$allow_bgdfs"
	uci set $cfg.$section.acs="$channel_plan_val"
fi

exit 0
