#!/bin/bash
# ---------------------------------------------------------------------------
# NAME
#
#     EnableEthernet - enables the Ethernet adapter in DHCP mode
#
# SYNOPSIS
#
#     EnableEthernet
#
# DESCRIPTION
#
#     Enables the Ethernet adapter in DHCP mode and configures the MAC ID
#     to the value in ~/macid.txt if the file is present.
#
# ---------------------------------------------------------------------------

# configure the MAC ID if the file is present
MACIDFILE=~/macid.txt
SWITCHCFGFILE=/home/smc/roots/000_EthernetSwitch/EthernetSwitchNumber.txt

if [ -s "$SWITCHCFGFILE" ]
then
  sudo SetPowerSwitch `cat "$SWITCHCFGFILE"` 1
fi

if [ -f "$MACIDFILE" ]
then
  NEWMACID=`cat $MACIDFILE`
  if [ -n "$NEWMACID" ]
  then
  	sudo ifconfig eth0 hw ether $NEWMACID
  fi
fi

# turns on the Ethernet adapter
sudo ifup eth0
sleep 3
ifconfig eth0 | grep inet
