Home > Java, Mac administration, Mac OS X, Scripting > Deploying Java for Mac OS X 10.6 Update 12 using the softwareupdate tool

Deploying Java for Mac OS X 10.6 Update 12 using the softwareupdate tool

With the latest round of Java browser blockages and updates being released, I wanted a way to deploy Apple’s Java for Mac OS X 10.6 Update 12 to those 10.6.x Macs that needed it. However, I wanted to make sure that I wasn’t deploying to machines that already had it. I also didn’t want to do a general Apple software update, I just wanted to update Java.

Fortunately, Apple’s softwareupdate command-line tool gives me a way to do this. I’m able to use the softwareupdate tool to list all available updates, then grep the list to see if the Java update I want is included:

softwareupdate -l | grep "Java"

For Macs that haven’t had Java for Mac OS X 10.6 Update 12 installed, the update should be named and described as follows:

   * JavaForMacOSX10.6-12.0
	Java for Mac OS X 10.6 Update 12 (12.0), 70724K [recommended]

Screen Shot 2013-02-04 at 12.02.13 PM

The name that softwareupdate uses for the update will appear as the first item listed. In this case, it’s JavaForMacOSX10.6-12.0. I can also use softwareupdate to specify and install that update:

softwareupdate --install JavaForMacOSX10.6-12.0

I then wrote the following script that uses softwareupdate to install Java for Mac OS X 10.6 Update 12. It does the following:

1. Verify that Java for Mac OS X 10.6 Update 12 is an available update for this Mac.

2. If Java for Mac OS X 10.6 Update 12 is an available update, the script logs that the update is being installed. Apple’s softwareupdate tool then installs that update silently in the background.

3. If Java for Mac OS X 10.6 Update 12 is not an available update, the script logs that information then exits silently.

#!/bin/sh

#
# Using the softwareupdate tool
# to detect if the Mac has
# Java for Mac OS X 10.6 Update 12
# as an available update.
#

JAVA_UPDATE_DETECT=$( softwareupdate -l | grep -o "JavaForMacOSX10.6-12.0" )

#
# If Java for Mac OS X 10.6 Update 12
# is an available update, script installs
# the update. If Java for Mac OS X 10.6 Update 12 is
# not an available update, script reports that and
# exits.
#

if [[ "${JAVA_UPDATE_DETECT}" = "JavaForMacOSX10.6-12.0" ]]; then
      logger "Installing Java for Mac OS X 10.6 Update 12"
      softwareupdate --install JavaForMacOSX10.6-12.0
   else
      logger "Java for Mac OS X 10.6 Update 12 not an available update. Exiting."
fi

exit 0

This script is available here on my GitHub repo:

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

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: