#!/bin/ksh

###############################################
# Sourcing macros
DIRNAME=/usr/bin/dirname
. `$DIRNAME $0`/../lib/psmacros
###############################################

###############################################
# Defines
###############################################

BELL_CHAR='\a'

PS_STATE_FILE="$PS_CONFIG_DIR/PSConfig.properties"

###############################################
# Get configuration from file
###############################################
GrabConfig() {
  local FILE=$1
  local KEY=$2
  local SEPARATOR=$3

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

###############################################
# Main
###############################################

if [ ! -f $PS_STATE_FILE ]; then
  $ECHO "Error: Cannot find $PS_STATE_FILE. $BELL_CHAR"
  exit 1
fi

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

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

PS_DIR="$PS_BASEDIR/$PS_PRODUCT_DIR"

JARS="$PS_DIR/lib/searchserver.jar:$KTSEARCH_LIB_DIR/ktsearch.jar:$PS_DIR/lib/db.jar"
CP="$PS_DIR/web-src/WEB-INF/classes:$PS_DIR/lib:$JARS"

LD_LIBRARY_PATH="$PS_DIR/lib"
export LD_LIBRARY_PATH

if [ "$OSTYPE" = "Linux" ]; then
  HEAP=-Xmx1800m
else
  HEAP=-Xmx1900m
fi

$JDK_DIR/bin/java -Xms32m $HEAP -cp $CP com.sun.portal.search.rdmgr.RDMgr "$@"

exit $?
