#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 17.3 $ generated on Mon Jun 25 13:50:05 PDT 2001
#
# (c)Copyright 1983-2001 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=PHCO_24437


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

#
# Message variables
#

MILDNOTE="NOTE:    The patch, $_PATCHID, will install correctly on your current system 
         configuration; however, if you ever choose to install the product
         B2491BA, \"MirrorDisk/UX\", you will need to reinstall this patch 
         after installing the optional product. You can do that by reusing 
         your current media (or depot) after installing from the application 
         media, or by searching HP's patch hub."

MILDWARNING="WARNING: The patch, $_PATCHID, affects both Core HP-UX and the optional product
         B2491BA, \"MirrorDisk/UX\". If you are installing the mirrored disks 
         product after completing the cold install, you must install this patch
         again after installing the optional product. You can do that by 
         reusing your current media (or depot) after installing from the 
         application media, or by searching HP's patch hub."

STRONGWARNING="WARNING: The patch, $_PATCHID, will only update your core LVM software, and 
         not the disk mirroring product B2491BA, \"MirrorDisk/UX\". After you
         have installed the 11.X version of the mirroring software from the 
         application media, you MUST re-install this patch. You can do this
         by reusing your current media (or depot) or by searching HP's patch 
         hub."

# START Check for 11.X patch mismatch                              #
#------------------------------------------------------------------#
Fileset=LVM.LVM-MIRROR-RUN

get_revision_state $Fileset | read fs_revision fs_state
is_software_selected $Fileset; fs_selected=$?

if [[ $fs_selected -eq 0 ]]		# if we're installing LVM mirroring right now,
then
   exit $SUCCESS			# everything is good, exit.
fi

if [[ $SW_INITIAL_INSTALL -eq 1 ]]	# Cold install, we don't know if they're getting mirrors
then
   # print -u2 "$MILDWARNING"		# Print a WARNING telling steps if they install mirrors
   # exit $WARNING			# Pause installation to make sure they read it

   print -u2 "$MILDNOTE"		# print the NOTE telling steps if they install mirrors
   exit $SUCCESS			# Don't pause because most customers shouldn't be 
					# "penalized".
fi


if [ "$fs_state" = configured -o "$fs_state" = installed ]
then
   if [[ "$fs_revision" = "B.11.00" ]]	# They have the 11.X fileset
   then
       exit $SUCCESS			# No problems - exit
   fi
fi

if [  "$fs_state" != configured -a "$fs_state" != installed ]
then					# Don't have LVM-MIRROR now and not installing it now
   print -u2 "$MILDNOTE"		# Stick a message in the log in case they buy mirrors later
   exit $SUCCESS			# Not enough risk to hassle the customer
fi

if [ "$fs_state" = configured -o "$fs_state" = installed ]
then
    if [ "$fs_revision" != "B.11.00" ]
    then					# Have a pre-11.00 version of LVM-MIRROR 
					# This should be the last possible case.
        print -u2 "$STRONGWARNING"		# Inform customer they MUST reinstall patch.
        exit $WARNING			# Make _sure_ we get the customer's attention
    fi
fi

# You should never get here.

print -u2 "WARNING: Cannot determine the current state of LVM and disk mirroring (B2491BA,
         \"MirrorDisk/UX\" software."
print -u2 "$STRONGWARNING"
exit $WARNING

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


