#!/bin/ksh
# This program to test AIX perfstat version.
if [ "AIX" = `uname` ]
then
	#check if perfstat is installed
	lslpp -l bos.perf.perfstat > /dev/null 2>&1
	if [ $? = 0 ]
	then
		#check if libperfstat is installed
		lslpp -l bos.perf.libperfstat > /dev/null 2>&1
		if [ $? = 0 ]
		then
			#check if bos.mp is installed
			lslpp -l bos.mp > /dev/null 2>&1
			bos_mp=$?
			lslpp -l bos.mp64 > /dev/null 2>&1
			bos_mp64=$?
			lslpp -l bos.up > /dev/null 2>&1
			bos_up=$?
			if [ $bos_mp = 0 ] || [ $bos_mp64 = 0 ] || [ $bos_up = 0 ]
			then
				#check if AIX version is 5.x, if it is version 6 the libs will be in correct version.
				sysversion=`uname -v`
				if [ $sysversion -lt 6 ]
				then
					#check if perfstat and libperfstat are the right version
					if [ $bos_mp = 0 ]
					then
						perfversion=`lslpp -l bos.mp bos.perf.perfstat bos.perf.libperfstat | awk -F' ' '{print $2 }' | grep 5 | cut -d . -f 1,2 | uniq | wc -l`
					elif [ $bos_mp64 = 0 ]
					then
						perfversion=`lslpp -l bos.mp64 bos.perf.perfstat bos.perf.libperfstat | awk -F' ' '{print $2 }' | grep 5 | cut -d . -f 1,2 | uniq | wc -l`
					elif [ $bos_up = 0 ]
					then
						perfversion=`lslpp -l bos.up bos.perf.perfstat bos.perf.libperfstat | awk -F' ' '{print $2 }' | grep 5 | cut -d . -f 1,2 | uniq | wc -l`
					fi
					if [ $perfversion -ne 1 ]
					then
						#$NLS-E$ Installed perfstat update is not compatible with OS version.
						nls_replace 'KCI0686I'
						if [ $bos_mp = 0 ]
						then
							mp_version=`lslpp -l bos.mp | awk -F' ' '{print $2 }' | grep 5 | cut -d . -f 1,2| uniq`
						elif [ $bos_mp64 = 0 ]
						then
							mp_version=`lslpp -l bos.mp64 | awk -F' ' '{print $2 }' | grep 5 | cut -d . -f 1,2| uniq`
						elif [ $bos_up = 0 ]
						then
							mp_version=`lslpp -l bos.up | awk -F' ' '{print $2 }' | grep 5 | cut -d . -f 1,2| uniq`
						fi
						#$NLS-E$ perfstat version should start with $mp_version
						nls_replace 'KCI0687I' $mp_version
						#$NLS-E$ installed perfstat version is:
						nls_replace 'KCI0688I'
						lslpp -l bos.perf.libperfstat bos.perf.perfstat
						exit 1
					fi
				fi	  
			else
				#$NLS-E$ Unable to find bos.mp/bos.up. Need OS update bos.mp/bos.up to run product ux.
				nls_replace 'KCI0689E' 'bos.mp/mp64/up' 'bos.mp/mp64/up' 'ux'
				exit 1
			fi
		else
			#$NLS-E$ Unable to find bos.perf.libperfstat. Need OS update bos.perf.libperfstat to run product ux.
			nls_replace 'KCI0689E' 'bos.perf.libperfstat' 'bos.perf.libperfstat' 'ux'
			exit 1
		fi
	else
		#$NLS-E$ Unable to find bos.perf.perfstat. Need OS update bos.perf.perfstat to run product ux.
		nls_replace 'KCI0689E' 'bos.perf.perfstat' 'bos.perf.perfstat' 'ux'
		exit 1
	fi
fi
exit 0
