#!/bin/ksh
#
# ident "@(#)check_clock_defect 1.3     04/12/17 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# The purpose of this script is to use prtfru to read
# the Sun_Part_No and the Sun_Serial_no from the board
# and then compare these to a list of these in the file,
# boards_to_upgrade. If there is a match, then echo
# "needs upgrading"
#

DATA_DIR=`dirname $0`
if [ -z ${DATA_DIR} ] ; then
	DATA_FILE=./boards_to_upgrade
else
	DATA_FILE=${DATA_DIR}/boards_to_upgrade
fi

SUN_PART_NO=`prtfru | grep Sun_Part_No: | nawk ' { print $2 } '`
SUN_SERIAL_NO=`prtfru | grep Sun_Serial_No: | nawk ' { print $2 } '`

#
# ALREADY_HAS_UPDATE = 0 means that it already has the OBP fix applied.
#

prtconf -V | grep 1.0.20 >/dev/null 2>&1
ALREADY_HAS_UPDATE=$?

# Bail if either of these is blank

if [ x${SUN_PART_NO} = x ] || [ x${SUN_SERIAL_NO} = x ]; then
	echo "Can't determine Sun_Serial_No"
	exit 0
fi

while read bad_sun_part_no bad_sun_serial_no ; do
    if [ ${SUN_PART_NO} = ${bad_sun_part_no} ] ; then
	if [ ${SUN_SERIAL_NO} = ${bad_sun_serial_no} ] && [ ${ALREADY_HAS_UPDATE} -eq 1 ] ; then
	    echo "board ${SUN_SERIAL_NO} has clock defect and needs OPB patch"
	    exit 0
	else
	    continue
	fi
    else
	continue
    fi
done < ${DATA_FILE}

echo "board ${SUN_SERIAL_NO} does not have clock defect and does not need OBP patch"
exit 0


