#!/bin/bash

if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
    set -x
fi
set -eu
set -o pipefail

tmp_dir=/tmp/hive
cd $tmp_dir

if [ -z "${HIVE_DOWNLOAD_URL:-}" ]; then
    HIVE_FILE=hive-$HIVE_VERSION-bin.tar.gz
else
    HIVE_FILE=$(basename $HIVE_DOWNLOAD_URL)
fi
tar xzf $HIVE_FILE
HIVE_DIR="${HIVE_FILE%.*}"
HIVE_DIR="${HIVE_DIR%.*}"
mv $HIVE_DIR /opt/hive
rm -r $tmp_dir
chmod -R a+rw /opt/hive

ln -s /usr/share/java/mysql-connector-java.jar /opt/hive/lib/libmysql-java.jar
chown -R hadoop:hadoop /opt/hive
cat >> /home/hadoop/.bashrc <<EOF
HIVE_HOME=/opt/hive
PATH=\$PATH:\$HIVE_HOME/bin
EOF
