#!/bin/sh
#
#
#    Copyright (c) 1996-2000 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#
# NAME
#      diagmodepr - set or display diagnostic print mode
# 
# SYNOPSIS
#      diagmodepr [ mode | -show ]
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This  command  enables  print mode if mode is non-zero value
#      and  disables print mode if mode is 0.  The mode is saved in
#      flash memory and stays in that mode until the next execution
#      of diagmodepr. The mode becomes active as soon as this  com-
#      mand  is  executed.  It  does  not  require a reboot to take
#      effect.
# 
#      Print mode when enabled will cause extra messages to be dis-
#      played  in  the burnin and POST(Power-on Self-Test) scripts.
#      The exact behavior depends on the script being run.
# 
# OPTIONS
#      mode      Specify print mode value. 0 means to disable print
#                mode, any other value will enable print mode.
# 
#      -show     If  specified  or  no  mode  is given, the current
#                print mode will be displayed.
# 
# EXAMPLES
#      > diagmodepr -show
#      Diagnostic Print Mode is currently disabled.
# 

#
#
# Load library -- must be first.
#
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.mode.disPr"	# config string to update
config_default=0		# default value
config_mode=$INTEGER		# config mode

syntax="`/bin/basename $0` [ mode \| -show ]" ; export syntax

show_mode=`/usr/bin/expr "$1" : "[-]*show"`
if { [ -z "$1" ] || [ "0" -ne "$show_mode" ] ; } ; then

	#
	# without option or -show option
	#
	current_value=`getConfig $config_string $config_mode $config_default`
	if [ $? != 0 ] ; then exit 3 ; fi

	if [ "$current_value" -eq "0" ] ; then
		echo "Diagnostic Print Mode is currently enabled."
	else
		echo "Diagnostic Print Mode is currently disabled."
	fi
else

	#
	# specified with any value except "-show"
	#
	value=`getValue $1`

	if [ $? != 0 ] ; then exit 3 ; fi

	#
	# (Caution)
	# use "set_value" in comparison
	# if the value is not 0, it means "Enable Print Mode", in other words
	#     "Set diag.mode.disPr to 0" : set_value = 0
	# if the value is 0, it means "Disable Print Mode", in other words
	#     "Set diag.mode.disPr to 1" : set_value = 1
	#
	if [ "$value" -eq  "0" ] ; then
		set_value=1
	else
		set_value=0
	fi

	current_value=`getConfig $config_string $config_mode $config_default`
	if [ "$current_value" != "$set_value" ]
	then
		setConfig $config_string $config_mode $set_value
		updateConfig
		if [ $? != 0 ] ; then exit 3 ; fi

		if [ "$set_value" -eq "0" ] ; then
			echo "Diagnostic Print Mode is now enabled."
		else
			echo "Diagnostic Print Mode is now disabled."
		fi
	else
		if [ "$set_value" -eq "0" ] ; then
			echo "Diagnostic Print Mode is enabled. (Unchanged)"
		else
			echo "Diagnostic Print Mode is disabled.(Unchanged)"
		fi
	fi
fi

exit 0
