#!/usr/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/tds/sbin/cl_tdssaquery.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 
# @(#)05	1.1  src/43haes/usr/sbin/cluster/sa/tds/sbin/cl_tdssaquery.sh, hacmp, 61haes_r714 11/28/11 15:01:20
#############################################################################
##
## Name:    cl_tdssaquery
##
## Description:    Performs application discovery query on the local node
##                 to determine if Tivoli Directory Server is available 
##
## Arguments:    none
##
## Returns:    0 Success
##             1 Failure
##
#############################################################################


#############################################################################
# Functions:
#
#
# displayInstall:
#       If any package installed, Displays information 
#
# Arguments:		
#	Package Name
#	Display Name
#	Component Name
#	Message Id number
#
# Return:
#	0 Success
#	1 Failure
#
#############################################################################

TDS_INSTALL_DIR="/opt/IBM/ldap/"
HAWS_HOME="/usr/es/sbin/cluster/sa/tds"
TMPFILE=$HAWS_HOME"/tds_config_type"
TMP_INSTANCE_LIST_FILE=$HAWS_HOME"/tds_instancelist"


set -A instanceList
set -A instanceHomeList

function displayInstall
{
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x

    pkgname=$1
    name=$2
    component=$3
    msgid=$4
    integer installed=0

    lslpp -l | grep $pkgname 1>/dev/null
	
    if test $? -eq 0
    then
       installed=1
    fi

	get_instance_list

	maxnum=`echo ${#instanceHomeList[*]}`
	let maxnum=${maxnum}+1
	i=1;
	while [[ $i -lt $maxnum ]];
    do
		confpath="${instanceHomeList[$i]}""/idsslapd-"${instanceList[$i]}"/etc"
		let i=${i}+1
		grep -x "objectclass: ibm-slapdReplication" $confpath/ibmslapd.conf 1>/dev/nulL
		if test $? -eq 0
		then
			grep "Proxy Server" $TMP_INSTANCE_LIST_FILE
			if test $? -eq 0
			then
				echo "DISTRIBUTED" > $TMPFILE
				break
			else 
				echo "PEERTOPEER" > $TMPFILE
				break
			fi
		else
			echo "STANDALONE" > $TMPFILE
		fi
	done
	
    print -n $(dspmsg -s 10 tdssa.cat 10 "Tivoli Directory Server Smart Assist")
    print -n ":TDS_5.2:"
    print -n $(dspmsg -s 10 tdssa.cat $msgid "$name")
    print -n ":$component:"
    echo $installed
}


#############################################################################
# Main:
#############################################################################

#PATH="$($(dirname ${0})/../../../utilities/cl_get_path all)"
PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"
PATH=$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin:/usr/es/sbin/cluster/sa/sbin
FPATH_BASE=/usr/es/lib/ksh93
FPATH=$FPATH_BASE/hacmp:$FPATH_BASE/sa:$FPATH_BASE/aix:$FPATH_BASE/aix/odm:$FPATH_BASE/ihs
export PATH FPATH
touch $TMPFILE

. /usr/es/sbin/cluster/sa/tds/sbin/clhaws_functions
TDSPackageName="idsldap"
TDSName="Tivoli Directory Server"
TDScomponent="TIVOLI_LDAP_SERVER"
TDSMessageId=35

displayInstall "$TDSPackageName" "$TDSName" "$TDScomponent" $TDSMessageId

exit 0
