Run onos-local with Bazel-provided remote JDK

That's it, no need to have a JDK installed in your host system.

Unfortunately the Bazel remote JDK targets don't expose some files
required by Karaf at runtime (conf/security). The workaround for
now is to check them in here, but we should consider fixing the Bazel
rules upstream.

Change-Id: Ib003b1589d326655c1cf5f329ebe48b0c946743f
diff --git a/tools/package/onos-run-karaf b/tools/package/onos-run-karaf
index 4718f45..e898006 100755
--- a/tools/package/onos-run-karaf
+++ b/tools/package/onos-run-karaf
@@ -4,6 +4,7 @@
 # -----------------------------------------------------------------------------
 
 ONOS_TAR=
+JDK_TAR=
 
 [ -f $ONOS_TAR ] || (echo "$ONOS_TAR not found" && exit 1)
 
@@ -27,6 +28,28 @@
   *)        md5cmd='md5sum';;
 esac
 
+# Use provided JDK as JAVA_HOME if given
+if [[ -f ${JDK_TAR} ]]; then
+    JDK_DIR=$ONOS_DIR-jdk
+    JDK_MD5=$JDK_DIR/CHECKSUM
+
+    oldJdkMD5=$(cat $JDK_MD5 2>/dev/null)
+    newJdkMD5=$(${md5cmd} ${md5cmdprm} $JDK_TAR)
+
+    if [[ ! -d ${JDK_DIR} || "$oldJdkMD5" != "$newJdkMD5" ]]; then
+        echo "Unpacking JDK in ${JDK_DIR} (from $JDK_TAR)..."
+        # Unroll new JDK from the specified tar file
+        rm -fr $JDK_DIR
+        mkdir $JDK_DIR
+        tar zxf $JDK_TAR -C $JDK_DIR --strip-components 1
+        echo "$newJdkMD5" > $JDK_MD5
+    else
+        echo "Using JDK in ${JDK_DIR}..."
+    fi
+    # Use the extracted JDK as our new JAVA_HOME
+    export JAVA_HOME=${JDK_DIR}
+fi
+
 oldMD5=$(cat $ONOS_MD5 2>/dev/null)
 newMD5=$(${md5cmd} ${md5cmdprm} $ONOS_TAR)