#!/bin/sh

## Compare the version of the pkg we are installing against the version
## of the pkg that may already be installed and abort installation
## if a mismatch is detected. 

# Check for version of current package you are trying to install

currentVersion=`pkgparam -f ${INST_DATADIR}/${PKG}/pkginfo VERSION | awk -F, '{print $1}'`

# Check if package conflicts with a package version already installed on the system
# There could be instances of $PKG.2 $PKG.3 if there are multiple versions installed.

for pkgs in `pkginfo | grep -w ${PKG} | awk -F' ', '{print $2}'`
do
existingVersion=`pkgparam -f ${PKG_INSTALL_ROOT}/var/sadm/pkg/${pkgs}/pkginfo VERSION | awk -F, '{print $1}'`
if [ ${existingVersion} -ne ${currentVersion} ]; then
echo "Note: SunVTS ${existingVersion} is already installed on this host. Simultaneous execution of more than one version of SunVTS is not supported. Only one version of the tool should be run at one time."
fi
sleep 6
done
