#!/bin/sh

ERR=""
IP=""
MASK=""
GW=""
MAC=""
BRD=""
DSP=NO

while [ ! "x$1" = "x" ] ; do
  case $1 in
   ip)
     IP=$2
     shift 2
     ;;
   gw)
     GW=$2
     shift 2
     ;;
   broadcast)
     BRD=$2
     shift 2
     ;;
   mask)
     MASK=$2
     shift 2
     ;;
   mac)
     MAC=$2
     shift 2
     ;;
   disp)
     DSP=yes
     shift 1
     ;;
   *)
     ERR=yes
     shift 1
     ;;
  esac
done

if [ ! "x$ERR" = "x" -o "x$IP" = "x" ] ; then
  echo
  echo "Sintax error USAGE:"
  echo
  echo "$0 ip <ip_addr> [mac <mac_addr>] [mask <netmask>]"
  echo "                 [gw <ip_addr>] [broadcast <broad_addr>] [disp]"
  echo
  exit
fi

ifconfig eth0 down 2>/dev/null

if [ ! "x$MAC" = "x" ] ; then
  cmd=" hw ether $MAC $IP "
else
  cmd=" $IP "
fi

if [ ! "x$MASK" = "x" ] ; then
  cmd=$cmd" netmask $MASK "
fi

if [ ! "x$BRD" = "x" ] ; then
  cmd=$cmd" broadcast $BRD "
fi

ifconfig eth0 $cmd up 2>/dev/null

if [ ! $? = 0 ] ; then
  echo "*"
  echo "* * * Invalid parameters for ifconfig"
  echo "*"
  echo
  echo ifconfig eth0 $cmd up
  echo
fi

if [ ! "x$GW" = "x" ] ; then
  route add default gw $GW eth0 2>/dev/null
fi

if [ $DSP = yes ] ; then
  ifconfig eth0
  echo
  route
fi


