From eb3bbeedb79977a0fdf805b1f5ff303ef177594d Mon Sep 17 00:00:00 2001
From: Phillip Ross <phillip.w.g.ross@gmail.com>
Date: Wed, 28 Oct 2015 17:46:14 -0400
Subject: [PATCH] Updated provisioning to allow configuring Vagrant machine to
 use OracleJDK8 instead of OpenJDK7

---
 README.md    |  4 +++-
 provision.sh | 67 ++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md
index 5e53dd9..bc462b2 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,9 @@
 
 Vagrantfile for Payara.
 
-Currently it uses ubuntu/trusty64 as a base and gets the Java EE Web profile of Payara 4.1.1.154, extracting to /opt/payara/payara-$PAYARA_VERSION.  The provision.sh script contains PAYARA_VERSION and PAYARA_ED variables which can be changed to point to a different version/edition of Payara.  OpenJDK 7 is installed, since that is the latest Java currently available in the Ubuntu repos.
+Currently it uses ubuntu/trusty64 as a base and gets the Java EE Web profile of Payara 4.1.1.154, extracting to /opt/payara/payara-$PAYARA_VERSION.  The provision.sh script contains PAYARA_VERSION and PAYARA_ED variables which can be changed to point to a different version/edition of Payara.
+
+By default, OpenJDK 7 is installed, since that is the latest Java currently available in the Ubuntu repos.  The `JDK` variable can be changed in the provision.sh script to choose to install Oracle JDK 8 instead of OpenJDK.
 
 During provisioning, both domains (`domain1` and `payaradomain`) are configured to enable secure admin mode with a username of `admin` and password of `payara0payara`.
 
diff --git a/provision.sh b/provision.sh
index 73f8a77..d5eaccc 100644
--- a/provision.sh
+++ b/provision.sh
@@ -5,6 +5,9 @@
 # Setting properties
 #
 
+# Which JDK to use (OPENJDK or ORACLE)
+JDK="OPENJDK"
+
 # Payara Version
 PAYARA_VERSION=4.1.1.154
 
@@ -68,7 +71,7 @@ case "$PAYARA_VERSION" in
 		MULTI_LANGUAGE_FULL=https://s3-eu-west-1.amazonaws.com/payara.co/payara-ml-prerelease.zip
 		MULTI_LANGUAGE_WEB=https://s3-eu-west-1.amazonaws.com/payara.co/payara-web-ml-prerelease.zip
 	;;
-\*)
+	\*)
 	echo "unknown version number"
 esac
 
@@ -80,21 +83,47 @@ PAYARA_ED=$WEB
 ##########################################
 
 
+# Configure the operating system environment
+configureOSE() {
+	echo "Configuring operating system"
+
+	echo "running update..."
+	apt-get -qqy update                           # Update the repos
+
+	echo "installing unzip"
+	apt-get -qqy install unzip                    # Install unzip
+}
+
+
+# Install OpenJDK7 from Ubuntu repos
+installOpenJDK7() {
+	echo "Installing OpenJDK 7"
+	apt-get -qqy install openjdk-7-jdk            # Install OpenJDK 7
+}
+
+
+# Install Oracle JDK8 via PPA from webupd8.org
+installOracleJDK8() {
+	echo "Installing OracleJDK 8"
+
+        # Automate the Oracle JDK license acceptence
+	echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
+
+	add-apt-repository -y ppa:webupd8team/java    # Register the PPA
+	apt-get -qqy update                           # Update the repos
+	apt-get -qqy install oracle-java8-installer   # Install Oracle JDK 8
+}
+
+
 # Download and unzip to /opt/payara
 installPayara() {
 	echo "Provisioning Payara-$PAYARA_VERSION $PAYARA_ED to $PAYARA_HOME"
-	
-	echo "running update..."
-	sudo apt-get -qqy update                      # Update the repos 
-	
-	echo "installing openjdk and unzip"
-	sudo apt-get -qqy install openjdk-7-jdk       # Install JDK 7 
-	sudo apt-get -qqy install unzip               # Install unzip 
-	
+
 	echo "Downloading Payara $PAYARA_VERSION"
-	wget -q $PAYARA_ED -O temp.zip > /dev/null    # Download Payara 
-	sudo mkdir -p $PAYARA_HOME                    # Make dirs for Payara 
-	unzip -qq temp.zip -d $PAYARA_HOME            # unzip Payara to dir 
+	wget -q $PAYARA_ED -O temp.zip > /dev/null    # Download Payara
+	mkdir -p $PAYARA_HOME                         # Make dirs for Payara
+	unzip -qq temp.zip -d $PAYARA_HOME            # unzip Payara to dir
+        rm temp.zip                                   # cleanup temp file
 
         echo "Enabling secure admin mode for domains (u/p = admin/payara0payara)"
         PWDFILE=/tmp/pwdfile
@@ -109,20 +138,20 @@ installPayara() {
         rm "${PWDFILE}"
 
         echo "Setting ownership of ${PAYARA_HOME} content"
-	sudo chown -R vagrant:vagrant $PAYARA_HOME    # Make sure vagrant owns dir
+	chown -R vagrant:vagrant $PAYARA_HOME         # Make sure vagrant owns dir
 }
 
 
 # Copy startup script, and create service
 installService() {
 	echo "installing startup scripts"
-	mkdir -p $PAYARA_HOME/startup                    # Make dirs for Payara 
+	mkdir -p $PAYARA_HOME/startup                 # Make dirs for Payara 
 	cp /vagrant/payara_service-$PAYARA_VERSION $PAYARA_HOME/startup/ 
 	chmod +x $PAYARA_HOME/startup/payara_service-$PAYARA_VERSION
 	ln -s $PAYARA_HOME/startup/payara_service-$PAYARA_VERSION /etc/init.d/payara 
 	
 	echo "Adding payara system startup..."
-	sudo update-rc.d payara defaults > /dev/null 
+	update-rc.d payara defaults > /dev/null 
 	
 	echo "starting Payara..."
 	
@@ -149,6 +178,14 @@ installService() {
 	esac
 }
 
+configureOSE
+
+if [ "$JDK" = "ORACLE" ]; then
+   installOracleJDK8
+else
+   installOpenJDK7
+fi
+
 installPayara
 
 if [ $PAYARA_ED = $WEB                 ] ||
-- 
2.39.5