#!/bin/sh
#
#
#    Copyright (c) 1996-2000 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   diagesdports
#    Module name: diag/scripts
#
#    This file implements the diagesdports command.
#
# NAME
#      diagesdports - set ESD skip ports list
# 
# SYNOPSIS
#      diagesdports [ itemlist | -show ]
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This  command sets the ESD idle port list. The list is saved
#      in flash memory and stays in that mode until the next execu-
#      tion of diagesdports.
# 
#      The  ESD  idle  ports  are used by several of the functional
#      test methods to disable testing on  the  specified  list  of
#      ports  when ESD mode is enabled (diagsetesdmode).  The exact
#      type of port list and the exact use of this list are  deter-
#      mined  by each test method.  The mode becomes active as soon
#      as this command is executed.  It does not require  a  reboot
#      to take effect.
# 
# OPTIONS
#      itemlist  Specify  the  range of ports to be set to ESD idle
#                port list. For proper syntax,  see  itemlist  help
#                page.
# 
#      -show     If  specified  or no itemlist is given,the current
#                ESD idle port list will be displayed.
# 
# EXAMPLES
#      > diagesdports -show
#      ESD Idle Port list is 1-8.
# 
# SEE ALSO
#      diagsetesdmode(1d), itemlist(1d)
# 
home="/fabos/share"
util="diagcommon.sh"
ok=0
for f in "./$util" "$FABOSHOME/share/$util" "$home/$util" ; do
	if [ -r $f ] ; then
		. $f
		ok=1
		break;
	fi
done
if [ $ok -ne 1 ] ; then
	echo "Error -- could not locate $util"
	exit 3
fi


#
# Program customization
#

config_string="diag.ports"	   # config string to update
config_name="ESD Idle Port list"   # User name of config.
config_default="-none-"		   # default value
config_mode=$STRING		   # config mode
syntax="`/bin/basename $0` [ itemlist ]" ; export syntax

#
# diagesdports()
#

checkForShow "$config_name" "$config_string" "$config_mode" "$config_default" "$1"

s=`/usr/bin/expr "$1" : "[-]*\([-, /, 0-9]\+\)"`
if { [ -z "$s" ] || [ $s != $1 ] ; } ; then
	err "Input is not a valid port list: $1"
	exit 3
fi


cur_val=`getConfig $config_string $config_mode $config_default`
if [ "$cur_val" != "$s" ]
then
	setConfig $config_string $config_mode $s
	echo "$config_name is now $s."
	updateConfig
else
	echo "$config_name is still $s."
fi
exit 0
