#!/bin/sh 
################################################################################
#
#                    S H E L L   S C R I P T  F I L E  
#
#                    COPYRIGHT 1997 - 2011  MOTOROLA
#                         ALL RIGHTS RESERVED
#
################################################################################
#
#   FILE NAME       : ifcfg-eth0_config 
#   FUNCTION        : Set the autoneg option in the file 'ifcfg-eth0'  on.
#   PARAMETERS      : None. 
#
################################################################################
#
# Revision History:
#
# Date               Description
# ---------      -----------------------------------------------------
# 04-May-11    Initial version
################################################################################


######################### Main function ########################################
SUCCESS=0
ERROR=1

NetworkScriptsPath="/etc/sysconfig/network-scripts"
ifcfgEth0File="/etc/sysconfig/network-scripts/ifcfg-eth0"
ETHTOOL_ON="\"speed 100 duplex full autoneg on\""



echo ""
echo "Setting ifcfg-eth0 to Autoneg-On"

if [ ! -e $ifcfgEth0File ]
then
echo "$ifcfgEth0File not exists"
exit ${ERROR}
fi


# Set autoneg
result=`grep -c "ETHTOOL_OPTS" $ifcfgEth0File`  > /dev/null
if [[ $result -eq 0 ]]
then
	# no line contains the 'ETHTOOL_OPTS' pattern was found
	echo "ETHTOOL_OPTS="$ETHTOOL_ON >> $ifcfgEth0File
else
	# line contains the 'ETHTOOL_OPTS' pattern was found
	sed 's/^ETHTOOL_OPTS.*/ETHTOOL_OPTS=\"speed 100 duplex full autoneg on\"/g' $ifcfgEth0File > /tmp/ifcfg-eth0.tmp 
 
	cp -f /tmp/ifcfg-eth0.tmp $ifcfgEth0File
	rm -f /tmp/ifcfg-eth0.tmp
fi


exit ${SUCCESS}


 