#!/bin/sh
#
# This script checks if ME10 Rev. 04.20 Series 300/400 can be run under the 
# current HP-UX. If HP-UX 8.0 is installed the following files are checked
# for correct what-strings:
#
#    /dev/kmem
#    /usr/lib/libsb.sl
#    /usr/bin/pcltrans
#
# This script MUST be run as root user
#

###############################################################################
#
# uxtest() - test the what-strings of given files
#
# $1 filename
# $2 grep string for line selection
# $3 correct what-string
#
###############################################################################
uxtest()
{
    filename=$1
    grepstr=$2
    whatstr=$3
    if  [ -r $filename ]   
    then
        ver="`/usr/bin/what $filename | /bin/grep $grepstr `"
        if [ "$ver" != "$whatstr" ]  
        then
	    echo
	    echo "WARNING:            $filename"
	    echo "Expected Revision:  $whatstr"         
	    echo "Installed Revision: $ver"
	    warning=1
        fi
    else
	echo
        echo "\007ERROR: can't read file $filename"
	echo
        exit 1
    fi
}

###############################################################################
#
# AMIROOT() - test whether the script is run as root user
#
###############################################################################
AMIROOT ()
{
    if [ "`whoami`" != "root" ]
    then
        echo
        echo "\007ERROR: You must be the root user to run this script!"
        echo
        exit 1
    fi
}


###############################################################################
#
# test_files() - calls for each file uxtest()
#
###############################################################################
test_files()
{
    uxtest "/dev/kmem" \
           "kern_exec.o" \
           "	 8.0PCO 910904: kern_exec.o 1.85.51.2"
    uxtest "/usr/lib/libsb.sl" \
           "401.1" \
           "	 M68K_8.0 910326 libsb2.a \$Revision: 401.1.1.2.1.1 \$"
    uxtest "/usr/bin/pcltrans" \
           "401.1.1.1.1.2" \
           "	\$Revision: 401.1.1.1.1.2 \$   \$Date: 91/09/03 13:43:09 \$ pcltrans"
    uxtest "/usr/bin/pcltrans" \
           "401.1.1.2.1.1" \
           "	\$Revision: 401.1.1.2.1.1 \$   \$Date: 91/09/03 11:30:54 \$ libfmtpcl.a"
}

###############################################################################
#
# MAIN
#
# This script tests whether you have installed at least HP-UX 8.0
# to run ME10 Rev. 04.20 Series 300/400.
#
###############################################################################
warning=0
osrev=`/bin/uname -r | /usr/bin/tr 'ABC.' '    ' \
		     | /usr/bin/awk '{print $(NF-1)"."$NF}' \
		     | /usr/bin/awk '{printf("%1.0f", 100*$1)}'`
mach=`/bin/uname -m | /usr/bin/tr '"/[A-Z][a-z]"' '" [0*][0*]"' | /usr/bin/awk '{print $NF}'`
if [ \( $mach -lt 300 \) -o \( $mach -gt 499 \) ]
then
    echo
    echo "\007This script is only for Series 300/400"
    echo
    exit 1
fi
if [ $osrev -lt 800 ]
then
    echo
    echo "\007ERROR: You must upgrade to HP-UX Rev. 8.0 or later to run ME10 Rev. 04.20!" 
    echo
    exit 1
fi
if [ $osrev -eq 800 ]
then
    AMIROOT
    test_files
fi
if [ $warning -eq 0 ]
then
    echo 
    echo "ME10 Rev. 04.20 is supported with your current HP-UX Revision"
    echo 
else
    echo 
    echo "\007WARNING: ME10 Rev. 04.20 should not be run with your current HP-UX Revision."
    echo "Please contact HP for assistance"
    echo 
fi

