#!/bin/ksh
# Copyright 01/12/03 Sun Microsystems, Inc. All Rights Reserved.
# @(#)prepatch        1.15 01/12/03 Sun Microsystems

if [ ${ROOTDIR} != "/" ]; then
  echo "ERROR: This patch does not support relocatability through the use of a client_root_path specified with the -R flag"
  exit 1;
fi

GREP=/usr/bin/grep
SED=/usr/bin/sed
UNIQ=/usr/bin/uniq
ECHO=/usr/bin/echo
CHMOD=/usr/bin/chmod
CUT=/usr/bin/cut

REQUIREDVERSION="7.0"
BELL_CHAR='\a'

# Confirm this is a 7.0 system
CheckVersion() {
  local VERSIONFILE=$1
  local VERSIONKEY=$2

  if [ ! -f $VERSIONFILE ]; then
    $ECHO "Error: Can not determine installed Portal version - $VERSIONFILE does not exist. $BELL_CHAR"
    exit 1
  fi

  local INSTALLEDVERSION=`$GREP "^$VERSIONKEY" $VERSIONFILE | $CUT -d= -f2`
  if [ "$INSTALLEDVERSION" == "" ]; then
    $ECHO "Error: Can not determine installed Portal version. $BELL_CHAR"
    exit 1
  fi

  if [ "$INSTALLEDVERSION" != "$REQUIREDVERSION" ]; then
    $ECHO "Error: This patch can only be applied to Portal Server $REQUIREDVERSION. $BELL_CHAR"
    exit 1
  fi
}


# Version checking
pkginfo -q SUNWportal-admin
if [ $? -eq 0 ]; then

  PS_INSTALL_DIR=`pkginfo -r SUNWportal-admin`

  CheckVersion $PS_INSTALL_DIR/SUNWportal/lib/PSversion.properties productversion

fi # End of checking for Portal Server node
