#!/bin/sh


    if [ -f /etc/config/network ]; then
    # old method is very insecure so we drop it
    # . /etc/config/network
    configfile='/etc/config/network'
    configfile_secured='/etc/config/network'
    # check if the file contains something we don't want
    if egrep -q -v '^#|^[^ ]*=[^;]*' "$configfile"; then
        # filter the original to a new file
        egrep '^#|^[^ ]*=[^;&]*'  "$configfile" > "$configfile_secured"
        configfile="$configfile_secured"
    fi
    source "$configfile"
    #[ x"$NETMASK" != x"0" ] || NETMASK="24";
    #[ x"$IPADDR" != x"0.0.0.0" ] || IPADDR="192.168.0.2";
    [ x"$MGMTNETMASK" != x"0" ] || MGMTNETMASK="24";
    [ x"$MGMTIPADDR" != x"0.0.0.0" ] || MGMTIPADDR="192.168.1.2";
    [ x"$MGMTVID" != x"0" ] || MGMTVID="1";

    #position=`expr $NETMASK - 8`	
    #OIFS=$IFS
    #IFS='/'
    #masks=$MASKEXAMPLES
    #pos=0
    #for x in $masks
    #do
#	if [ "x$pos" = "x$position" ]; then
#	   NETMASK=$x
#	fi
 #       pos=`expr $pos + 1`
  #  done
   # IFS=$OIFS

    #insmod /lib/modules/eth_pss.ko
    #mknod /dev/mvPP c 240 0
    #insmod /lib/modules/mvKernelExt.ko mvKernelExt_major=241
    #mknod /dev/mvKernelExt c 241 1
    #ifconfig eth0 $IPADDR; #> /dev/null 2>&1;
    #ifconfig eth0 $IPADDR netmask $NETMASK up > /dev/null 2>&1;
    #ifconfig eth1 $MGMTIPADDR > /dev/null 2>&1;
    #ifconfig eth1 $MGMTIPADDR/$MGMTNETMASK up > /dev/null 2>&1;
    #ifconfig lan 192.168.255.254 up
    /usr/sbin/switchd >/dev/null 2>&1 &


    if [ $? = 0 ]; then
    if [ x"$GATEWAY" != x"0.0.0.0" ] && [ "$GATEWAY" != "" ]; then
        #echo "route add default gw $GATEWAY";
        route add default gw $GATEWAY > /dev/null 2>&1;
        if [ $? = 0 ]; then
            echo "error: network configuration failed!!";
            exit -1;
        fi
    fi;
    else
        echo "error: network configuration failed!!!";
        exit -1;
    fi;
fi;

exit 0;
