#!/bin/bash

# This script contains some fixes needed to have the Cloudera Ubuntu
# packages up and running

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

case "$DISTRO_NAME" in
    ubuntu )
        # pietro: small hack to fix install problems on ubuntu
        # the CDH package contains a broken symlink instead of the log4j jar file
        # these 4 lines should go away once Cloudera fixes the package
        echo "Fixing install problem for CDH: log4j";
        wget http://repo1.maven.org/maven2/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar;
        sudo rm /usr/lib/hadoop/lib/slf4j-log4j12-1.6.1.jar;
        sudo mv slf4j-log4j12-1.6.1.jar /usr/lib/hadoop/lib/

        mkdir /run/hadoop
        chown hadoop:hadoop /run/hadoop/

        mkdir -p /var/run/hadoop ; chown hadoop:hadoop /var/run/hadoop
        mkdir -p /mnt/log/hadoop ; chown hadoop:hadoop /mnt/log/hadoop
    ;;
esac
