#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 11.4 $ generated on Tue Oct 26 13:07:19 EDT 1999
#
# (c)Copyright 1983-1999 Hewlett-Packard Co.,  All Rights Reserved.
#
#------------------------------------------------------------------#
# SD checkremove script template for 11.X patches.                 #
#------------------------------------------------------------------#
# This file is optional for all 11.X patches.  The purpose of this #
# script is to ensure that there is no patch specific restriction  #
# to removing the selected software from the target system.        #
#------------------------------------------------------------------#

_PATCHID=PHKL_20169

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

# START OF INSERTED PATCH CODE

# This section is intended to prevent the installation of the HP-UX
# bootstrap - hpux(1M) on a system with a machine identification
# number of zero and a LVM boot disk.  The system should always have
# a valid machine identification number before installing hpux(1M)
# on a LVM boot disk.

# To prevent the installation, a check is made to see if the machine
# identification number is zero and the system has a LVM boot disk.

MONGOOSE_DEBUG="y"
MONGOOSE_DEBUG=""

#
########
# is_zero
#
# Returns 0 if the argument string is zero and 1 otherwise.
# NOTE:  the null string is considered to be numeric zero.
#
is_zero()
{
    typeset str="$@"
#   Is the string NULL?
    [[ -z $str ]] && return 0   # Yes, the string is NULL.
    echo $str | awk '
    {
        sub("0*", "", $0)       # If $0 is all zeros, set $0 to NULL
        if ($0 == NULL) {       # If $0 is NULL, return 0 indicating
                exit 0          # the value tested was all zeros or NULL.
        } else {                # If $0 is not NULL, return 1 indicating
                exit 1          # the value tested was not all zeros or NULL.
        }
    }'
    return $?
}
#
# This section of code is intended to prevent the execution
# of 11.X commands using a non 11.X kernel by just returning
# a zero, so it looks like the patch is installed, even 
# thought the patch is not install.
#
# The problem happens during an update, where the new commands
# have been installed, but the kernel has not been updated.
# The lvlnboot(1M) command fails in this situation.
#

RELEASE_IS=`uname -r`

case ${RELEASE_IS} in
	B.11.*)
		;;	# Continue, this is "B.11.*".
	*)
		return 0
		;;	# Do not continue, this is not "B.11.*".
esac

# Does the bootconf file exist?

BOOTCONF=${SW_ROOT_DIRECTORY}stand/bootconf
if [ ! -f $BOOTCONF ]
then
    if [[ -n $MONGOOSE_DEBUG ]]
    then
        echo "ERROR:   Cannot find the file $BOOTCONF."
    fi
    exit $FAILURE
fi

# Determine if the machine identification number is zero.

TEMP=`uname -i`
is_zero "$TEMP"
STATUS=$?
if [[ $STATUS -eq 0 ]]
then

# Search the bootconf file for LVM boot disks entries.
# The entries should be specified by a l, p or w and be followed
# by a space and the device file path.
# e.g.
#
# l /dev/dsk/c0t2d0
# p /dev/dsk/c0t4d0
# w /dev/dsk/c0t6d0
#
# All other entries are ignored.
#
#   Determine if the system has a LVM boot disk.
#

#   Open the bootconf file.

    exec 9<${BOOTCONF}

    while ( true )
    do
        read -u9 OPERATION BOOTDEV JUNK
        READ_STATUS=$?
        if [[ ${READ_STATUS} != 0 ]]
        then # If the status is non zero, assume end of file and quit searching.
            break
        fi
        case ${OPERATION} in
            l)
                echo "ERROR:   An attempt to update hpux(1M) on a system \c"
                echo "         with a serial number of zero."
                echo "         Please correct the problem an try again."
                exitval=$GLOBAL_ERROR
                break
                ;;
            *)
                break   #       Do nothing.
                ;;
            esac
    done
fi

# END OF INSERTED PATCH CODE

exit $exitval
