#!/usr/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/ihs/sbin/cl_discihs.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2009,2010 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)17	1.1  src/43haes/usr/sbin/cluster/sa/ihs/sbin/cl_discihs.sh, hacmp, 61haes_r714 11/28/11 15:26:32
###################################################################
##
## NAME:	cl_discihs
##
## DESCRIPTION:	
##    Perform IBM Http Server (IHS) Discovery.  Discovers all
##    installed instances of IHS and returns information 
##    about them.
##
##
## ARGUMENTS:	
##    None
##
## OUTPUT:	
##    Colon delimiter list of IHS installations
##    where each line contains info info about a
##    separate installation.  Information is:
##
##    Total number IHS Installations
##    Installation Path
##    Version
##    Installation Volume Groups
##    Installation PVIDs
##    Listen Directive Host
##
## EXIT CODES:	
##    None
##
## KLIB Functions:
##    KLIB_IHS_get_installations
##    KLIB_IHS_log_message
##    KLIB_IHS_get_ihs_plugin_path
##    KLIB_IHS_get_ihs_listen_host
##
##    KLIB_AIX_add_vg_by_path
##    KLIB_AIX_get_pvids_by_vgs
##
###################################################################



##########
# MAIN
##########

# Load the common klib functions, abort, logmsg, dbgmsg, etc.
. /usr/es/lib/ksh93/common_functions.ksh93

# Set the FPATH for all IHS / HACMP functions
FLIB=/usr/es/lib/ksh93
FPATH=$FLIB/utils:$FLIB/hacmp:$FLIB/ihs:$FLIB/util:$FLIB/util/list:$FLIB/aix/:$FLIB/aix/odm/:$FLIB/db2/vg

umask -S u=rw,g=,o=
PATH=$PATH:/usr/es/sbin/cluster/utilities:/usr/es/sbin/cluster/sa/ihs/sbin/

KLIB_DEFAULT_LOGFILE=/var/hacmp/log/ihssa.log
KLIB_HACMPLOG_ENTRY=ihssa.log
KLIB_OUTPUT_CONSOLE=false

typeset IHS_VGS=""
typeset LISTEN_HOST=""
typeset IHS_INSTALLATIONS=""

integer count=0
integer install_count=0
typeset version=""
typeset install_path=""
typeset plugin_path=""
typeset tmp=""

IHS_INSTALLATIONS=$(KLIB_IHS_get_installations "*IHS*")

echo $IHS_INSTALLATIONS | IFS=: read install_count installations
if [[ -z $installations ]]; then
    KLIB_IHS_log_message "IHS WARNING: IHS installation is not found"
else 
    KLIB_IHS_log_message "IHS INFO: installations found - $IHS_INSTALLATIONS"
fi

count=$install_count

# Get information about each installation
while (( $count > 0 )) ; do
    echo $installations | IFS=: read version install_path tmp
    installations=$tmp

    IHS_VGS=""
    LISTEN_HOST=""

    KLIB_AIX_add_vg_by_path IHS_VGS $install_path "$IHS_VGS"

    IHS_VG_PVIDS=$(KLIB_AIX_get_pvids_by_vgs $IHS_VGS)
    LISTEN_HOST=$(KLIB_IHS_get_ihs_listen_host $install_path)

    KLIB_IHS_log_message "IHS INFO: cl_discihs returning - ihs:$install_count:$install_path:$version:$IHS_VGS:$IHS_VG_PVIDS:$LISTEN_HOST"

    echo "ihs:$install_count:$install_path:$version:$IHS_VGS:$IHS_VG_PVIDS:$LISTEN_HOST"
    count=$count-1
done
