#
# DESCRIPTION:
#
#   configure an interface to boot boot over network
#
# part of the LiveBackup project:  
#
#                     http://livebackup.sourceforge.net/
#
# Copyright 2006-2010 by Wolfgang Rohrmoser <info@rohrmoser-engineering.de>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

if [ "$ADDRESS" != "not_set" ]; then

    sleep 5			# wait until network driver is initialized

    if [ $LB_DEBUG -eq 50 ]; then  set -x; fi

    if [ "$ADDRESS" = "dhcp" ]; then
	msg -i "configure network by dhcp, using $INTERFACE ...."
	udhcpc -n -i $INTERFACE
	if [ $? -ne 0 ]; then
	    msg -c "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	    msg -c "ERROR: failed to configure network by dhcp"
	    msg -c "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	    rescue_shell "try to use: udhcpc -i $INTERFACE, on success continue by exit" 
        fi
    else
	msg -w "network $INTERFACE: ip=$ADDRESS, mask=$NETMASK, gateway=$GATEWAY"
        ifconfig $INTERFACE $ADDRESS netmask $NETMASK
	if [ $? -ne 0 ]; then
	    msg -c "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	    msg -c "ERROR: failed to configure the network    "
	    msg -c "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	    rescue_shell "you can try to fix it in this shell and continue by exit" 
        fi
	if [ "$GATEWAY" != "0.0.0.0" ]; then
	   route add default gw $GATEWAY
	fi
	if [ $LB_DEBUG -gt 3 ]; then
	    ifconfig
            route -n
	fi
    fi
fi


#
# Local Variables: 
# mode: shell-script
# End: 
#
