#!/bin/sh
#############################################################################
# Name: /IBM/bin/readNvram <parm-id>
# Purpose: Utility to read NVRAM parms for SNMP or other use
#          client subagent
# Input: parm id # <id>
# Output: This will write the value of the parmeter in file /tmp/snmp/<id>
#         without any labels
# If error, look at log in file /tmp/snmp/r.err.$1
#############################################################################

PATH=$PATH:/configs:/local

if [ $1 ]; then

if [ -f /configs/nvram_settings ]; then  
 # we have a nvram_settings file, so we're new mode.  
 # bypass all that extra stuff.
	
 /local/nvram_rw -nolabel -r$1 -BDIT/configs/nvram_settings -OT/tmp/snmp/$1
#  /local/nvram_rw -nolabel -r$1 -BDIT/configs/nvram_settings -OT/scratch/snmp/$1

else

   # check if seeprom device is loaded
  if [ ! -e /dev/seeprom ]; then
      echo "readNvram ERROR: seeprom device driver is not loaded" >> /tmp/snmp/r.err.$1
      exit 1
   fi
 
   # if nvram file is not present, create one
   if [ ! -f /tmp/snmp/nvram.bin ]; then
      cp /tmp/snmp/seeprom /tmp/snmp/nvram.bin
   fi

   # Call nvram_rw program to read NVRAM and output value
   /IBM/bin/nvram_rw -nolabel -I/tmp/snmp/nvram.bin -r$1 -OT/tmp/snmp/$1

   # check for valid data - if output file has no data (0 bytes) there
   # is no valid data available
   if [ ! -e /tmp/snmp/$1 ]; then
      echo "Error" > /tmp/snmp/$1
   fi 
fi

else

  echo "readNvram ERROR: No id specified"
  echo "  Usage: readNvram <id>, where id is valid id # specified in nvID.h"
  echo "         The value is printed in /tmp/snmp/<id>"
  echo "         If id = 0, it will print all the parmeters to the file"
  echo "  Any read error will be logged in /tmp/snmp/r.err.<id> file"

fi
