#!/bin/bash
#
# Execute topology commands requiring root privilege 
#
# Description: Issue to run topology commands 
#
# Change Activity:
#   08/07/2006 Feustel     - initial version
#
#STARTUSAGE
#
# Usage:
#   collecteed -s savedTopologySourceFile -e deviceForEthtool
#
# Where:
#   -s   The fully-qualified path name of the tmp file to save as the new saved topology
#
#   -e   Device to query with ethtool (eth0, eth1, etc). 
#
#
#ENDUSAGE
#****************************************************************************
noopt=1
giveUsage=0
sfile=
dev=

# Parse the options
while getopts 's:e:?' optname; do
   case "$optname" in
      s) sfile="$OPTARG";;
      e) dev="$OPTARG";;
      \?) giveUsage=1; break;;
   esac
   noopt=0
done

if [ "$giveUsage" -eq 1 ]; then
   # Print out the prologue comments as usage info
   sed -e '/STARTUSAGE/,/ENDUSAGE/ s/^#//' -e '1,/STARTUSAGE/ d' -e '/ENDUSAGE/,$ d' "$0"
   exit 0
fi
      
if [ "$noopt" -eq 1 ]; then
   # Print out the prologue comments as usage info
   sed -e '1 d' -e '2,/ENDUSAGE/ s/^#//' -e '/ENDUSAGE/,$ d' "$0"
   exit 0
fi

if [ -n "$sfile" ]; then
   # Save the passed topology file to the standard place
   /bin/mv -f ${sfile} /opt/hsc/data/topology/saved_topology.xml
fi

if [ -n "$dev" ]; then
   # Run the ethtool command to query the given device
   osname=`uname`
   if [ "$osname" != "AIX" ]
   then
      /usr/sbin/ethtool ${dev}
   else
      /usr/bin/netstat -v ${dev}
   fi
fi

exit 0
