#! /sbin/sh
###############
# Product: OS-CORE
# Fileset: CORE-KRN
# verify
# @(#) $Revision: 1.2.98.1 $
################
#
# (c) Copyright Hewlett-Packard Company, 1994
#
########################################################################
#                                                                      #
# Compare release as reported by uname to the fileset we are verifying.#
#                                                                      #
########################################################################

# The global variables SUCCESS, FAILURE, WARNING, EXCLUDE, PATH, ROOT,
# SW_CTL_SCRIPT_NAME, _pf, PRODUCT, and FILESET are all set by control_utils.

UTILS=/usr/lbin/sw/control_utils
if [[ ! -f $UTILS ]]
then
  print "ERROR:   Cannot find the sh functions library $UTILS."
  exit 1
fi
. $UTILS


running="$(/usr/bin/uname -r)"
if [[ -z "$running" ]]
then
  print "ERROR:   The uname command failed, could not determine release string."
  exit $FAILURE
fi

revision="$(swlist -a revision -l product $PRODUCT 2>/dev/null | \
		/usr/bin/awk -v prod=$PRODUCT 'prod == $1 {print $2}' )"
if [[ -z "$revision" ]]
then
  print "ERROR:   The swlist or awk commands failed, could not determine"
  print "         product revision."
  exit $FAILURE
fi

## Check for pre-release software

if [[ "$revision" = +(*.%*) ]]
then
  print "NOTE:    You are running pre-release software!"
fi

        # Just use first 7 characters as release number
while [[ ${#revision} -gt 7 ]]
do
  revision="${revision%.*}"
done
shouldbe="${revision}"

if [[ "$running" != "$shouldbe" ]]
then
  print "WARNING: Running system is release ${running}, instead of"
  print "         ${shouldbe}.  $FILESET fileset is not properly installed."
  exit $WARNING
fi

exit $SUCCESS
