#! /bin/bash

set -ex

echo "Installing OpenJDK Java ${2}"

add-apt-repository -y ppa:openjdk-r/ppa # THIS REPO IS OUTDATED, but that's ok for testing
apt-get update
apt-get install -y openjdk-${2}-jdk

echo "Creating activation script"
echo """ #! /bin/bash

rm -f /usr/lib/jvm/java-current-openjdk
ln -sf /usr/lib/jvm/java-${1}-openjdk-amd64 /usr/lib/jvm/java-current-openjdk""" > /usr/bin/activate_java_${2}
chmod a+x /usr/bin/activate_java_${2}
