###################################################
# COPYRIGHT : BEA Systems Inc.
#
###################################################


###################################################
# ENVIRONMENT VARIABLE CHECK
###################################################

# CHECK BEA_HOME
if [ -z "${BEA_HOME}" ]
then
  echo "Error : BEA_HOME was not set. Please set this variable to the root directory of the BEA Platform installation."
  return 1
elif [ ! -d "${BEA_HOME}" ]
then
  echo "Error : BEA_HOME (${BEA_HOME}) does not point to a valid directory."
  return 1
fi
export BEA_HOME

WLS_HOME=weblogic81
export WLS_HOME

# CHECK JAVA_HOME
if [ -z "${JAVA_HOME}" ]
then
  echo "Error : JAVA_HOME was not set. Please set this variable to the root directory of a JDK installation."
  return 1
elif [ ! -d "${JAVA_HOME}" ]
then
  echo "Error : JAVA_HOME (${JAVA_HOME}) does not point to a valid directory."
  return 1
fi
export JAVA_HOME

# CHECK WLI_UTIL_HOME
if [ -z "${WLI_UTIL_HOME}" ]
then
  echo "Error : WLI_UTIL_HOME was not set."
  echo "Please download and unzip the WLI common utilities. Then set this variable to the root directory (wli_util)."
  return 1
elif [ ! -d "${WLI_UTIL_HOME}" ]
then
  echo "Error : WLI_UTIL_HOME (${WLI_UTIL_HOME}) does not point to a valid directory."
  return 1
fi
export WLI_UTIL_HOME

# CHECK JYTHON_HOME
if [ -z "${JYTHON_HOME}" ]
then
  JYTHON_HOME="${BEA_HOME}/${WLS_HOME}/common/lib"
  echo "JYTHON_HOME was set to the default location ${JYTHON_HOME}"
fi
if [ ! -d "${JYTHON_HOME}" ]
then
  echo "Error : JYTHON_HOME (${JYTHON_HOME}) does not point to a valid directory."
  return 1
fi
export JYTHON_HOME

# CHECK WLST_JAR
if [ -z "${WLST_JAR}" ]
then
  WLST_JAR="${WLI_UTIL_HOME}/lib/wlst.jar"
  echo "WLST_JAR was set to the default location ${WLST_JAR}"
fi
if [ ! -s "${WLST_JAR}" ]
then
  echo "Error : WLST_JAR (${WLST_JAR}) does not point to a valid file."
  return 1
fi
export WLST_JAR

# CHECK DOMAIN_HOME
if [ -z "${DOMAIN_HOME}" ]
then
  DOMAIN_HOME="${BEA_HOME}/user_projects"
  echo "DOMAIN_HOME was set to the default location ${DOMAIN_HOME}"
fi
if [ ! -s "${DOMAIN_HOME}" ]
then
 mkdir -p "${DOMAIN_HOME}"
fi
export DOMAIN_HOME


###################################################
# ADD ant TO PATH
###################################################

PATHSEP=":"
myos=`uname`
case "$myos" in
  Window*)
  PATHSEP=";"
  ;;
esac

PATH="${BEA_HOME}/${WLS_HOME}/server/bin${PATHSEP}${PATH}"
export PATH


###################################################
# create env.properties
###################################################

cd ..
CLIENT_HOME=`pwd`
cd scripts 

if [ -s env.properties ]
then
  rm -f env.properties
fi

echo >>env.properties
echo tools.dir=${WLI_UTIL_HOME}>>env.properties
echo bea.home=${BEA_HOME}>>env.properties
echo weblogic.name=${WLS_HOME}>>env.properties
echo jdk.home=${JAVA_HOME}>>env.properties
echo jython.home=${JYTHON_HOME}>>env.properties
echo wlst.jar=${WLST_JAR}>>env.properties
echo domain.base=${DOMAIN_HOME}>>env.properties

echo >>env.properties
echo CLIENT_HOME=${CLIENT_HOME}>>env.properties
echo input.document.store=${CLIENT_HOME}/client/resources/input_data>>env.properties
echo selector.property.file=${CLIENT_HOME}/client/resources/query/${SELECTOR_PROPERTY_FILE}>>env.properties
echo mode=${MODE}>>env.properties
echo server.url=${SERVER_URL}>>env.properties
echo user=${WLS_USER}>>env.properties
echo password=${WLS_PASSWORD}>>env.properties

echo "Environment Set."

unsetenv CLASSPATH
unset CLASSPATH
