#!/bin/sh
FON_REVISION=$(cat /etc/fon_revision)

[ $(( $FON_REVISION )) -ge 1 ] || {
	# this one needs to be committed to have an effect...
	# the rest is only set in ram only
	[ "$(nvram get boot_wait)" = "on" ] || {
		nvram set boot_wait=on
		nvram commit
	}
	nvram set lan_ipaddr=192.168.10.1
	[ "$(nvram get wl0_ssid)" = "FON" ] && nvram set wl0_ssid=HotSpot
	rm /etc/fon_revision
	echo 1 > /etc/fon_revision
}

	# update from previous default ssid

# disable all encryption and set normal access point mode
nvram set wl0_mode=ap
nvram set wl0_closed=0
nvram set wl0_infra=1
nvram set wl0_macmode=none
nvram set wl0_akm=none
nvram set wl0_wep=disabled
nvram set wl0_auth=0

wl_if="$(iwconfig 2>&1 | grep IEEE | awk '{print $1}')"
[ -z "$wl_if" ] || {
	# remove the wireless interface from the bridge configuration
	ifnames=""
	for tmp in $(nvram get lan_ifnames); do
		[ "$tmp" = "$wl_if" ] || ifnames="$ifnames $tmp"
	done
	ifnames="${ifnames%% }"
	ifnames="${ifnames## }"
	[ -z "$ifnames" ] || nvram set lan_ifnames="$ifnames"

	nvram set wifi_ifname="$wl_if"
	nvram set wifi_proto=static
	nvram set wifi_ipaddr=192.168.182.1
	nvram set wifi_netmask=255.255.255.0
}

# grab the startup lock
lock -u /var/run/startup.lock
lock /var/run/startup.lock
