#! /sbin/sh
###############################################################################
#  checkinstall for HPVM-KRN
#  @(#) $Revision: 7902 $
###############################################################################
#
# (c) Copyright Hewlett-Packard Company 2005-2006
#


###############################################################################
# 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

###############################################################################
# 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

##############################################################################
# Do not install if there are any HFS filesystems, these are not compatible
# with 64KB base_pagesize
##############################################################################
if [[ -f /etc/fstab ]]
then
   HAS_HFS=`grep -v '^#'  /etc/fstab | awk '{print $3}' | grep hfs `
   if [[ -n ${HAS_HFS} ]] 
   then
        msg "ERROR: HFS file systems are incompatible with Integrity Virtual Machines. Any HFS filesystems must be removed from /etc/fstab."
   exitval=1
   fi
fi



#######################################################################################
# This will detect whether HP Insgight Manager product is installed on the system
# and if so, refuse to install until it is removed.
#######################################################################################

##########################################
# Check for HP Insight Manager bundle.
##########################################

PATH=$PATH:/usr/bin

is_HPSIM_installed()
{
    swlist -l bundle 2>/dev/null | grep -Fqi 'HPSIM-HP-UX'
    return $?
}

#######################################################################################
# This will detect whether VirtualPartition (vpars) product is installed on the system
# and if so, refuse to install until it is removed.
#######################################################################################

##########################################
# Check for VirtualPartition bundle first.
##########################################

PATH=$PATH:/usr/bin

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

if [[ "${SW_SESSION_IS_UPDATE:-}" = "1" ]]
then
   VPARS_inst=1;
else
   is_VPARS_installed; VPARS_inst=$?
fi

#########################################################
# If VPARS bundle, VirtualPartition is installed, then fail.
#########################################################

if [[ $VPARS_inst -eq 0 ]]
then

      msg "ERROR:   VirtualPartition software must be removed before installing the Integrity Virtual Machines."
      exitval=$FAILURE

fi

if [[ "${SW_SESSION_IS_UPDATE:-}" = "1" ]]
then
   HPSIM_inst=1
else
   is_HPSIM_installed; HPSIM_inst=$?
fi

#########################################################
# If HPSIM bundle, Insight Manager is installed, then fail.
#########################################################

if [[ $HPSIM_inst -eq 0 ]]
then

      msg "ERROR:   HP Insight Manager software must be removed before installing the HP VirtualMachines."
      exitval=$FAILURE

fi

exit $exitval
