#!/bin/sh
#
#    Copyright (c) 1996-2000 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#
# NAME
#      diagsetcycle - set diagnostic script parameters
# 
# SYNOPSIS
#      diagsetcycle  script  [  -show | -default | [ -keyword value
#      ... ]]
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This command provides interactive way of updating diagnostic
#      command parameters. With only script specified, it will dis-
#      play all  configuration  variables  used  by  the  specified
#      script  and  go  into an interactive session. Using the full
#      stretched option parameters, variables can be  updated  non-
#      interactively too.
# 
#      In  interactive  mode, the current value, default value, and
#      description of purpose of the  variable  are  displayed  for
#      each  variable.  If no new value is specified, then the cur-
#      rent value is left unchanged. If a  new  value  is  entered,
#      then  its  value is updated, and stored in the configuration
#      database for that blade type. It does not require  a  reboot
#      to take effect.
# 
# OPTIONS
#      script    Specify which script's prameters to edit.
# 
#      -show     It  will  display  the parameters for a diagnostic
#                script specified by script.
# 
#      -default  The script parameters will be set to default  val-
#                ues.
# 
#      -keyword value
#                The  script parameters can be updated non-interac-
#                tively using this style of option list. keyword is
#                the  keyword  to  update  and  the value should be
#                specified manually in this case.
# 
# EXAMPLES
#      > diagsetcycle switchburnin.sh -show
#      CURRENT - KEYWORD        : DEFAULT
#       1      - number_of_runs : 1
#       2      - vib            : 2
#       10     - thermal        : 10
#       BURNIN - label          : BURNIN
#       1      - tbr_passes     : 1
#       1      - prt_on         : 1
#       1      - cntmem_on      : 1
#       1      - cmi_on         : 1
#       1      - retention_on   : 1
#       1      - cam_on         : 1
#       50     - flt_passes     : 50
#       25     - sta_passes     : 25
#       100    - plb_nframes    : 100
#       50     - txd_nframes    : 50
#       200    - xpt_nframes    : 200
#       20     - bpt_nframes    : 20
#       50     - slk_nmegs      : 50
#       30     - bpt_all_nframes: 30
#       50     - slk_all_nmegs  : 50
# 
# SEE ALSO
#      burninname(1d), burninlevel(1d), burninscript(1d),  diagset-
#      burnin(1d), diagstopburnin(1d)
# 

if [ ! $?FABOSHOME ]
then
	export FABOSHOME=/fabos
fi
home="/fabos/share"
util="diagcommon.sh"
export syntax="`/bin/basename $0` script [ -show \| -key [ value \| -default ] ... ]"
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
	err "Could not locate $util"
	exit 3
fi
arg=""
script=""
if [ $# -gt 0 ]
then
	# check for a "-" character	
	if [ -z `/bin/echo $1 | /bin/sed "s/^-/@/g" | /bin/grep @` ]
	then
		script="$1"
		shift
	fi
	arg="$*"
fi

if [ -z "$script" ]
then
  /bin/echo "Syntax: diagSetCycle <script_name> [ -show | -default | <-keyword value>.. ]"
  /bin/echo "  -show            Outputs the values of the variables (No editing)"
  /bin/echo "  -default         Sets the values to the default value"
  /bin/echo "  -keyword value   Sets the value of a specific keyword (-number_of_runs 3)"
  /bin/echo "Please specify what diag cycles to set."
  _num_choice=`getNumAvailableScripts DIAGSETCYCLE_CAPABLE -noconfig`
  _answer=-1
  while [  $_answer -lt 0 -o $_answer -gt $_num_choice ]
  do
    /bin/echo "Choices are:"
    showAvailableScripts DIAGSETCYCLE -noconfig
    /bin/echo "Make selection (0-$_num_choice)"
    read _answer
    if [ ! -z "$_answer" ]
    then
	valid=`validate_integer $_answer 0 $_num_choice`
	if [ "$valid" != "TRUE" ]
	then
	    /bin/echo "Invalid selection. valid selection are between 0 and $_num_choice"
	    /bin/echo " Please make another selection"
	    _answer=-1
	else
	    if [ $_answer -eq 0 ]
	    then
		exit 1
	    fi
	    script=`getScriptSelection $_answer DIAGSETCYCLE -noconfig`
	    /bin/echo script selection: $script
	fi
    else
	_answer=-1
    fi
  done
fi
#
# If a file is specified, then call that file with the parameter "diagsetcycle"
#
ok=0
for f in "$script" "./$script" "$FABOSHOME/share/$script" "$home/$script" ; do
  if [ -r $f ]
  then
    $f diagsetcycle $arg
    ok=1
    break;
  fi
done
if [ $ok -eq 0 ]
then
	echo "diagSetCycle: Could not find $script"
	exit 1
fi
exit 0
