#!/bin/bash

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

tmp_dir=$TARGET_ROOT/tmp/hive
mkdir -p $tmp_dir

if [ -z ${HIVE_DOWNLOAD_URL:-} ]; then
    HIVE_DOWNLOAD_URL=http://archive.apache.org/dist/hive/hive-$HIVE_VERSION/hive-$HIVE_VERSION-bin.tar.gz
fi
HIVE_FILE=$(basename $HIVE_DOWNLOAD_URL)
cached_tar="$DIB_IMAGE_CACHE/$HIVE_FILE"
$TMP_HOOKS_PATH/bin/cache-url $HIVE_DOWNLOAD_URL $cached_tar
sudo install -D -g root -o root -m 0644 $cached_tar $tmp_dir
