#!/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

GrabConfig() {
  local FILE=$1
  local KEY=$2
  local SEPARATOR=$3

  ANSWER=`$GREP "^$KEY$SEPARATOR" $FILE | $UNIQ | $SED -e "s/$KEY$SEPARATOR//"`
}

BELL_CHAR='\a'

pkginfo -q SUNWps
if [ $? -eq 0 ]; then

  PS_STATE_FILE="/etc/opt/SUNWps/PSConfig.properties"
  if [ ! -f $PS_STATE_FILE ]; then
    $ECHO "Error: $PS_STATE_FILE does not exist. $BELL_CHAR"
    exit 1
  fi

  GrabConfig $PS_STATE_FILE "BASEDIR" "="
  if [ "$ANSWER" != "" ]; then
     PS_INSTALL_DIR=$ANSWER
  else
    $ECHO "Error: Cannot determine BASEDIR. $BELL_CHAR"
    exit 1
  fi

  GrabConfig $PS_STATE_FILE "DEPLOY_TYPE" "="
  if [ "$ANSWER" != "" ]; then
    DEPLOY_TYPE=$ANSWER
  else
    $ECHO "Warning: Cannot determine DEPLOY_TYPE. $BELL_CHAR"
  fi

  # Permission fix for SUNWps
  if [ "$PS_INSTALL_DIR" != "" ]; then
    $CHMOD 755 $PS_INSTALL_DIR/SUNWps
  fi

  DEPLOY=$PS_INSTALL_DIR/SUNWps/bin/deploy

  $ECHO ""
  $ECHO "To complete the patch install, you must deploy"
  $ECHO "the updated web application using:"
  $ECHO "# $DEPLOY redeploy"
  $ECHO "and then restart your web container instances."
  $ECHO ""

  if [ $DEPLOY_TYPE="IWS" ]; then

      GrabConfig $PS_STATE_FILE "DEPLOY_INSTANCE" "="
      if [ "$ANSWER" != "" ]; then
        DEPLOY_INSTANCE=$ANSWER
      else
        $ECHO "Warning: Cannot determine DEPLOY_INSTANCE. $BELL_CHAR"
        DEPLOY_INSTANCE="<deploy-instance>"
      fi

      GrabConfig $PS_STATE_FILE "DEPLOY_URI" "="
      if [ "$ANSWER" != "" ]; then
        DEPLOY_URI=$ANSWER
      else
        $ECHO "Warning: Cannot determine DEPLOY_URI. $BELL_CHAR"
        DEPLOY_URI="<deploy-uri>"
      fi

      $ECHO "WARNING: The deploy command redeploys content from $PS_INSTALL_DIR/SUNWps/web-src"
      $ECHO "to /var/opt/SUNWps/https-$DEPLOY_INSTANCE$DEPLOY_URI/web-apps"
      $ECHO "Any customisations to the Portal web application should always be made"
      $ECHO "to web-src and then deployed to web-apps. Ensure that any changes you"
      $ECHO "have made under web-apps have been replicated in web-src before"
      $ECHO "running deploy, or they will be lost."
      $ECHO ""
  fi
fi
