Switch to Amazon Coretto Java distribution and install both JDK 8 and 11

Install shellcheck from binary release (source install with haskell's
cabal tool takes >10m)

Change-Id: I5c6af1d5b8d9245e2b2d97ffc91eb7991e1723ed
diff --git a/jjb/onos/onos-release-build-verify.sh b/jjb/onos/onos-release-build-verify.sh
index b6fa112..22898b2 100644
--- a/jjb/onos/onos-release-build-verify.sh
+++ b/jjb/onos/onos-release-build-verify.sh
@@ -13,10 +13,8 @@
 if [ ${GERRIT_BRANCH} == "master" -o ${GERRIT_BRANCH} == "onos-2.2" ]
 then
     echo Installing OPEN JDK 11
-    curl -L -o jdk.tar.gz -s https://cdn.azul.com/zulu/bin/zulu11.31.11-ca-jdk11.0.3-linux_x64.tar.gz
-    tar xf jdk.tar.gz
-    export JAVA_HOME="`pwd`/zulu11.31.11-ca-jdk11.0.3-linux_x64"
-    PATH="$JAVA_HOME/bin:$PATH"
+    sudo update-alternatives --set java  /usr/lib/jvm/java-11-amazon-corretto/bin/java
+    sudo update-alternatives --set javac /usr/lib/jvm/java-11-amazon-corretto/bin/javac
     java -version
 else
     echo Using default JDK
diff --git a/jjb/onos/onos-release-build.sh b/jjb/onos/onos-release-build.sh
index a076733..77d48e4 100644
--- a/jjb/onos/onos-release-build.sh
+++ b/jjb/onos/onos-release-build.sh
@@ -13,10 +13,8 @@
 if [ ${GERRIT_BRANCH} == "master" -o ${GERRIT_BRANCH} == "onos-2.2" ]
 then
     echo Installing OPEN JDK 11
-    curl -L -o jdk.tar.gz -s https://cdn.azul.com/zulu/bin/zulu11.31.11-ca-jdk11.0.3-linux_x64.tar.gz
-    tar xf jdk.tar.gz
-    export JAVA_HOME="`pwd`/zulu11.31.11-ca-jdk11.0.3-linux_x64"
-    PATH="$JAVA_HOME/bin:$PATH"
+    sudo update-alternatives --set java  /usr/lib/jvm/java-11-amazon-corretto/bin/java
+    sudo update-alternatives --set javac /usr/lib/jvm/java-11-amazon-corretto/bin/javac
     java -version
 else
     echo Using default JDK
diff --git a/packer/provision/basebuild.sh b/packer/provision/basebuild.sh
index b41e9f9..5dc6657 100644
--- a/packer/provision/basebuild.sh
+++ b/packer/provision/basebuild.sh
@@ -10,19 +10,9 @@
     echo 'No changes to apply'
 }
 
-ubuntu_install_java_setup() {
-    DISTRO="xenial" # TODO get this programatically
-    echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
-    echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu $DISTRO main" | \
-        tee /etc/apt/sources.list.d/webupd8team-java.list
-    echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu $DISTRO main" | \
-        tee -a /etc/apt/sources.list.d/webupd8team-java.list
-    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
-}
 
 ubuntu_systems() {
     apt-get clean
-    ubuntu_install_java_setup
 
     # set up docker repo
     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@@ -43,8 +33,6 @@
         nodejs \
         nodejs-legacy \
         npm \
-        oracle-java8-installer \
-        oracle-java8-set-default \
         python \
         python-pip \
         python-virtualenv \
@@ -56,13 +44,11 @@
     npm install -g bower
     npm install karma --save-dev
 
-    #TODO clean up
-    #apt-get clean
-    #apt-get purge -y
-    #apt-get autoremove -y
-    #rm -rf /var/lib/apt/lists/*
-    #rm -rf /var/cache/oracle-jdk8-installer
-    echo 'No changes to apply'
+    # clean up
+    apt-get clean
+    apt-get purge -y
+    apt-get autoremove -y
+    rm -rf /var/lib/apt/lists/*
 }
 
 all_systems() {
diff --git a/packer/provision/baseline.sh b/packer/provision/baseline.sh
index 025740e..532247c 100644
--- a/packer/provision/baseline.sh
+++ b/packer/provision/baseline.sh
@@ -227,29 +227,32 @@
 
     ensure_ubuntu_install unzip xz-utils puppet git libxml-xpath-perl
 
-    # install Java 7
-    echo "---> Configuring OpenJDK"
-    FACTER_OSVER=$(/usr/bin/facter operatingsystemrelease)
-    case "$FACTER_OSVER" in
-        14.04)
-            apt-get install openjdk-7-jdk
-            # make jdk8 available
-            add-apt-repository -y ppa:openjdk-r/ppa
-            apt-get update
-            # We need to force openjdk-8-jdk to install
-            apt-get install openjdk-8-jdk
-            # make sure that we still default to openjdk 7
-            update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
-            update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
-        ;;
-        16.04)
-            apt-get install openjdk-8-jdk
-        ;;
-        *)
-            echo "---> Unknown Ubuntu version $FACTER_OSVER"
-            exit 1
-        ;;
-    esac
+    echo "---> Configuring Corretto JDK Distribution"
+    # instructions: https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/generic-linux-install.html
+    # install prereqs
+    apt-get install java-common
+
+    # install Java8
+    CORRETTO_JAVA8_VERSION="8.222.10-1"
+    CORRETTO_JAVA8_SHA256SUM="e5fd6c6f2d1a1fc5e6926f7a543e67ad0f0e0389ddc5d2deb5890bdeb21ea445"
+    curl -L -o /tmp/corretto_java8.deb "https://d3pxv6yz143wms.cloudfront.net/$(echo $CORRETTO_JAVA8_VERSION | tr - .)/java-1.8.0-amazon-corretto-jdk_${CORRETTO_JAVA8_VERSION}_amd64.deb"
+    echo "$CORRETTO_JAVA8_SHA256SUM  /tmp/corretto_java8.deb" | sha256sum -c -
+    dpkg -i /tmp/corretto_java8.deb
+
+    # install Java11
+    CORRETTO_JAVA11_VERSION="11.0.4.11-1"
+    CORRETTO_JAVA11_SHA256SUM="f47c77f8f9ee5a80804765236c11dc749d351d3b8f57186c6e6b58a6c4019d3e"
+    curl -L -o /tmp/corretto_java11.deb "https://d3pxv6yz143wms.cloudfront.net/$(echo $CORRETTO_JAVA11_VERSION | tr - .)/java-11-amazon-corretto-jdk_${CORRETTO_JAVA11_VERSION}_amd64.deb"
+    echo "$CORRETTO_JAVA11_SHA256SUM  /tmp/corretto_java11.deb" | sha256sum -c -
+    dpkg -i /tmp/corretto_java11.deb
+
+    # Set default version to be Java8
+    update-alternatives --set java  /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/bin/java
+    update-alternatives --set javac /usr/lib/jvm/java-1.8.0-amazon-corretto/bin/javac
+
+    # Set default version to be Java11
+    # update-alternatives --set java  /usr/lib/jvm/java-11-amazon-corretto/bin/java
+    # update-alternatives --set javac /usr/lib/jvm/java-11-amazon-corretto/bin/javac
 
     ########################
     # --- START LFTOOLS DEPS
@@ -264,15 +267,16 @@
     # Used by lftools scripts to parse XML
     ensure_ubuntu_install xmlstarlet
 
-    # Haskel Packages
-    # Cabal update fails on a 1G system so workaround that with a swap file
-    dd if=/dev/zero of=/tmp/swap bs=1M count=1024
-    mkswap /tmp/swap
-    swapon /tmp/swap
-
-    ensure_ubuntu_install cabal-install
-    cabal update
-    cabal install --bindir=/usr/local/bin "shellcheck-0.4.6"  # Pin shellcheck version
+    # Install Shellcheck from archive
+    SHELLCHECK_VERSION="v0.6.0"
+    SHELLCHECK_SHA256SUM="95c7d6e8320d285a9f026b5241f48f1c02d225a1b08908660e8b84e58e9c7dce"
+    curl -L -o /tmp/shellcheck.tar.xz https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz
+    echo "$SHELLCHECK_SHA256SUM  /tmp/shellcheck.tar.xz" | sha256sum -c -
+    pushd /tmp
+    tar -xJvf shellcheck.tar.xz
+    cp shellcheck-${SHELLCHECK_VERSION}/shellcheck /usr/local/bin/shellcheck
+    chmod a+x /usr/local/bin/shellcheck
+    popd
 
     # --- END LFTOOLS DEPS
     ######################