#!/bin/sh
json="/usr/sbin/jsoner"
file="/work/config.json"
#**************************************************************


#***********************************************************
# set mac addr
#***********************************************************
setMacAddr()
{
    mac=`$json -g $file eth0.mac`
    if [ $? -ne 0 ]
    then
	return;
    fi
    
    /sbin/ifconfig eth0 down
    /sbin/ifconfig eth0 hw ether $mac
#    /sbin/ifconfig eth0 up
    echo "set mac0 $mac"
    
}
#********************************************************************

setMacAddr 0

#˿ӡʵǷģҪһ
#-set eth0----------------------------------
dhcp0=`$json -g $file "eth0.dhcp"`
if [ $? -eq 0 ]
then 
	echo "dhcp0 : $dhcp0"
    if [ $dhcp0 == "on" ]
    then
		echo "dhcp1 is true"
		/sbin/udhcpc -i eth0 &
		exit
    fi
fi

sleep 1

ip=`$json -g $file "eth0.ip"`
mask=`jsoner -g $file "eth0.mask"`
#/sbin/ifconfig eth0 down
/sbin/ifconfig eth0 $ip netmask $mask up

gate=`$json -g $file "eth0.gate"`
route del default dev eth0 
route add default gw $gate dev eth0 


VALID_WIFI=`$json -g $file "wifi.enable"`
VALID_4G=`$json -g $file "4g.enable"`

#wifi
if [ ${VALID_WIFI} = "true" ]; then
	echo "start wifi..."
	/sbin/route del default
	$startWifi &
fi

#4g
#if [ ${VALID_4G} = "true" ]
#then
#	$start4G &
#fi

