#!/usr/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2020,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/db2/sbin/cl_db2sw_ver_collector.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2008 
# 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
# @(#)  7d4c34b 43haes/usr/sbin/cluster/sa/db2/sbin/cl_db2sw_ver_collector.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM

#
# Name:		cl_db2sw_ver_collector
#
# Description:  This script is used by clverify to gather
#               the base DB2 UDB support and product signature fileset
#               installed version.
#
#		The output format will be as below
#		BASE_DB2_ENGINE:<corresponding version>
#		ESE_PRODUCT_SIGNATURE:<corresponding version>
#
#		As from DB2 V9.1 onwards DB2 install images
#		no longer uses the OS formats. Hence 'lslpp'
#		command can't be used to query DB2 installation.
#
# Arguments:    n/a
#
# Returns:      n/a
#

/usr/bin/lslpp -l 'db2*.db2.engn' 1>/dev/null 2>&1
[[ $? == 0 ]] && {
	echo "BASE_DB2_ENGINE:$(/usr/bin/lslpp -Lc 'db2*.db2.engn' | grep -v "#" | cut -d ':' -f 3)"
	echo "ESE_PRODUCT_SIGNATURE:$(/usr/bin/lslpp -Lc 'db2*.essg' | grep -v "#" | cut -d ':' -f 3)"
} || {
	
	typeset CLIENT_PATH
	typeset BASE_PATH
	
	CLIENT_PATH="/usr/local/bin"
	BASE_PATH=$($CLIENT_PATH/db2ls -c -a  2>/dev/null | grep -v "#" | cut -d ':' -f 1)

	#
	: As from DB2 V9.1 onwards DB2 install images
	: no longer uses the OS formats. Hence "lslpp"
	: command cannot be used to query DB2 installation.
	#
	echo "BASE_DB2_ENGINE:$($CLIENT_PATH/db2ls -c -a -q -b "$BASE_PATH" -f "BASE_DB2_ENGINE"  2>/dev/null | \
					grep -v "#" | cut -d ':' -f 2)"
	echo "ESE_PRODUCT_SIGNATURE:$($CLIENT_PATH/db2ls -c -a -q -b "$BASE_PATH" -f "ESE_PRODUCT_SIGNATURE"  2>/dev/null | \
						grep -v "#" | cut -d ':' -f 2)"
}
