#!/bin/bash
#
# Copyright 2014 Cloudera Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

function debug() {
  [ -n "$debug" ] && echo "$0 debug: $@"
}

bin=`dirname $0`
bin=`cd ${bin} && pwd`
lib="`dirname ${bin}`/lib/*"

KITE_CLASSPATH=${KITE_CLASSPATH:-$lib}

if [ ! -z "$KITE_USER_CLASSPATH" ]; then
  KITE_CLASSPATH="$KITE_USER_CLASSPATH:$KITE_CLASSPATH"
fi

if [ -d "$HIVE_CONF_DIR" ]; then
  debug "Adding HIVE_CONF_DIR=$HIVE_CONF_DIR"
  KITE_CLASSPATH="$HIVE_CONF_DIR:$KITE_CLASSPATH"
fi

if [ -d "$HADOOP_CONF_DIR" ]; then
  debug "Adding HADOOP_CONF_DIR=$HADOOP_CONF_DIR"
  KITE_CLASSPATH="$HADOOP_CONF_DIR:$KITE_CLASSPATH"
fi

debug "Using KITE_CLASSPATH=$KITE_CLASSPATH"
exec java $flags -cp "$KITE_CLASSPATH" org.kitesdk.minicluster.cli.Main "$@"

