#!/bin/sh
#
#
#    Copyright (c) 1996-2000 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   burninserial
#    Module name: diag/scripts
#
#    This file implements the burninserial command.
#
# NAME
#      burninserial  -  set  or  display  the serial number for the
#      board in burnin
# 
# SYNOPSIS
#      burninserial [ serial | -show ] [ slotno ]
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This command sets or displays  the  serial  number  for  the
#      board being tested by a burnin script.  The script uses this
#      information to detect if a board has been  replaced  in  the
#      middle of the burnin cycle.  The mode becomes active as soon
#      as this command is executed.  It does not require  a  reboot
#      to take effect.
# 
# OPTIONS
#      serial    Specify  the  serial  number  of  the  board being
#                tested.
# 
#      -show     The current serial number will be displayed.
# 
#      slotno    Specify which slot to  update  or  show.  If  this
#                option  is  not specifed, the current slot will be
#                assumed. You can set the current slot by execution
#                of  setslot  command.  To  use this option, either
#                serial, -show should be specified before.
# 
# EXAMPLES
#      > burninserial -show 2
#      Slot 2 burnin serial number is 0.
# 
# SEE ALSO
#      setslot(1d)
# 
# NOTES
#      This command may be removed in future releases.
# 

#########################
# Temporarily disabling this command until the 
# implementation is needed by manufacturing.
#########################

echo "This manufacturing command is not supported at this time"
exit 0

def_slot=0

#
#
# 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

#
# Get slot number
#
x=`/usr/bin/expr "$2" : "\([0-9]\+\)"`
if  [ -z $x ] ; then
    ans="`isValidSlot $FABOS_SLOTNO`"
    if [ "$ans" = TRUE ] ; then
       slot=$FABOS_SLOTNO
    else
       slot=$def_slot
    fi   
else
     ans="`isValidSlot $x`"
     avail=`getAvailSlots`
     if [ "$ans" = TRUE ] ; then
        slot=$x
     else 
	 err "$x is an invalid slot number"
	 if [ $multiBlade = TRUE ] ; then
	       /bin/echo "Available slots are: $avail."
	 fi
	 exit 4
     fi     
fi



#
# Program customization
#

config_string="diag.mode.burnin.$slot.serial" # config string to update
if [ `isMultiBlade` = TRUE ]
then
    config_name="Slot $slot burnin serial number"	# User name of config.
else
    config_name="burnin serial number"	# User name of config.
fi
config_default=0		# default value
config_mode=$INTEGER		# config mode


#
# burninserial()
#
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 serial number  must be >= 0"
    exit 3
fi

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.
	updateConfig
else
	echo $config_name is still $val.
fi
exit 0
