#!/bin/bash



###############################
###############################
#
# Display help text
#
###############################
###############################

helptext() {

	echo ""
	echo "------------------------------------------------"
	echo " Script to test network configuration settings "
	echo " on a system."
	echo ""
	echo " -h             Display help text (this text)"
	echo " -o <target>    Redirect outpput from stdout to "
	echo "                <target> file. If <target>"
	echo "                already exists it will be "
	echo "                overwritten"
#	echo " With parameter -o <target> output can be re- "
#	echo " directed from stdout to <target> file."
	echo "------------------------------------------------"

	exit 0
}

###############################
###############################
#
# Initial configuration of script behaviour
#
##############################
##############################

while getopts "o:h" OPTIONS
do
	case $OPTIONS in
	o)
	TARGETFILE=$OPTARG
	OUTPUTTOFILE=1;;
	h)
	helptext;;
	esac
done

typeset -i OUTPUTTOFILE
if  (( OUTPUTTOFILE == 1 ))
then
	if [ -f "$TARGETFILE"  ]
	then 
		> $TARGETFILE
	fi
	exec 1>$TARGETFILE
fi



#echo $OUTPUTTOFILE 
#echo $TARGETFILE


#echo $COUNTER

######################
######################
#
# Detection available network devices
#
#####################
#####################



NWDEVICES=""
NWDEVICENUMBERS=""
STRING=""

#NWDEVICES=$( hwinfo --network | grep SysFS | awk -F' ' '{print $3}' | awk -F'/' '{print $4}' )
#NWDEVICENUMBER=$( echo $NWDEVICES | awk -F' ' '{print NF}' )

NWDEVICES=$( ls /sys/class/net/ | awk '{print $0}' )
NWDEVICENUMBER=$( ls /sys/class/net/ | wc -l )

typeset -i i
for  ((  i = 1 ; i <= NWDEVICENUMBER; i++ ))
do
	STRING=$( echo $NWDEVICES | awk -F' ' '{print '\$$i'}')
	if [ "$STRING" != "lo"  ] 
	then
		DEVICEARRAY[$i]=$STRING
		echo ${DEVICEARRAY[$i]}
	k=$i
	STRING=""
	fi
done 
#echo 
NWDEVICENUMBER=$k


