#!/bin/sh /etc/rc.common

START=99

check_load_default()
{
	webinit=`nvram_get WebInit`
	[ "$webinit" != "1" ] && {
		ralink_init clear 2860 > /dev/null 2>&1
		ralink_init renew 2860 /etc_ro/Wireless/RT2860AP/RT2860_default_vlan > /dev/null 2>&1
		rm -rf /overlay/*
	}
}

sync_wui_telnet_passwd()
{
	login=`nvram_get 2860 Login`
	pass=`nvram_get 2860 Password`
	if [ "$login" != "" -a "$pass" != "" ]; then
		echo "$login::0:0:Adminstrator:/:/bin/sh" > /etc/passwd
		echo "$login:x:0:$login" > /etc/group
		cat >> /etc/group << EOF
daemon:x:1:
adm:x:4:
mail:x:8:
audio:x:29:
www-data:x:33:
ftp:x:55:
users:x:100:
network:x:101:
nogroup:x:65534:
dnsmasq:x:453:
lldp:x:129:
EOF
		chpasswd.sh "$login" "$pass"
	fi
}

start(){

	# nvram_check
	count=$(ralink_init show 2860 2>&1 | grep -c 'Could not open mtd')
	if [ $count -ne 0 ]; then
		exit 1
	fi
	
	hostname=`nvram_get HostName`
	echo "$hostname" >/proc/sys/kernel/hostname

	radius.sh init
	
	check_load_default
	sync_wui_telnet_passwd
	#init_boarddata

	nvram_daemon&
	goahead&
	#/etc/init.d/firewall disable
	#/etc/init.d/firewall stop
	#iptables -F
    
	# this should be invoked after "nvram_daemon" who writes parameter "Login" and "Password" to config	
	# /sbin/burn_in.sh
	# dray_fwup &
	dray_sta_info &
	dray_rs &
	#for telnet debugging
	telnetd
	#/sbin/apmc.sh
}

stop(){
	# killall goahead
	# killall nvram_daemon
	echo "" > /dev/null
}


