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

if [ $1 ]; then
   #remove the output file, if an old one exists   
   if [ -f /tmp/snmp/$1 ]; then
      rm -f /tmp/snmp/$1
   fi   

   # check if seeprom device is loaded
   temp=`ls -l /tmp | grep seeprom`
   if [ ! "$temp" ]; 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/nvram.bin ]; then
      cp /tmp/seeprom /tmp/nvram.bin
   fi

   # Call nvram_rw program to read NVRAM and output value
   /IBM/bin/nvram_rw -nolabel -I/tmp/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
   temp=`wc -c /tmp/snmp/$1 | grep " 0 "`
   if [ "$temp" ]; then
      echo "Error" > /tmp/snmp/$1
   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