#!/bin/sh
echo Try to bring eth0 interface up ...>/dev/console
ReadIni()#设备初始化
{
INIFILE=$1; SECTION=$2; ITEM=$3
_readIni=`awk -F '=' '/\['$SECTION'\]/{a=1}a==1&&$1~/'$ITEM'/{print $2;exit}' $INIFILE`
echo $_readIni
}
if [ -e /etc/NetConfig.ini ] ; then
NETCARDTYPE=$( ReadIni /etc/NetConfig.ini NetConfig NetCardType )
ADDRCONFIGTYPE=$( ReadIni /etc/NetConfig.ini NetConfig AddrConfigType )
IPADDR=$( ReadIni /etc/NetConfig.ini NetConfig IpAddr )
NETMASK=$( ReadIni /etc/NetConfig.ini NetConfig Netmask )
GATEWAY=$( ReadIni /etc/NetConfig.ini NetConfig Gateway )
MAC=$( ReadIni /etc/NetConfig.ini NetConfig MacAddr )
if [ -z $NETCARDTYPE ] ; then
echo "NetCardType is empty !" >/dev/console
exit 1
fi
if [ -z $ADDRCONFIGTYPE ] ; then
echo "AddrConfigType is empty !" >/dev/console
exit 1
fi
if [ -z $IPADDR ] ; then
echo "IpAddr is empty !" >/dev/console
exit 1
fi
if [ -z $NETMASK ] ; then
echo "Netmask is empty !" >/dev/console
exit 1
fi
if [ -z $GATEWAY ] ; then
echo "Gateway is empty !" >/dev/console
exit 1
fi
if [ -z $MAC ] ; then
echo "MacAddr is empty !" >/dev/console
exit 1
fi
if [ $NETCARDTYPE = "LAN" ] ; then
if [ $ADDRCONFIGTYPE = "DHCP" ] ; then
echo "Get ip type :"$ADDRCONFIGTYPE >/dev/console
ifconfig eth0 down
ifconfig eth0 hw ether $MAC
echo ifconfig eth0 hw ether $MAC >/dev/console
udhcpc
else
if [ $ADDRCONFIGTYPE = "MANUAL" ] ; then
echo "Get ip type :"$ADDRCONFIGTYPE >/dev/console
ifconfig eth0 down
ifconfig eth0 hw ether $MAC
echo ifconfig eth0 hw ether $MAC >/dev/console
ifconfig eth0 $IPADDR netmask $NETMASK up
echo ifconfig eth0 $IPADDR netmask $NETMASK up >/dev/console
route add default gw $GATEWAY
echo add default gw $GATEWAY >/dev/console
fi
fi
else
if [ $NETCARDTYPE = "WIFI" ] ; then
echo "wifi device not found!!!" >/dev/console
fi
fi
else
echo "/etc/NetConfig.ini not found!!!" >/dev/console
fi
echo Done > /dev/console