#!/bin/ksh

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

/usr/bin/pkginfo -R ${ROOTDIR} -q SUNWpswp
if [ $? -eq 0 ]; then
  /usr/bin/echo 'SUNWpswp has been detected.'
  /usr/bin/echo 'Aborting this patch.'
  exit 1
fi

ANSWER=`/usr/bin/pkgparam -R ${ROOTDIR} SUNWps 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 '118128' > /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

