#!/bin/sh
#
#
#    Copyright (c) 1996-2005 Brocade Communications Systems, Inc.
#    All rights reserved.
#
# NAME
#      diagpost - set or display diagnostic POST configuration
# 
# SYNOPSIS
#      diagpost [ mode | -show ]
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This  command enables POST(Power-On Self-Test) if mode value
#      is non-zero and disables POST if mode value is 0.  The  mode
#      is  saved  in  flash memory and stays in that mode until the
#      next  execution  of  either  diagpost,  diagenablepost   and
#      diagdisablepost.   The  mode  becomes active as soon as this
#      command is executed.  It does not require a reboot  to  take
#      effect.
# 
#      POST  mode  modifies  the behavior of the diagnostics daemon
#      program to inhibit testing of switch blades when the  system
#      is first powered on or a new blade is added.
# 
# OPTIONS
#      mode      Specify  diagnostic  POST setting. 0 means disable
#                POST, any other value will enable POST.
# 
#      -show     If specified or no mode is given, the current POST
#                setting will be displayed.
# 
# EXAMPLES
#      > diagpost -show
#      Diagnostic POST is currently enabled.
# 
# SEE ALSO
#      diagdisablepost(1d), diagenablepost(1d)
# 
# NOTES
#      To  enable  or disable diagnostic POST, it is recommended to
#      use diagenablepost and diagdisablepost.
# 

#
# Load library -- must be first.
#
print_usage()
{
    echo " diagpost [ mode | -show ]"
}

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

#Parameter Validation
if [ $# -gt 1 ] ; then
/bin/echo "  Invalid arguments"
print_usage;
exit 0
elif [ $# == 1 ] && [ "$1" != -enable ] && [ "$1" != -disable ] && [ "$1" != -show ] && [ "$1" != 1 ] && [ "$1" != 0 ] ; then
/bin/echo "  Invalid arguments"
print_usage;
exit 0
fi

#
# Program customization
#
config_string="diag.postDisable"	# config string to update
config_default=0			# default value
config_mode=$INTEGER			# config mode

# Syntax
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 POST is currently enabled."
	else
		echo "Diagnostic POST 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 Post", in other words
	#     "Set diag.postDisable to 0" : set_value = 0
	# if the value is 0, it means "Disable Post", in other words
	#     "Set diag.postDisable 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 POST is now enabled."
		else
			echo "Diagnostic POST is now disabled."
		fi
	else
		if [ "$set_value" -eq "0" ] ; then
			echo "Diagnostic POST is enabled. (Unchanged)"
		else
			echo "Diagnostic POST is disabled.(Unchanged)"
		fi
	fi
fi

exit 0







