#! /sbin/sh
###############
# Product: HPVM
# Fileset: HPVM-CORE
# configure
# @(#) $Revision: 8449 $
################
#
# (c) Copyright Hewlett-Packard Company, 2005-2006
#
########################################################################

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

###############################################################################
# If you have to perform an operation such as converting a file format to a
# new form, that operation can be done as part of the configure script.  You
# must be able to detect that the conversion has been done so the conversion
# is not attempted more than once.
###############################################################################
# If you start a daemon, set your system configuration file's startup
# parameter to also start it at subsequent reboots. If SW_CONFIG_AFTER_REBOOT
# is set do NOT start your daemon.
# If vmm_cdio is unused in the kern, then do NOT start hpvm deamon.
# We need to check with dev. to see when /etc/rc.config.d/hpvm gets updated
# if hpvm is installed, but the kern module is "unused" or not configured.
# For now, if the kern module is NOT configured, we are not starting or
# setting rc.config.d/hpvm to run hpvm on reboots.
###############################################################################

#
# New "hpvmsys" group creation with conversion of a old
# obsolete hpvmoper group if it exists.
#
exist=
cp /etc/group /etc/group.prehpvm
# Does the hpvmsys group already exist?
if /usr/bin/grget -n hpvmsys >/dev/null 2>&1 ; then
    exist=TRUE
fi
# Does an old hpvmoper group exist?
if /usr/bin/grget -n hpvmoper >/dev/null 2>&1 ; then
    if [ -z "$exist" ] ; then
        /usr/sbin/groupmod -n hpvmsys hpvmoper
        exist=TRUE
    else
        /usr/sbin/groupdel hpvmoper
    fi
fi
#
# if hpvmsys group still does not exist create it
#
if [ -z "$exist" ] ; then
    groupadd hpvmsys >/dev/null 2>/dev/null
    cp /etc/group /etc/group.hpvmnew
    sed 's/hpvmsys::\([0-9]*\):/hpvmsys:*:\1:root/' /etc/group.hpvmnew >/etc/group 
    rm /etc/group.hpvmnew
fi 
rm /etc/group.prehpvm

# Change the group on directories and files owned by hpvmsys

chmog 555 bin bin /opt/hpvm

chmog 2755 root hpvmsys /var/opt/hpvm
IPD_addfile /var/opt/hpvm

chmog 2755 root hpvmsys /var/opt/hpvm/guests
IPD_addfile /var/opt/hpvm/guests

chmog 2755 root hpvmsys /var/opt/hpvm/common
IPD_addfile /var/opt/hpvm/common

chmog 2755 root hpvmsys /var/opt/hpvm/uuids
IPD_addfile /var/opt/hpvm/uuids

chmog 2755 root hpvmsys /var/opt/hpvm/ISO-images
IPD_addfile /var/opt/hpvm/ISO-images

chmog 2755 root hpvmsys /var/opt/hpvm/ISO-images/hpux
IPD_addfile /var/opt/hpvm/ISO-images/hpux

chmog 2755 root hpvmsys /var/opt/hpvm/ISO-images/linux
IPD_addfile /var/opt/hpvm/ISO-images/linux

chmog 2755 root hpvmsys /var/opt/hpvm/ISO-images/windows
IPD_addfile /var/opt/hpvm/ISO-images/windows

chmog 2755 root hpvmsys /var/opt/hpvm/ISO-images/common
IPD_addfile /var/opt/hpvm/ISO-images/common

chmog 4550 root hpvmsys /opt/hpvm/bin/hpvmstart
IPD_addfile /opt/hpvm/bin/hpvmstart

chmog 2555 root hpvmsys /opt/hpvm/bin/hpvmconsole
IPD_addfile /opt/hpvm/bin/hpvmconsole

chmog 2555 root hpvmsys /opt/hpvm/bin/hpvmctrld
IPD_addfile /opt/hpvm/bin/hpvmctrld

chmog 4550 root hpvmsys /opt/hpvm/lbin/hpvmapp
IPD_addfile /opt/hpvm/lbin/hpvmapp

chmog 0755 root hpvmsys /opt/hpvm/lbin/hpvmmonlogd
IPD_addfile /opt/hpvm/lbin/hpvmmonlogd

#
# Create HPVM logging files, command.log & vm_serial
#
touch /var/opt/hpvm/common/command.log
chmog 660 root hpvmsys /var/opt/hpvm/common/command.log
touch /var/opt/hpvm/common/vm_serial
chmog 640 root hpvmsys /var/opt/hpvm/common/vm_serial
mkdir /opt/hpvm/eval_newconfig
chown bin /opt/hpvm/eval_newconfig
chgrp bin /opt/hpvm/eval_newconfig
chmod 555 /opt/hpvm/eval_newconfig
mv /opt/hpvm/newconfig/* /opt/hpvm/eval_newconfig/.
rmdir /opt/hpvm/newconfig
mv /opt/hpvm/eval_newconfig /opt/hpvm/newconfig

touch /opt/hpvm/newconfig/enable_eval_kit
rm /opt/hpvm/newconfig/enable_eval_kit

#
############################################################################
# Add /opt/hpvm/bin to /etc/PATH
############################################################################
# The name of the path to add.
cmdpath=${SW_ROOT_DIRECTORY}opt/hpvm/bin
# Add the HPVM path into /etc/PATH.
mod_pathfile -a P ${cmdpath}
if [[ $? -ne 0 ]]
then
    # The path could not be added to /etc/PATH so write a message to the log
    # file and set the exit value.
    msg WARNING "The path \"${cmdpath}\" could not be added to /etc/PATH."
    [[ ${exitval} -ne $FAILURE ]] && exitval=$WARNING
fi

############################################################################
# Add /opt/hpvm/share/man to /etc/MANPATH
############################################################################
# The name of the path to add.
manPath=${SW_ROOT_DIRECTORY}opt/hpvm/share/man
# Add the path into /etc/MANPATH.
mod_pathfile -a MP ${manPath}
if [[ $? -ne 0 ]]
then
    # The path could not be added to /etc/MANPATH so write a message to the
    # log file and set the exit value.
    msg WARNING "The path \"${manPath}\" could not be added to /etc/MANPATH."
    [[ ${exitval} -ne $FAILURE ]] && exitval=$WARNING
fi 

############################################################################
# Remove T2767AC bundle if it is installed
############################################################################
VM_BUNDLE_REMOVE=T2767AC
swlist -l bundle 2>/dev/null | egrep -q $VM_BUNDLE_REMOVE
T2767AC_INSTALLED=$?
if [[ ${T2767AC_INSTALLED} -eq 0 ]]
then
   swmodify -u $VM_BUNDLE_REMOVE > /dev/null 2>&1
fi

############################################################################
# Remove T2767BC bundle if it is installed and T2767CC is installed
############################################################################
VM_BUNDLE_REMOVE=T2767BC
swlist -l bundle 2>/dev/null | egrep -q $VM_BUNDLE_REMOVE
T2767BC_INSTALLED=$?
swlist -l bundle 2>/dev/null | egrep -q T2767CC
T2767CC_INSTALLED=$?
if [[ ${T2767CC_INSTALLED} -eq 0 ]]
then
    if [[ ${T2767BC_INSTALLED} -eq 0 ]]
    then
        swmodify -u $VM_BUNDLE_REMOVE > /dev/null 2>&1
    fi
fi

############################################################################
# Remove VMMIgrate bundle if it is installed
############################################################################
VM_BUNDLE_REMOVE=VMMigrate
swlist -l bundle 2>/dev/null | egrep -q $VM_BUNDLE_REMOVE
REMOVE_BUNDLE_INSTALLED=$?
if [[ ${REMOVE_BUNDLE_INSTALLED} -eq 0 ]]
then
   swmodify -u $VM_BUNDLE_REMOVE > /dev/null 2>&1
fi

############################################################################
# Remove S529hpvm if it exists and is a sym link
############################################################################
if [[ ${SW_SESSION_IS_DRD} != 1 ]]; then
    if [[ -h  /sbin/rc2.d/S529hpvm ]]
    then
        rm /sbin/rc2.d/S529hpvm
    fi
fi

############################################################################
# Remove K471hpvm if it exists and is a sym link
############################################################################
if [[ ${SW_SESSION_IS_DRD} != 1 ]]; then 
    if [[ -h  /sbin/rc1.d/K471hpvm ]]
    then
        rm /sbin/rc1.d/K471hpvm
    fi
fi


############################################################################
# Above code copied from development drop file  - Carol Lopp 
# /var/cvsroot/vmm/install/opt/hpvm/bin/install_hpvm_script,v Rev: 1.8 
############################################################################
 
if [ -z "${SW_CONFIG_AFTER_REBOOT}" ] # env var is not set
then
    if [[ -x /sbin/init.d/hpvm ]]
    then
	# Start the daemon
	msg "NOTE:    Starting HPVM daemon"
	/sbin/init.d/hpvm start
    fi	
fi

exit $exitval
