#!/bin/bash

# This element installs Hadoop CDH 4 HDFS from Cloudera.
# It does not do a full install of CDH, it installs the miminum needed to
# Spark to run correctly.

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

echo "Creating hadoop user & group"
case "$DISTRO_NAME" in
    ubuntu )
        if ! getent group hadoop > /dev/null; then
            addgroup hadoop
        fi
        if ! getent passwd hadoop > /dev/null; then
            adduser --ingroup hadoop --disabled-password --gecos GECOS hadoop
        fi
        adduser hadoop sudo
    ;;
esac

echo "Pre-configuring Hadoop"

cat >> /home/hadoop/.bashrc <<EOF
PATH=$PATH:/usr/sbin
EOF
cat >> /etc/hadoop/hadoop-env.sh <<EOF
export HADOOP_LOG_DIR=/mnt/log/hadoop/\$USER
export HADOOP_SECURE_DN_LOG_DIR=/mnt/log/hadoop/hdfs
EOF
