#! /bin/bash

apt install --yes default-jdk-headless
[[ -f "hadoop-3.1.1.tar.gz" ]] || wget "https://ftp.cs.up.ac.za/installers/linux/hadoop-3.1.1.tar.gz"
rm -rf /opt/hadoop*

cd /opt
echo Installing Hadoop, please wait \(this might take a while\)
tar -xf "$OLDPWD/hadoop-3.1.1.tar.gz"
chown -R root:root hadoop*
ln -s hadoop* hadoop
if ! grep -q hadoop ~/.bashrc; then
	echo "export PATH=\"\$PATH:/opt/hadoop/bin\"" >> ~/.bashrc
fi
echo JAVA_HOME="/usr/lib/jvm/default-java" >> /opt/hadoop/etc/hadoop/hadoop-env.sh

cd "$OLDPWD"

echo Please run \"source /etc/environment\" to add Hadoop to your PATH
