#!/bin/sh
#
# Give every atc interface a defined auto_apn value so the handler and the UI
# agree on what should happen.  Existing choices are never overwritten: this
# runs again on each package upgrade.
#

changed=0

for iface in $(uci -q show network | sed -n "s/^network\.\([^.]*\)\.proto='atc'\$/\1/p")
do
	# Already answered by the user or by a previous run.
	uci -q get "network.${iface}.auto_apn" >/dev/null && continue

	if [ -n "$(uci -q get "network.${iface}.apn")" ]
	then
		uci set "network.${iface}.auto_apn=0"
	else
		uci set "network.${iface}.auto_apn=1"
	fi
	changed=1
done

[ "$changed" = 1 ] && uci commit network

exit 0
