#! /sbin/sh
###############################################################################
#  checkinstall for HPVM Prod
#  @(#) $Revision: 8370 $
###############################################################################
#
# (c) Copyright Hewlett-Packard Company 2005-2008
#


###############################################################################
# SD control utilities
###############################################################################

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

exitval=$SUCCESS

##########################################
# Check for HPVM Trial bundle first.
##########################################

PATH=$PATH:/usr/bin

isHPVMTrial_installed()
{
    swlist -l bundle 2>/dev/null | grep -Fq 'T2801AA'
    return $?
}

isHPVMTrial_installed; hpvmT_inst=$?

#########################################################
# If Trial bundle, T2801AA is installed, then fail.
#########################################################

if [[ $hpvmT_inst -eq 0 ]]
then

      msg "ERROR:   HPVM Trial software must be removed before installing the \
full version. "
      exit $FAILURE

fi
##########################################
# Check for the 11.31.0903 or greater SysMgmtMin on the current system, SysMgmtMin,r=B.11.31.0903
# Starting with V4.1, 0903 HP-UX is required.
##########################################


isBase_installed()
{
        Base_version=`swlist -l bundle SysMgmtMin 2>/dev/null | awk '/SysMgmtMin/ {print $2; exit}' 2>/dev/null`
        maj_release=`echo $Base_version | cut -d '.' -f 2`
        min_release=`echo $Base_version | cut -d '.' -f 3`
        dat_release=`echo $Base_version | cut -d '.' -f 4`
        OE_version="$maj_release$min_release$dat_release"

if [[ -z $OE_version ]]
then
        OE_version=-1
fi
#
# this check is for 11.31 0903 or later in the final version this
# check will be 11.31 0903 or later 11310903
if [[ $OE_version -ge 11310903 ]]
then
        return 1
else
        return 0
fi

}

#########################################################
# If 0903 or later HP-UX  is not installed, then fail,
# unless this is an update-ux or initial (cold) install
#########################################################

if [[ "${SW_SESSION_IS_UPDATE:-}" = "1" ]]
then
    hpvm_inst=1
elif [[ "${SW_INITIAL_INSTALL}"  = "1" ]]
then
    hpvm_inst=1
else
    isBase_installed; hpvm_inst=$?
fi

if [[ $hpvm_inst -ne 1 ]]
then

        msg "ERROR:   Bundle, SysMgmtMin,r=B.11.31.0903 or greater is required for HPVM to install."
        msg "         Please upgrade HPUX to version 0903 or later before continuing."
        exitval=$FAILURE

fi


###############################################################################
# Do not install on a virtual machine
###############################################################################

vm_model="Integrity Virtual Machine"
if [[ -x /usr/bin/model ]]
then
    is_vm=`/usr/bin/model | /usr/bin/grep -c "$vm_model" `
    if [[ $is_vm -gt 0 ]]
    then
        msg "ERROR:    Cannot install on a virtual machine."
        exitval=1
    fi
fi

exit $exitval


###############################################################################
# following code is commented out by design. This is templated for any checks
# for installed or selecetd software that is incompatible with HPVM
###############################################################################
#
#PATH=$PATH:/usr/bin
#
#software_rev=`get_sw_rev SOFTWARE.fileset` ; software_installed=$?
#if [[ $software_installed -eq 1 ]]
#        then
#                # If SOFTWARE.fileset is installed then FAIL, and give an error.
#                msg "ERROR:   SOFTWARE, is not compatible with "
#                msg "         T2767BC.HPVM versions B.04.xx.  "
#                msg "         Please remove SOFTWARE before proceeding."
#                exitval=$FAILURE
#fi
#
#is_software_selected SOFTWARE.fileset ; software_selected=$?
#
#if [[ $software_selected -eq 1 ]]
#        then
#                # If SOFTWARE.fileset is selected then FAIL, and give an error.
#                msg "ERROR:   SOFTWARE, is not compatible with "
#                msg "         T2767BC.HPVM versions B.04.xx.  "
#                msg "         Please unselect SOFTWARE from the install before 
#                msg "         proceeding."
#                exitval=$FAILURE
#fi
exit $exitval
