#!/bin/sh
#
# Copyright (c) 2017-2020
# Beijing Baolande Software Corporation
#
# All Rights Reserved
#

BIN_HOME=`dirname "$0"`

if [ -d "$1" ]; then
  BES_ROOT=$1
  shift
fi

if [ ! -n "$BES_ROOT" ]; then
  BES_ROOT=`cd "${BIN_HOME}/.."; pwd`
fi

TEMP_LIB=${BES_ROOT}/lib
while true
do
    if [ -d "${TEMP_LIB}" ];then
        break
    else
        echo "Please specify the BES home:"
        read BES_ROOT
        if [ ! -n "$BES_ROOT" ];then
            BES_ROOT=.
        fi
        TEMP_LIB=${BES_ROOT}/lib
        if [ ! -d "${TEMP_LIB}" ];then
            echo "The specified directory is invalid!"
        fi
    fi
done

. "${BES_ROOT}/bin/setenv.conf"

SET_PATCH_ENV_TYPE=patch
. "${BES_ROOT}/bin/setpatchenv.conf"
PATH="${BES_ROOT}/bin;${BES_ROOT}/lib;${PATH}"
"${JAVA_BASE}/bin/java" ${JAVA_OPTS} "-Dcom.bes.installRoot=${BES_ROOT}" -cp "${PATCH_CLASSPATH}" com.bes.patch.cli.PatchLauncher "${@}"
