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

GREP=/usr/bin/grep
SED=/usr/bin/sed
UNIQ=/usr/bin/uniq

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

  ANSWER=`$GREP "^$KEY$SEPARATOR" $FILE | $UNIQ | $SED -e "s/$KEY$SEPARATOR//"`
}
STATE_FILE="/etc/opt/SUNWps/PSConfig.properties"

# Permission fix for 6.2PC4 badpatch
/usr/bin/pkginfo -q SUNWps
if [ $? -eq 0 ]; then
  GrabConfig $STATE_FILE "BASEDIR" "=" 
  PS_INSTALL_DIR=$ANSWER
  chmod 755 $PS_INSTALL_DIR/SUNWps

# PST requirement to check that the services are running
GrabConfig $STATE_FILE "SERVER_PORT" "="
NETWORK_PORT=$ANSWER
GrabConfig $STATE_FILE "DEPLOY_ADMIN_HOST" "="
DEPLOY_HOST=$ANSWER
if [ -f $PS_INSTALL_DIR/SUNWps/bin/checkport ]; then
  $PS_INSTALL_DIR/SUNWps/bin/checkport $DEPLOY_HOST $NETWORK_PORT 2
  if [ $? -eq 1 ]; then
    echo "One or more of the required services are not running."
    echo "Please start them before attempting to apply the patch."
    echo "See the patch release notes for more information."
    exit 1;
  fi
fi

fi
