#!/bin/bash
### BEGIN INIT INFO
# Provides: hmcpostnet
# Required-Start: $network $syslog
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop:
# Description: Provide network checking after hmc network has been configured
### END INIT INFO

# Source function library.
. /etc/rc.status

rc_reset

case "$1" in
  start)

    # Remove for defect 471534
    
    # reset IP error indicator file (referenced in xManager script)
    #persist_err_file=/var/hsc/log/ip_err_flag
    #if [ -f $persist_err_file ]; then
    #    rm -f $persist_err_file
    #fi

    #HOSTNAME=`/bin/hostname`
    #if [[ -n "$HOSTNAME" && "$HOSTNAME" != "localhost" && "$HOSTNAME" != "localhost.localdomain" ]]; then
  
        # A non-localhost hostname was detected meaning someone has previously set
        # the hostname and/or IP address.  Potential for IP conflict, so check it out...
    #    ls -1 /etc/sysconfig/network/ifcfg-eth* | while read file
    #    do

    #        ipaddr=$(grep "^IPADDR" $file | sed -e "s/IPADDR=//;s/'//g")
    #        if [[ "$ipaddr" != "" && "$ipaddr" != "127.0.0.1" ]]; then

                # rc=0 from 'arping' means no duplicate addresses...
    #            /sbin/arping -q -c 5 -D $ipaddr
          
                #
                # Note that rc could be = 2, indicating that, at least, the case
                # that the interface is not up, so skip it. A rc = 1 seems to indicate
                # the duplicate IP address condition.
                #
    #            if [ $? -eq 1 ]; then
                
                    # dup IP address so drop this interface
    #                interface=`echo $file | cut -c 30-33`
    #                /sbin/ifdown $interface 2>/dev/null
              
                    # rest hostname to something "safe"
    #                hostname localhost.localdomain

                    # Set error indicator flag
    #                touch $persist_err_file
    #                chmod 777 $persist_err_file
            
                    # one error is enough...
    #                break
    #            fi
    #        fi
    #    done
    #fi   

    # 
    # Now to set tg3 media speed dynamically - run ethtool for tg3 driver.
    # No big deal if interface is down due to the above condition, the
    # module will still be loaded.
    #
    cat /etc/modules.conf | grep "#tg3 " | grep "eth" | cut -c 6- | while  
    read cmd                                                               
    do                                                                     
      if [ "$cmd" != "" ]; then                                            
          `$cmd`                                                         
      fi                                                                   
    done                                                                   

    rc_status -v
    ;;
  stop)
    rc_status -v
    ;;
  *)
    echo "Usage: hmcpostnet {start|stop}"
    exit 1
    ;;
esac
rc_exit

