#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 9.5 $ generated on Tue Jun 22 09:40:01 PDT 1999
#
# (c)Copyright 1983-1996 Hewlett-Packard Co.,  All Rights Reserved.
#
#------------------------------------------------------------------#
# SD checkinstall script template for 11.X patches.                #
#------------------------------------------------------------------#
# This file is optional for all 11.X patches.  The purpose of this #
# script is to ensure that the target system has no patch specific #
# conditions which would cause either an installation failure or a #
# runtime failure.  There must be no side effects from running     #
# this script, since it is run before there is any commitment to   #
# installation.                                                    #
#------------------------------------------------------------------#

_PATCHID=PHKL_18543

UTILS="/usr/lbin/sw/control_utils"

if [ ! -f $UTILS ]; then
    echo "ERROR:   Cannot find $UTILS"
    exit 1
fi

. $UTILS
exitval=$SUCCESS

#####
##### Insert any code you may require at this point in the script.
##### Pay attention to the exitval variable and set appropriately
##### in your code.  If you are unsure as to what types of operations
##### are legal in this file and what types aren't, consult the 
##### "Guidelines for SD Control Scripts" document.
#####
##### START_CUSTOMIZATION_HERE

########
# get_revision_state
#
# Print a word that corresponds to a given fileset's install state.
#       $1      :  Software to test:  PRODUCT.FILESET
#       revision:  OS release (i.e. B.10.20, B.11.00)
#       state   :  installed or configured
#
# This function is essentially the get_install_state function from 
# control_utils.  However, that function does not get revision data.
#
get_revision_state ()
{
    typeset prod_fs=${1%%,*}
    typeset revision=""
    typeset state=""

    # SD's debugging output messes up parsing, so unset it for this function.
    if [[ -n $SDU_DEBUG ]]
    then
	typeset SDU_DEBUG_SAVED=$SDU_DEBUG
	unset SDU_DEBUG
    fi

    set -- $(/usr/sbin/swlist -l fileset -a state -a revision $prod_fs 2>/dev/null | sed '/^#/d')
    while [[ $1 != $prod_fs && $# -gt 1 ]]
    do
        shift
    done

    if [[ $1 = $prod_fs ]]
    then
	revision=$2
        state=$3
    fi

    echo "$revision $state"

    if [[ -n $SDU_DEBUG_SAVED ]]
    then
	SDU_DEBUG=$SDU_DEBUG_SAVED
    fi
} # end  get_revision_state

# START Check for 11.X patch mismatch                              #
#------------------------------------------------------------------#
Filesets="
AdvJournalFS.VXFS-ADV-KRN
JournalFS.VXFS-BASE-KRN
JournalFS.VXFS-PRG
OS-Core.CORE-KRN
OS-Core.CORE2-KRN
OS-Core.KERN2-RUN
ProgSupport.C-INC
"

#########################################################################
# This script part is to replace the whole custom part of the script with
# another patch if needed.  At initial patch release time there is no 
# basepatch_utils file
#

BASEPATCH_UTILS="$SW_ROOT_DIRECTORY/usr/lbin/patch/basepatch_utils"

if [ -f $BASEPATCH_UTILS ] 
then
    # replace with a fixed version if needed
    print -u2 "NOTE:    $BASEPATCH_UTILS installed."
    print -u2 "         Using control script functions from this file."
    . $BASEPATCH_UTILS
    checkinstall_cntl || exitval=$? # retain a non-zero return value
    exit $exitval
fi # [ -f  ]

for Fileset in $Filesets
do
  fstate=$(get_install_state $Fileset)
  is_software_selected $Fileset; fselected=$?
  if [ "$fstate" = configured -o "$fstate" = installed -o $fselected -eq 0 ]
  then
    Fset=${Fileset#*.}
    PFset=$_PATCHID.$Fset
    pstate=$(get_install_state $PFset)
    is_software_selected $PFset; pselected=$?
    if [ "$pstate" != configured -a "$pstate" != installed -a $pselected -ne 0 ]
    then
	# At this point, we believe the product.fileset is installed, but
	# the patch.fileset is not currently selected for install.  There
	# is one case where this is ok: if we are updating from an earlier
	# release (i.e. 10.20) and this product was installed at that time.
	# If the product is ISU, it must be installed after the core bits.

	get_revision_state $Fileset | read frevision fstate
	if [[ $frevision != "B.11.00" ]]
	then
	  # Allow ommision of this Fileset, but issue a helpful warning to
	  # the user.

        print -u2 "WARNING: The ${frevision#*.} version of the \"${Fileset%.*}\" product is currently"
        print -u2 "         installed.  This patch is not compatible with that product"
        print -u2 "         version.  After you install the 11.00 version of\"${Fileset%.*}\","
        print -u2 "         you must again install this patch, $_PATCHID.  (The reinstall*"
        print -u2 "         options must be set to false - the default.)  Failure to do so"
        print -u2 "         may leave the OS in an unstable state."

        if [ $exitval -ne $FAILURE ]
        then
          exitval=$WARNING
        fi
      else
        # Do not allow this fileset to be omitted, as it would split the
        # patch.

        print -u2 "ERROR:   Fileset \"$Fileset\" is currently installed or selected"
        print -u2 "         for installation, but patch fileset \"$PFset\" is"
        print -u2 "         not currently installed or selected for installation.  This"
        print -u2 "         indicates that all the applicable components of $_PATCHID"
        print -u2 "         are not being installed.  You must install using the"
        print -u2 "         patch_match_target option of swinstall(1M), which will insure"
        print -u2 "         all the appropriate patch components are installed."

        exitval=$FAILURE
      fi #[[ $frevision != "B.11.00" ]]
    fi
  fi
done

if [ $exitval -eq $FAILURE ]
then
  print -u2 "NOTE:    If you are currently running swinstall interactively, and"
  print -u2 "         $_PATCHID is not currently marked for installation, you may"
  print -u2 "         mark it now and rerun the analysis phase."
fi

#------------------------------------------------------------------#
# DONE with Check for 11.X patch mismatch


exit $exitval
