#!/bin/bash

# Copyright (c) 2017 Cloudera, Inc. All rights reserved.

# Time marker for both stderr and stdout
date; date 1>&2

# debug
set -x
echo "Running on: $(hostname -f) ($(hostname -i))" 1>&2

cloudera_config=`dirname $0`
cloudera_config=`cd "$cloudera_config/../common"; pwd`
. ${cloudera_config}/cloudera-config.sh

# Load the parcel environment
source_parcel_environment

# attempt to find java
locate_cdh_java_home

# simulate /etc/default/hadoop if necessary
. ${cloudera_config}/cdh-default-hadoop

echo "Using $JAVA_HOME as JAVA_HOME"
echo "Using $CONF_DIR as CONF_DIR"
echo "Using $CDH_VERSION as CDH_VERSION"

set_hadoop_classpath

export HADOOP_HOME=$CDH_HADOOP_HOME
echo "Using $HADOOP_HOME as HADOOP_HOME"

export HADOOP_CONF_DIR=$CONF_DIR/$HADOOP_CONF_DIR_NAME
export HADOOP_BIN=$HADOOP_HOME/bin/hadoop

# Search-replace {{CMF_CONF_DIR}} in files
replace_conf_dir

echo "Using $HADOOP_CONF_DIR as HADOOP_CONF_DIR"
echo "Using $HADOOP_BIN as HADOOP_BIN"

if [ $1 = "prune" ]; then
  exec ${HADOOP_BIN} s3guard prune
fi
