#!/bin/sh
#* ----------------------------------------------------------------------
#*               Proprietary and Confidential Information
#*
#* This material contains, and is part of a computer software program
#* which is, proprietary and confidential information owned by COMPUTER
#* ASSOCIATES INTERNATIONAL, INC.  The program, including this material,
#* may not be duplicated, disclosed or reproduced in whole or in part for
#* any purpose without the express written authorization of COMPUTER
#* ASSOCIATES. All authorized reproductions must be marked with this
#* legend.
#*
#*                          Copyright (c) 1992-2005
#*             Computer Associates International, Incorporated
#*                          All rights reserved
#*
#* ----------------------------------------------------------------------
#*  SCCS Module Control Stamp
#* ----------------------------------------------------------------------
#
#* "@(#)univer	1.6  08/15/05 16:01:20"
#* "Copyright (C) 1992-2005 Computer Associates International, Inc.  All rights reserved."
#

#
# Source the environment

ARG1="$1"

test -r /etc/profile.CA && . /etc/profile.CA minimum >/dev/null 2>&1

if [ "$CASHCOMP" = "" ]; then
	echo "Environment variable CASHCOMP is not set."
	echo "Exiting.."
	exit 4
fi

if [ ! -x "${CASHCOMP}/csutils/bin/ca_version" ];then
	echo "Unable to find the expected file: ${CASHCOMP}/csutils/bin/ca_version"
	echo "Contact Computer Associates Technical Support"
	exit 5
fi

if [ ! -x /usr/bin/lsm ];then
	lsmloc=`which lsm`  2>&1
	if [ ! -x $lsmloc ];then
       	    echo "Software Management Installer (LSM) is not installed. This gets installed with Unicenter NSM."
            echo "Contact Computer Associates Technical Support"
            echo ""
            exit 6
	fi
fi
PrintNSM="NO"
	ver=`"${CASHCOMP}/csutils/bin/ca_version" NSM -v 2>/dev/null`

	rc="$?"

	if [ "$rc" = "0" ];then
	
		if [ "$ARG1" = "-v" ];then
			"${CASHCOMP}/csutils/bin/ca_version" NSM
		else
			nsm_ver=`echo $ver |cut -d'.' -f1-2`
#Issue: 18548011    Title: NEED UNIVER FIX FOR SP1 commented the below line
#			echo "Unicenter NSM $nsm_ver"
			PrintNSM="YES"
		fi
	else

		ver=`"${CASHCOMP}/csutils/bin/ca_version" CCS -v 2>/dev/null`
		rc="$?"

		if [ "$rc" = "0" ];then

			if [ "$ARG1" = "-v" ];then
				"${CASHCOMP}/csutils/bin/ca_version" CCS
			else
				ccs_ver=`echo $ver |cut -d'.' -f1-2`
				echo "CA Common Services $ccs_ver"
			fi
		else

			# Try to get the name using .univer
			if [ -f "$CAIGLBL0000/.univer" ];then
				cat "$CAIGLBL0000/.univer"
			elif [ -f "$CASHCOMP/ccs/.univer" ];then
				cat "$CASHCOMP/ccs/.univer"
			fi
		fi
	fi

# Check for distribution version text file and report if found
#Issue: 18548011    Title: NEED UNIVER FIX FOR SP1 
#Added the if condition so that Version and Genlevel are displayed on the same line for NSM
	if [ $PrintNSM = "YES" ];then
		if [ -f "$CAIGLBL0000/.univer.txt" ]; then
           		dist=`cat "$CAIGLBL0000/.univer.txt"`
        	elif [ -f "$CASHCOMP/ccs/.univer.txt" ]; then
           		dist=`cat "$CASHCOMP/ccs/.univer.txt"`
        	fi
		echo "Unicenter NSM $nsm_ver $dist"
	else
		if [ -f "$CAIGLBL0000/.univer.txt" ]; then
	        	cat "$CAIGLBL0000/.univer.txt"
      		elif [ -f "$CASHCOMP/ccs/.univer.txt" ]; then
           		cat "$CASHCOMP/ccs/.univer.txt"
        	fi

	fi
        exit $rc
