#!/sbin/sh
#
########
#  Product: Graphics
#  Graphics checkinstall
#  @(#) $Revision: 1.3 $
########
#
# (c) Copyright Hewlett-Packard Company, 2002
#
set -u
########
#  Source control_utils
# 

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

##############################################################################
#
# function _exit_code
# 	determines appropriate abnormal exit code:
#	returns: 	EXCLUDE if exclude functionality available
#			FAILURE otherwise
#
SD_EXCLUDE_PATCH=PHCO_21492

function _exit_code {

    #########################################################################
    # EXCLUDE functionality will be available if one of:
    #	- SW_SESSION_IS_UPDATE (OS updates to 11i) is defined
    #	- current OS is 11i or higher
    #	- $SD_EXCLUDE_PATCH or its successors is on the system
    #
    if (( ${#SW_SESSION_IS_UPDATE} )); then
	return $EXCLUDE
    fi

    ###

    _current_os=$(/usr/bin/uname -r)
    _current_os=${_current_os#*.} 
    if ( ! [[ X${_current_os} < X11.11 ]] ); then
	return $EXCLUDE
    fi

    ###

    $(/usr/sbin/swlist -l fileset -a supersedes @ $SW_ROOT_DIRECTORY \
			| /usr/bin/grep -q $SD_EXCLUDE_PATCH)
    if (( $? == 0 )); then
	return $EXCLUDE
    fi

    #########################################################################
    # EXCLUDE functionality not available
    #
    return $FAILURE

} # _exit_code


##############################################################################
#
# MAIN
#
# set up exit code
#
_exit_code
CPU_FAIL=$?

##############################################################################
# 
# determine if cold install or update
#

if [[ ${SW_INITIAL_INSTALL:-0} -eq 1 ]]        # cold install
then
    ###########################################################################
    # 
    # cold install
    # install only if 64 bit capable
    #
    CAN_RUN_64BIT=0
    if [[ -f $INST_CLIENT_DIR/host.info ]]
    then
        grep -qi  'can_run_64bit=FALSE' $INST_CLIENT_DIR/host.info
	CAN_RUN_64BIT=$?
    fi

    if [[ $CAN_RUN_64BIT -eq 0 ]]
    then
        echo "NOTE:    This product will not be installed because"
        echo "         it can not be determined if this system is"
        echo "         compatible with the software.  It requires a"
        echo "         processor that can execute PA-RISC version 2.0"
        echo "         object code."
        echo "         "
        echo "         If you need additional information about this"
        echo "         error message, contact your HP Country Response"
        echo "         Center or other HP-UX software support personnel."
        exit $CPU_FAIL
    fi

else
    ###########################################################################
    # 
    # update: check architecture
    #
    CPU_TYPE=`/usr/bin/getconf CPU_VERSION`
    if [ $CPU_TYPE -lt 532 ]
    then
        if [ $CPU_FAIL -eq $FAILURE ]
        then
            echo "ERROR:   This product will not be installed because it is"
        else
            echo "NOTE:    This product will not be installed because it is"
        fi
        echo "         incompatible with the microprocessor (CPU) on"
        echo "         the destination system.  It requires a"
        echo "         processor that can execute PA-RISC version 2.0"
        echo "         object code."
        echo "         "
        echo "         If you need additional information about this"
        echo "         error message, contact your HP Country Response"
        echo "         Center or other HP-UX software support personnel."
        exit $CPU_FAIL
    fi
fi
