#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org 

#This script is to record the boot logs for debug purpose,
#it should be executed after other scrips are all done
START=99

#Help keyword object to establish dns reply record at end of boot time
/etc/init.d/keyword_object restart &

# boot usb WAN if config is enabled
check_usb_wan() {
	usb_wan="usb1 usb2"
	for elem in $usb_wan;do
		usb_status=$(uci -q get network.${elem}.status)
		usb_conn=$(json get network.${elem}.connection)
		if [ "$usb_status" = "enable" -a "$usb_conn" = "down" ]; then
			/etc/gcom/3g.reboot &
			break
		fi
	done
}

IPTABLE_BOOT_LOG=/tmp/iptables_bootlog
IPSET_BOOT_LOG=/tmp/ipset_bootlog

boot() 
{
     burnin=$(/sbin/mtd fw_printenv 1|grep burnin_check|awk -F = '{print $2}')
	/usr/sbin/iptables-save > $IPTABLE_BOOT_LOG
	/usr/sbin/ipset -S > $IPSET_BOOT_LOG
	echo "boot completed" >/dev/console
	#check_usb_wan
	#power on USB device
	uci -q -P /var/state revert network.usb1
	uci -q -P /var/state revert network.usb2
	uci -q -P /var/state set network.usb_boot=1
	/etc/init.d/usb usb_pw all on 1>/dev/null 2>&1
	if [ "$burnin" -eq "1" ]; then
         /sbin/mtd fw_setenv burnin_linux 1
         reboot
    fi
}
