Home > Java, Mac administration, Mac OS X, Scripting > Automating Oracle Java 8 updates

Automating Oracle Java 8 updates

To go along with my earlier post about automating Oracle Java 7 updates, I’ve also posted a script to download and install the latest Java 8 update from Oracle. The method is identical, with the exception of referring to Java 8’s SUFeedURL value in Java 8’s /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist file.

Screen Shot 2014-08-16 at 10.31.44 PM

For more information, see below the jump.

The script below will download a disk image containing the latest version of Java 8 from Oracle and install Java 8 using the installer package stored inside the downloaded disk image.

How the script works:

  1. Uses curl to download a disk image containing the latest Java 8 installer from Oracle’s web site.
  2. Renames the downloaded disk image to java_eight.dmg and stores it in /tmp.
  3. Mounts the disk image silently in /tmp. The mounted disk image will not be visible to any logged-in user.
  4. Installs the latest Java 8 using the installer package stored on the disk image.
  5. After installation, unmounts the disk image and removes it from the Mac in question.


#!/bin/bash
# This script downloads and installs the latest Oracle Java 8 for compatible Macs
# Determine OS version
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
# Specify the "OracleUpdateXML" variable by adding the "SUFeedURL" value included in the
# /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist file.
#
# Note: The "OracleUpdateXML" variable is currently specified in the script as that for
# Java 8 Update 20, but the XML address embedded with Java 8 Update 20 is not special in
# this regard. I have verified that using the address for Java 8 Update 5 will also work
# to pull the address of the latest Oracle Java 8 installer disk image. To get the "SUFeedURL"
# value embedded with your currently installed version of Java 8 on Mac OS X, please run
# the following command in Terminal:
#
# defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info" SUFeedURL
#
# As of Java 8 Update 20, that produces the following return:
#
# https://javadl-esd-secure.oracle.com/update/mac/au-1.8.0_20.xml
#
OracleUpdateXML="https://javadl-esd-secure.oracle.com/update/mac/au-1.8.0_20.xml"
# Use the XML address defined in the OracleUpdateXML variable to query Oracle via curl
# for the complete address of the latest Oracle Java 8 installer disk image.
fileURL=`/usr/bin/curl –silent $OracleUpdateXML | awk -F \" /enclosure/'{print $(NF-1)}'`
# Specify name of downloaded disk image
java_eight_dmg="$3/tmp/java_eight.dmg"
if [[ ${osvers} -lt 7 ]]; then
echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
fi
if [[ ${osvers} -ge 7 ]]; then
# Download the latest Oracle Java 8 software disk image
# The curl -L option is needed because there is a redirect
# that the requested page has moved to a different location.
/usr/bin/curl –retry 3 -Lo "$java_eight_dmg" "$fileURL"
# Specify a /tmp/java_eight.XXXX mountpoint for the disk image
TMPMOUNT=`/usr/bin/mktemp -d "$3"/tmp/java_eight.XXXX`
# Mount the latest Oracle Java 8 disk image to /tmp/java_eight.XXXX mountpoint
hdiutil attach "$java_eight_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
# Install Oracle Java 8 from the installer package. This installer may
# be stored inside an install application on the disk image, or there
# may be an installer package available at the root of the mounted disk
# image.
if [[ -e "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.app \))/Contents/Resources/JavaAppletPlugin.pkg" ]]; then
/usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.app \))/Contents/Resources/JavaAppletPlugin.pkg" -target "$3"
fi
if [[ -e "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.pkg -o -iname \*\.mpkg \))" ]]; then
/usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.pkg -o -iname \*\.mpkg \))" -target "$3"
fi
# Clean-up
# Unmount the Oracle Java 8 disk image from /tmp/java_eight.XXXX
/usr/bin/hdiutil detach -force "$TMPMOUNT"
# Remove the /tmp/java_eight.XXXX mountpoint
/bin/rm -rf "$TMPMOUNT"
# Remove the downloaded disk image
/bin/rm -rf "$java_eight_dmg"
fi
exit 0

view raw

gistfile1.sh

hosted with ❤ by GitHub

I’ve posted the script to my GitHub repo at the following address:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/install_latest_oracle_java_8

This script is also available as a payload-free installer package, stored as a .zip file in the payload_free_installer directory.

  1. Anver
    November 26, 2015 at 8:34 am

    Hi Rich

    The script seems not to work anymore. Since the update 65. Any idea?

  1. No trackbacks yet.

Leave a comment