#!/bin/ksh

/usr/bin/pkginfo -R ${ROOTDIR} -q SUNWpsgwa
if [ $? -eq 1 ]; then
  /usr/bin/echo 'Portal Server Secure Remote Access not installed.'
  /usr/bin/echo 'Aborting this patch.'
  exit 1
fi

ANSWER=`/usr/bin/pkgparam -R ${ROOTDIR} SUNWpsgwa SUNW_PRODVERS`
OLD_IFS="$IFS"
IFS='.'
set $ANSWER
MAJOR_VERSION=$1
MINOR_VERSION=$2
SUB_VERSION=${3:-0}
IFS="$OLD_IFS"

ABORT='n'

if [ $MAJOR_VERSION -gt 6 ]; then
  ABORT='y'
elif [ $MAJOR_VERSION -eq 6 ]; then
  if [ $MINOR_VERSION -gt 2 ]; then
    ABORT='y'
  fi
fi

if [ "$ABORT" = 'n' ]; then
  INSTALLED_PATCHES=`/usr/sbin/patchadd -p -R ${ROOTDIR} | /usr/bin/cut -f2 -d' '`
  /usr/bin/echo $INSTALLED_PATCHES | /usr/bin/grep '118129' > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    ABORT='y'
  fi
fi

if [ "$ABORT" = 'y' ]; then
  /usr/bin/echo 'A newer version of Portal Server has been detected.'
  /usr/bin/echo 'Aborting this patch.'
  exit 1
fi

exit 0

