#!/bin/sh
#
#
#    Copyright (c) 1996-2000 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#
# NAME
#      burninlevel - set the diagnostics burnin level
# 
# SYNOPSIS
#      burninlevel [ level | -show ]
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This command selects or displays the burnin level.  When the
#      burnin level is set to a value other than 0, the  diagnostic
#      daemon  program  will  perform  burnin  testing  in place of
#      POST(Power-On Self-Test) phase II each time a  switch  blade
#      is  powered on. The mode becomes active as soon as this com-
#      mand is executed so that it does not  require  a  reboot  to
#      take effect.
# 
#      When  a  burnin  level  other than 0 is selected, the actual
#      behavior is determined by the configuration of the  diagnos-
#      tics daemon and the burnin scripts that are run.
# 
# OPTIONS
#      level     The burnin level will be set to this value.
# 
#      -show     If  this  is specified, or level is not specified,
#                the current burnin  level  setting  will  be  dis-
#                played.
# 
# EXAMPLES
#      > burninlevel -show
#      Burnin level is 0.
# 
# SEE ALSO
#      burninname(1d),   diagdisablepost(1d),   diagenablepost(1d),
#      diagsetburnin(1d)
# 

#
# Load library -- must be first.
#
home="/fabos/share"
util="diagcommon.sh"
ok=0

# Check RBAC permission on command
/fabos/libexec/rbac_check `/bin/basename $0`

if [ $? -ne 0 ]; then
    exit 127
fi

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.mode.burnin.level" # config string to update
config_string2="diag.mode.burnin"      # config string to update
config_name="Burnin level"	# User name of config.
config_default=0		# default value
config_mode=$INTEGER		# config mode


#
#
# burninlevel()
#

checkForShow "$config_name" "$config_string" "$config_mode" "$config_default" $1
val=`getValue $1`
if [ $? != 0 ] ; then exit 3 ; fi

if [ $val -lt 0 ] ; then
	err "Burnin level must be >= 0"
	exit 3
fi

# set level
update_needed=FALSE
cur_val=`getConfig $config_string $config_mode $config_default`
if [ "$cur_val" != "$val" ]
then
	setConfig $config_string $config_mode $val
	echo $config_name is now $val.
	update_needed=TRUE
else
	echo $config_name is still $val.
fi
# set enable
if [ $val != 0 ] ; then
	val=1
fi
if [ "$val" = "1" ] ; then
	res=Enabled
else
	res=Disabled
fi
cur_val=`getConfig $config_string2 $config_mode $config_default`
if [ "$cur_val" != "$val" ]
then
	setConfig $config_string2 $config_mode $val
	echo Burnin mode is now $res.
	update_needed=TRUE
else
	echo Burnin mode is still $res.
fi
if [ "$update_needed" = "TRUE" ]
then
	updateConfig
fi

exit 0











