Skip to main content
Question

Autoupdate Java by shell


peterlbk
Forum|alt.badge.img+11

Hi all!

inspired by the great @rtrouton , I adjusted his superb script on installing Java.

I added a check to see if java has been installed or if a newer version is available, a bit like my Flash Update script, for which I borrowed heavily on other guys work.

Hope you guys can use this, and if you have any suggestions, please let me know!

1#!/bin/bash -e
2
3# This script downloads and installs the latest Oracle Java 8 for compatible Macs
4
5# Determine OS version
6osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
7
8# Specify the "OracleUpdateXML" variable by adding the "SUFeedURL" value included in the
9# /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist file.
10#
11# Note: The "OracleUpdateXML" variable is currently specified in the script as that for
12# Java 8 Update 20, but the XML address embedded with Java 8 Update 20 is not special in
13# this regard. I have verified that using the address for Java 8 Update 5 will also work
14# to pull the address of the latest Oracle Java 8 installer disk image. To get the "SUFeedURL"
15# value embedded with your currently installed version of Java 8 on Mac OS X, please run
16# the following command in Terminal:
17#
18# defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info" SUFeedURL
19#
20# As of Java 8 Update 20, that produces the following return:
21#
22# https://javadl-esd-secure.oracle.com/update/mac/au-1.8.0_20.xml
23#
24
25OracleUpdateXML="https://javadl-esd-secure.oracle.com/update/mac/au-1.8.0_20.xml"
26
27# check if newer version exists
28plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
29if [ -f "$plugin" ]
30then
31 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
32 echo " Current version is $currentver"
33 currentvermain=${currentver:5:1}
34 echo "Installed main version is $currentvermain"
35 currentvermin=${currentver:14:2}
36 echo "Installed minor version is $currentvermin"
37 /usr/bin/curl --retry 3 -Lo /tmp/au-1.8.0_20.xml $OracleUpdateXML
38 onlineversion1=`cat /tmp/au-1.8.0_20.xml | awk -F " /enclosure/'{print $(NF-1)}'`
39 onlineversion2=${onlineversion1:50:8}
40 onlineversionmain=${onlineversion2:2:1}
41 echo "Online main: $onlineversionmain"
42 onlineversionmin=${onlineversion2:6:2}
43 echo "Online minor: $onlineversionmin"
44 if [ "$onlineversionmain" -gt "$currentvermain" ]
45 then
46 echo "Let's install Java! Main online version is higher than installed version."
47 installjava=1
48 fi
49 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" -gt "$currentvermin" ]
50 then
51 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
52 installjava=1
53 fi
54 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" = "$currentvermin" ]
55 then
56 echo "Java is up-to-date!"
57 fi
58else
59 echo "No java installed, let's install"
60 installjava=1
61fi
62
63
64# Use the XML address defined in the OracleUpdateXML variable to query Oracle via curl
65# for the complete address of the latest Oracle Java 8 installer disk image.
66
67
68fileURL=`/usr/bin/curl --silent $OracleUpdateXML | awk -F " /enclosure/'{print $(NF-1)}'`
69
70# Specify name of downloaded disk image
71
72java_eight_dmg="/tmp/java_eight.dmg"
73
74if [[ ${osvers} -lt 7 ]]; then
75 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
76 exit 0
77fi
78if [ "$installjava" = 1 ]
79then
80 echo "Start installing Java"
81 if [[ ${osvers} -ge 7 ]]; then
82
83 # Download the latest Oracle Java 8 software disk image
84 # The curl -L option is needed because there is a redirect
85 # that the requested page has moved to a different location.
86
87 /usr/bin/curl --retry 3 -Lo "$java_eight_dmg" "$fileURL"
88
89 # Specify a /tmp/java_eight.XXXX mountpoint for the disk image
90
91 TMPMOUNT=`/usr/bin/mktemp -d /tmp/java_eight.XXXX`
92
93 # Mount the latest Oracle Java 8 disk image to /tmp/java_eight.XXXX mountpoint
94
95 hdiutil attach "$java_eight_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
96
97 # Install Oracle Java 8 from the installer package. This installer may
98 # be stored inside an install application on the disk image, or there
99 # may be an installer package available at the root of the mounted disk
100 # image.
101
102 if [[ -e "$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *.app ))/Contents/Resources/*Java*.pkg" ]]; then
103 pkg_path="$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *.app ))/Contents/Resources/*Java*.pkg"
104 elif [[ -e "$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *Java*.pkg -o -iname *Java*.mpkg ))" ]]; then
105 pkg_path="$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *Java*.pkg -o -iname *Java*.mpkg ))"
106 fi
107
108 # Before installation, the installer's developer certificate is checked to
109 # see if it has been signed by Oracle's developer certificate. Once the
110 # certificate check has been passed, the package is then installed.
111
112 if [[ "${pkg_path}" != "" ]]; then
113 signature_check=`/usr/sbin/pkgutil --check-signature "$pkg_path" | awk /'Developer ID Installer/{ print $5 }'`
114 if [[ ${signature_check} = "Oracle" ]]; then
115 # Install Oracle Java 8 from the installer package stored inside the disk image
116 /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" > /dev/null 2>&1
117 fi
118 fi
119
120 # Clean-up
121
122 # Unmount the Oracle Java 8 disk image from /tmp/java_eight.XXXX
123
124 /usr/bin/hdiutil detach -force "$TMPMOUNT"
125
126 # Remove the /tmp/java_eight.XXXX mountpoint
127
128 /bin/rm -rf "$TMPMOUNT"
129
130 # Remove the downloaded disk image
131
132 /bin/rm -rf "$java_eight_dmg"
133
134 # Remove xml file
135 /bin/rm -rf /tmp/au-1.8.0_20.xml
136 fi
137fi

34 replies

Forum|alt.badge.img+16
  • Honored Contributor
  • 1054 replies
  • October 6, 2015

Thanks Peter !!! :) not re-inventing the wheel is always great!!!!

C


Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • February 23, 2016

Hi Peter,
Am trying this - sometimes it shows it runs all the way through but nothing is updated and other times I get an error (see below) any ideas?

Executing Policy Autoupdate Java (Test)...
Running script Autoupdate Java...
Script exit code: 1
Script result: Current version is Java 8 Update 31
Installed main version is 8
Installed minor version is 31
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1160 100 1160 0 0 3501 0 --:--:-- --:--:-- --:--:-- 3504
Online main: 8
Online minor: 73
Let's install Java! Main online version is equal than installed version, but minor version is higher.
Start installing Java
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 915 0 915 0 0 4145 0 --:--:-- --:--:-- --:--:-- 4140
100 935 0 935 0 0 3508 0 --:--:-- --:--:-- --:--:-- 3501

2 64.2M 2 1551k 0 0 1402k 0 0:00:46 0:00:01 0:00:45 1402k
6 64.2M 6 4064k 0 0 1928k 0 0:00:34 0:00:02 0:00:32 2507k
8 64.2M 8 5626k 0 0 1802k 0 0:00:36 0:00:03 0:00:33 2021k
11 64.2M 11 7261k 0 0 1769k 0 0:00:37 0:00:04 0:00:33 1904k
13 64.2M 13 9190k 0 0 1800k 0 0:00:36 0:00:05 0:00:31 1909k
17 64.2M 17 11.3M 0 0 1912k 0 0:00:34 0:00:06 0:00:28 2024k
20 64.2M 20 13.3M 0 0 1923k 0 0:00:34 0:00:07 0:00:27 1920k
23 64.2M 23 15.2M 0 0 1919k 0 0:00:34 0:00:08 0:00:26 1991k
26 64.2M 26 17.2M 0 0 1941k 0 0:00:33 0:00:09 0:00:24 2083k
30 64.2M 30 19.3M 0 0 1961k 0 0:00:33 0:00:10 0:00:23 2126k
33 64.2M 33 21.4M 0 0 1974k 0 0:00:33 0:00:11 0:00:22 2049k
37 64.2M 37 23.9M 0 0 2024k 0 0:00:32 0:00:12 0:00:20 2169k
40 64.2M 40 26.3M 0 0 2057k 0 0:00:31 0:00:13 0:00:18 2281k
44 64.2M 44 28.6M 0 0 2077k 0 0:00:31 0:00:14 0:00:17 2323k
48 64.2M 48 30.9M 0 0 2096k 0 0:00:31 0:00:15 0:00:16 2369k
51 64.2M 51 33.1M 0 0 2107k 0 0:00:31 0:00:16 0:00:15 2403k
54 64.2M 54 35.1M 0 0 2104k 0 0:00:31 0:00:17 0:00:14 2297k
59 64.2M 59 38.2M 0 0 2164k 0 0:00:30 0:00:18 0:00:12 2444k
64 64.2M 64 41.5M 0 0 2229k 0 0:00:29 0:00:19 0:00:10 2657k
69 64.2M 69 44.5M 0 0 2268k 0 0:00:28 0:00:20 0:00:08 2788k
72 64.2M 72 46.6M 0 0 2263k 0 0:00:29 0:00:21 0:00:08 2766k
77 64.2M 77 49.5M 0 0 2295k 0 0:00:28 0:00:22 0:00:06 2947k
82 64.2M 82 52.9M 0 0 2347k 0 0:00:28 0:00:23 0:00:05 3009k
87 64.2M 87 56.4M 0 0 2399k 0 0:00:27 0:00:24 0:00:03 3052k
92 64.2M 92 59.6M 0 0 2434k 0 0:00:27 0:00:25 0:00:02 3101k
98 64.2M 98 63.4M 0 0 2487k 0 0:00:26 0:00:26 --:--:-- 3432k
100 64.2M 100 64.2M 0 0 2497k 0 0:00:26 0:00:26 --:--:-- 3558k
hdiutil: attach failed - No such file or directory


davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • February 23, 2016

Thanks, I was looking for this just the other day. Much appreciated. Saved me a pile of work!!


Wakko
Forum|alt.badge.img+19
  • Valued Contributor
  • 89 replies
  • April 1, 2016

Any update form dshumatetaos post. It fails to update, this is the results I'm getting.

Script result: Current version is Java 8 Update 73 build 02
Installed main version is 8
Installed minor version is 73
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1160 100 1160 0 0 6054 0 --:--:-- --:--:-- --:--:-- 6073
Online main: 8
Online minor: 77
Let's install Java! Main online version is equal than installed version, but minor version is higher.
Start installing Java
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 935 0 935 0 0 4529 0 --:--:-- --:--:-- --:--:-- 4538

4 64.2M 4 3201k 0 0 3838k 0 0:00:17 --:--:-- 0:00:17 3838k
15 64.2M 15 9.9M 0 0 5580k 0 0:00:11 0:00:01 0:00:10 7034k
24 64.2M 24 15.9M 0 0 5758k 0 0:00:11 0:00:02 0:00:09 6558k
34 64.2M 34 22.0M 0 0 5900k 0 0:00:11 0:00:03 0:00:08 6473k
44 64.2M 44 28.5M 0 0 6058k 0 0:00:10 0:00:04 0:00:06 6520k
54 64.2M 54 34.9M 0 0 6128k 0 0:00:10 0:00:05 0:00:05 6509k
64 64.2M 64 41.4M 0 0 6217k 0 0:00:10 0:00:06 0:00:04 6450k
74 64.2M 74 47.6M 0 0 6234k 0 0:00:10 0:00:07 0:00:03 6503k
83 64.2M 83 53.4M 0 0 6200k 0 0:00:10 0:00:08 0:00:02 6430k
92 64.2M 92 59.6M 0 0 6213k 0 0:00:10 0:00:09 0:00:01 6362k
100 64.2M 100 64.2M 0 0 6249k 0 0:00:10 0:00:10 --:--:-- 6398k
/dev/disk4 GUID_partition_scheme /dev/disk4s1 Apple_HFS /private/tmp/java_eight.EJ9s
"disk4" unmounted.
"disk4" ejected.


peterlbk
Forum|alt.badge.img+11
  • Author
  • Jamf Heroes
  • 68 replies
  • April 1, 2016

Hi All, and especially @dshumatetaos and @Echevarria just tested it again with this script and all worked well. Please let me know if this one still gives errors.

1#!/bin/sh -x
2# Determine OS version
3osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
4
5# check if newer version exists
6plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
7if [ -f "$plugin" ]
8then
9 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
10 echo " Current version is $currentver"
11 currentvermain=${currentver:5:1}
12 echo "Installed main version is $currentvermain"
13 currentvermin=${currentver:14:2}
14 echo "Installed minor version is $currentvermin"
15 onlineversionmain=`curl http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $4}'`
16 echo "Online main: $onlineversionmain"
17 onlineversionmin1=`curl http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $6}'`
18 onlineversionmin=${onlineversionmin1:0:2}
19 echo "Online minor: $onlineversionmin"
20 if [ -z "$currentvermain" ] || [ "$onlineversionmain" -gt "$currentvermain" ]
21 then
22 echo "Let's install Java! Main online version is higher than installed version."
23 installjava=1
24 fi
25 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" -gt "$currentvermin" ]
26 then
27 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
28 installjava=1
29 fi
30 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" = "$currentvermin" ]
31 then
32 echo "Java is up-to-date!"
33 fi
34else
35 echo "No java installed, let's install"
36 installjava=1
37fi
38
39
40# Find Download URL
41fileURL=`curl http://www.java.com/en/download/manual.jsp | grep "Download Java for Mac OS X" | awk -F """ '{ print $4;exit}'`
42
43
44# Specify name of downloaded disk image
45
46java_eight_dmg="/tmp/java_eight.dmg"
47
48if [[ ${osvers} -lt 7 ]]; then
49 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
50 exit 0
51fi
52if [ "$installjava" = 1 ]
53then
54 echo "Start installing Java"
55 if [[ ${osvers} -ge 7 ]]; then
56 /usr/bin/curl --retry 3 -Lo "$java_eight_dmg" "$fileURL"
57
58 # Specify a /tmp/java_eight.XXXX mountpoint for the disk image
59
60 TMPMOUNT=`/usr/bin/mktemp -d /tmp/java_eight.XXXX`
61
62 # Mount the latest Oracle Java 8 disk image to /tmp/java_eight.XXXX mountpoint
63
64 hdiutil attach "$java_eight_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
65
66 # Find the Java installer
67
68 JAVAVOL=`ls /Volumes/ | grep "Java"`
69 JAVAAPP=`ls "$TMPMOUNT" | grep "Java"`
70 pkg_path=`ls "$TMPMOUNT"/"$JAVAAPP"/Contents/Resources/*Java*.pkg`
71
72 # Check installer certificate
73
74 if [[ "${pkg_path}" != "" ]]; then
75 signature_check=`/usr/sbin/pkgutil --check-signature "$pkg_path" | awk /'Developer ID Installer/{ print $5 }'`
76 if [[ ${signature_check} = "Oracle" ]]; then
77 # Install Oracle Java 8 from the installer package stored inside the disk image
78 /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" > /dev/null 2>&1
79 fi
80 fi
81
82 # Clean-up
83
84 # Unmount the Oracle Java 8 disk image from /tmp/java_eight.XXXX
85
86 /usr/bin/hdiutil detach -force "$TMPMOUNT"
87
88 # Remove the /tmp/java_eight.XXXX mountpoint
89
90 /bin/rm -rf "$TMPMOUNT"
91
92 # Remove the downloaded disk image
93
94 /bin/rm -rf "$java_eight_dmg"
95
96 fi
97fi

Forum|alt.badge.img+5
  • Contributor
  • 46 replies
  • June 16, 2016

Hey @peterloobuyck -- Same issue here as @dshumatetaos and @Echevarria ... I have tried both script versions you have on this site; it seems to try and do "stuff" but the version does not change after the script runs:

1Checking for policies triggered by "java" for user "ryan.s"...
2Executing Policy Java (JRE) Updater
3Mounting NA-US-CA-Fremont-Office to /Volumes/casper...
4Getting package details from https://jss.teslamotors.com:8443/...
5Uninstalling...
6 Looking for Applications...
7 Deleting files...
8Uninstalled oracle_java_jre_7u67.dmg.
9Getting package details from https://jss.teslamotors.com:8443/...
10Uninstalling...
11 Looking for Applications...
12 Deleting files...
13Uninstalled oracle_java_jre_8u65.dmg.
14Running script App_JavaJRE-autoupd...
15Script exit code: 0
16Script result: ++ sw_vers -productVersion
17++ awk -F. '{print $2}'
18+ osvers=11
19+ plugin='/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist'
20+ '[' -f '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist' ']'
21+ echo 'No java installed, let'''s install'
22No java installed, let's install
23+ installjava=1
24++ curl http://www.java.com/en/download/manual.jsp
25++ grep 'Download Java for Mac OS X'
26++ awk -F '"' '{ print $4;exit}'
27 % Total % Received % Xferd Average Speed Time Time Time Current
28 Dload Upload Total Spent Left Speed
29100 23151 100 23151 0 0 294k 0 --:--:-- --:--:-- --:--:-- 297k
30+ fileURL='http://javadl.oracle.com/webapps/download/AutoDL?BundleId=207766'
31+ java_eight_dmg=/tmp/java_eight.dmg
32+ [[ 11 -lt 7 ]]
33+ '[' 1 = 1 ']'
34+ echo 'Start installing Java'
35Start installing Java
36+ [[ 11 -ge 7 ]]
37+ /usr/bin/curl --retry 3 -Lo /tmp/java_eight.dmg 'http://javadl.oracle.com/webapps/download/AutoDL?BundleId=207766'
38 % Total % Received % Xferd Average Speed Time Time Time Current
39 Dload Upload Total Spent Left Speed
40100 755 0 755 0 0 1233 0 --:--:-- --:--:-- --:--:-- 1235
41100 64.2M 100 64.2M 0 0 24.1M 0 0:00:02 0:00:02 --:--:-- 33.6M
42++ /usr/bin/mktemp -d /tmp/java_eight.XXXX
43+ TMPMOUNT=/tmp/java_eight.TjzG
44+ hdiutil attach /tmp/java_eight.dmg -mountpoint /tmp/java_eight.TjzG -nobrowse -noverify -noautoopen
45/dev/disk3 GUID_partition_scheme
46/dev/disk3s1 Apple_HFS /private/tmp/java_eight.TjzG
47++ ls /Volumes/
48++ grep Java
49+ JAVAVOL=
50++ ls /tmp/java_eight.TjzG
51++ grep Java
52+ JAVAAPP='Java 8 Update 91.app'
53++ ls '/tmp/java_eight.TjzG/Java 8 Update 91.app/Contents/Resources/JavaAppletPlugin.pkg'
54+ pkg_path='/tmp/java_eight.TjzG/Java 8 Update 91.app/Contents/Resources/JavaAppletPlugin.pkg'
55+ [[ /tmp/java_eight.TjzG/Java 8 Update 91.app/Contents/Resources/JavaAppletPlugin.pkg != '' ]]
56++ /usr/sbin/pkgutil --check-signature '/tmp/java_eight.TjzG/Java 8 Update 91.app/Contents/Resources/JavaAppletPlugin.pkg'
57++ awk '/Developer ID Installer/{ print $5 }'
58+ signature_check=Oracle
59+ [[ Oracle = O
60acle ]]
61+ /usr/sbin/installer -dumplog -verbose -pkg '/tmp/java_eight.TjzG/Java 8 Update 91.app/Contents/Resources/JavaAppletPlugin.pkg' -target /
62+ /usr/bin/hdiutil detach -force /tmp/java_eight.TjzG
63"disk3" unmounted.
64"disk3" ejected.
65+ /bin/rm -rf /tmp/java_eight.TjzG
66+ /bin/rm -rf /tmp/java_eight.dmg
67
68Unmounting file server...

Looking at my Casper inventory: Java 8 Update 60.app Java 8 Update 60 build 27 /Users/ryan.s/Library/Application Support/Java/Java 1.8.60.27/Java 8 Update 60.app No

I'm trying to debug, can I cannot seem to find anything broken...


peterlbk
Forum|alt.badge.img+11
  • Author
  • Jamf Heroes
  • 68 replies
  • June 20, 2016

Hi guys, @ryan.s @davidacland @Echevarria

Seems you're right, Oracle played with its own installer app.

Can you test the script underneath? I made some changes and tests in my testlab seems to be ok...

1#!/bin/bash -e
2
3# This script downloads and installs the latest Oracle Java 8 for compatible Macs
4
5# Determine OS version
6osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
7
8OracleUpdateXML="https://javadl-esd-secure.oracle.com/update/mac/au-1.8.0_20.xml"
9
10# check if newer version exists
11plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
12if [ -f "$plugin" ]
13then
14 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
15 echo " Current version is $currentver"
16 currentvermain=${currentver:5:1}
17 echo "Installed main version is $currentvermain"
18 currentvermin=${currentver:14:2}
19 echo "Installed minor version is $currentvermin"
20 /usr/bin/curl --retry 3 -Lo /tmp/au-1.8.0_20.xml $OracleUpdateXML
21 onlineversion1=`cat /tmp/au-1.8.0_20.xml | awk -F " /enclosure/'{print $(NF-1)}'`
22 onlineversion2=${onlineversion1:50:8}
23 onlineversionmain=${onlineversion2:2:1}
24 echo "Online main: $onlineversionmain"
25 onlineversionmin=${onlineversion2:6:2}
26 echo "Online minor: $onlineversionmin"
27 if [ "$onlineversionmain" -gt "$currentvermain" ]
28 then
29 echo "Let's install Java! Main online version is higher than installed version."
30 installjava=1
31 fi
32 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" -gt "$currentvermin" ]
33 then
34 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
35 installjava=1
36 fi
37 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" = "$currentvermin" ]
38 then
39 echo "Java is up-to-date!"
40 fi
41else
42 echo "No java installed, let's install"
43 installjava=1
44fi
45
46
47# Use the XML address defined in the OracleUpdateXML variable to query Oracle via curl
48# for the complete address of the latest Oracle Java 8 installer disk image.
49
50
51fileURL=`/usr/bin/curl --silent $OracleUpdateXML | awk -F " /enclosure/'{print $(NF-1)}'`
52
53# Specify name of downloaded disk image
54
55java_eight_dmg="/tmp/java_eight.dmg"
56
57if [[ ${osvers} -lt 7 ]]; then
58 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
59 exit 0
60fi
61if [ "$installjava" = 1 ]
62then
63 echo "Start installing Java"
64 if [[ ${osvers} -ge 7 ]]; then
65
66 # Download the latest Oracle Java 8 software disk image
67
68 /usr/bin/curl --retry 3 -Lo "$java_eight_dmg" "$fileURL"
69
70 # Specify a /tmp/java_eight.XXXX mountpoint for the disk image
71
72 TMPMOUNT=`/usr/bin/mktemp -d /Volumes/java_eight.XXXX`
73
74 # Mount the latest Oracle Java disk image to /tmp/java_eight.XXXX mountpoint
75
76 hdiutil attach "$java_eight_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
77
78 # Install Oracle Java 8 from the installer package.
79
80 if [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.pkg)" ]]; then
81 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.pkg`
82 elif [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.mpkg)" ]]; then
83 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.mpkg`
84 fi
85
86 # Before installation, the installer's developer certificate is checked
87
88 if [[ "${pkg_path}" != "" ]]; then
89 echo "installing Java from ${pkg_path}..."
90 /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" > /dev/null 2>&1
91
92 fi
93
94 # Clean-up
95
96 # Unmount the disk image from /tmp/java_eight.XXXX
97
98 /usr/bin/hdiutil detach -force "$TMPMOUNT"
99
100 # Remove the /tmp/java_eight.XXXX mountpoint
101
102 /bin/rm -rf "$TMPMOUNT"
103
104 # Remove the downloaded disk image
105
106 /bin/rm -rf "$java_eight_dmg"
107
108 # Remove xml file
109 /bin/rm -rf /tmp/au-1.8.0_20.xml
110 fi
111fi

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • June 20, 2016

Thanks, works ok for me.


Forum|alt.badge.img+12
  • Contributor
  • 288 replies
  • July 20, 2016

..


Forum|alt.badge.img+12
  • Contributor
  • 288 replies
  • July 21, 2016

The current script is erroring ever since Oracle released a 3 digit version number.

The $onlineversionmin variable is returning 10 instead of 101. $onlineversion2 also returning 1.8.0_10 instead of 1.8.0_101

While using variables like the below work for two digit version numbers, they break when Oracle released version 101. onlineversion2=${onlineversion1:50:9} onlineversionmain=${onlineversion2:2:1}

I'm making some modifications on the script to allow support for both two and three digit version numbers.
I changed it so that if Java isn't installed, it exits. (we didn't want users in our environment to get java installed if they didn't have it).

Also added functionality to remove the /tmp/au-1.8.0_20.xml once the script ran regardless if it installs or not. Previously it removed if the software needed to be updated.

1#!/bin/bash
2
3# This script downloads and installs the latest Oracle Java 8 for Macs
4
5# Determine OS version
6osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
7
8OracleUpdateXML="https://javadl-esd-secure.oracle.com/update/mac/au-1.8.0_20.xml"
9
10# check if newer version exists
11plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
12if [ -f "$plugin" ]
13then
14 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
15 echo " Current version is $currentver"
16
17 currentvermain=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString | awk '{print $2}'`
18 echo "Installed main version is $currentvermain"
19
20 currentvermin=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString | awk '{print $4}'`
21 echo "Installed minor version is $currentvermin"
22
23 /usr/bin/curl --retry 3 -Lo /tmp/au-1.8.0_20.xml $OracleUpdateXML
24
25 onlineversion1=`cat /tmp/au-1.8.0_20.xml | awk -F " /enclosure/'{print $(NF-1)}' | grep -oE 'd.d.{1,2}d_d{1,3}'`
26
27 onlineversionmain=`cat /tmp/au-1.8.0_20.xml | awk -F " /enclosure/'{print $(NF-1)}' | grep -oE 'd.d.{1,2}d_d{1,3}' | cut -d '.' -f2`
28
29 echo "Online main: $onlineversionmain"
30 onlineversionmin=`cat /tmp/au-1.8.0_20.xml | awk -F " /enclosure/'{print $(NF-1)}' | grep -oE 'd.d.{1,2}d_d{1,3}' | cut -d "_" -f 2`
31 echo "Online minor: $onlineversionmin"
32
33
34 if [ "$onlineversionmain" -gt "$currentvermain" ]
35 then
36 echo "Java version is newer than installed version."
37 installjava=1
38 fi
39 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" -gt "$currentvermin" ]
40 then
41 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
42 installjava=1
43 fi
44 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" = "$currentvermin" ]
45 then
46 echo "Java is up-to-date!"
47 # Remove xml file
48 /bin/rm -rf /tmp/au-1.8.0_20.xml
49 fi
50else
51 echo "No java installed, exit"
52 installjava=0
53 # Remove xml file
54 /bin/rm -rf /tmp/au-1.8.0_20.xml
55fi
56
57
58# Use the XML address defined in the OracleUpdateXML variable to query Oracle via curl
59# for the complete address of the latest Oracle Java 8 installer disk image.
60
61
62fileURL=`/usr/bin/curl --silent $OracleUpdateXML | awk -F " /enclosure/'{print $(NF-1)}'`
63
64# Specify name of downloaded disk image
65
66java_eight_dmg="/tmp/java_eight.dmg"
67
68if [[ ${osvers} -lt 7 ]]; then
69 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
70 exit 0
71fi
72if [ "$installjava" = 1 ]
73then
74 echo "Start installing Java"
75 if [[ ${osvers} -ge 7 ]]; then
76
77 # Download the latest Oracle Java 8 software disk image
78
79 /usr/bin/curl --retry 3 -Lo "$java_eight_dmg" "$fileURL"
80
81 # Specify a /tmp/java_eight.XXXX mountpoint for the disk image
82
83 TMPMOUNT=`/usr/bin/mktemp -d /Volumes/java_eight.XXXX`
84
85 # Mount the latest Oracle Java disk image to /tmp/java_eight.XXXX mountpoint
86
87 hdiutil attach "$java_eight_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
88
89 # Install Oracle Java 8 from the installer package.
90
91 if [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.pkg)" ]]; then
92 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.pkg`
93 elif [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.mpkg)" ]]; then
94 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.mpkg`
95 fi
96
97 # Before installation, the installer's developer certificate is checked
98
99 if [[ "${pkg_path}" != "" ]]; then
100 echo "installing Java from ${pkg_path}..."
101 /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" > /dev/null 2>&1
102
103 fi
104
105 # Clean-up
106
107 # Unmount the disk image from /tmp/java_eight.XXXX
108
109 /usr/bin/hdiutil detach -force "$TMPMOUNT"
110
111 # Remove the /tmp/java_eight.XXXX mountpoint
112
113 /bin/rm -rf "$TMPMOUNT"
114
115 # Remove the downloaded disk image
116
117 /bin/rm -rf "$java_eight_dmg"
118
119 # Remove xml file
120 /bin/rm -rf /tmp/au-1.8.0_20.xml
121 fi
122fi

peterlbk
Forum|alt.badge.img+11
  • Author
  • Jamf Heroes
  • 68 replies
  • July 27, 2016

Hi guys @bbot , since Oracle changes things a lot, I changed the script a bit. I now read the manual download page and grab versions. New script underneath

1#!/bin/sh
2# Determine OS version
3osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
4
5# check if newer version exists
6plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
7if [ -f "$plugin" ]
8then
9 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
10 echo " Current version is $currentver"
11 currentvermain=${currentver:5:1}
12 echo "Installed main version is $currentvermain"
13 currentvermin=${currentver:14:2}
14 echo "Installed minor version is $currentvermin"
15 onlineversionmain=`curl http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $4}'`
16 echo "Online main: $onlineversionmain"
17 onlineversionmin1=`curl http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $6}' | awk -F "<" '{ print $1}'`
18 onlineversionmin=${onlineversionmin1:0:3}
19 echo "Online minor: $onlineversionmin"
20 if [ -z "$currentvermain" ] || [ "$onlineversionmain" -gt "$currentvermain" ]
21 then
22 echo "Let's install Java! Main online version is higher than installed version."
23 installjava=1
24 fi
25 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" -gt "$currentvermin" ]
26 then
27 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
28 installjava=1
29 fi
30 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" = "$currentvermin" ]
31 then
32 echo "Java is up-to-date!"
33 fi
34else
35 echo "No java installed, let's install"
36 installjava=1
37fi
38
39
40# Find Download URL
41fileURL=`curl http://www.java.com/en/download/manual.jsp | grep "Download Java for Mac OS X" | awk -F """ '{ print $4;exit}'`
42
43
44# Specify name of downloaded disk image
45
46java_eight_dmg="/tmp/java_eight.dmg"
47
48if [[ ${osvers} -lt 7 ]]; then
49 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
50 exit 0
51fi

Forum|alt.badge.img+17
  • Valued Contributor
  • 404 replies
  • August 10, 2016

No chance you've got something similar for the Java JDK? ;-)


Forum|alt.badge.img+8
  • Contributor
  • 34 replies
  • August 11, 2016

@peterloobuyck

Hey buddy i wanted to see if any of the Java update scripts listed were able to address the issue with the policy completing successfully but the version is still the same. I ran this script and the following results took place but the update didn't happen:

Executing Policy Java Installation update
Running script New Java Update Script...
Script exit code: 0
Script result: Current version is Java 8 Update 73 build 02
Installed main version is 8
Installed minor version is 73
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1167 100 1167 0 0 2111 0 --:--:-- --:--:-- --:--:-- 2110
Online main: 8
Online minor: 10


Forum|alt.badge.img+12
  • Contributor
  • 288 replies
  • August 11, 2016

@bjones If you look at my post above, the issue is that the script isn't finding the new version number 101. As you can see in your log, it thinks the version number is Main 8, Minor 10, which is why the script is exiting.

See below in bold for what it should return.

Script result: Current version is Java 8 Update 71 build 15
Installed main version is 8
Installed minor version is 71
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1167 100 1167 0 0 5926 0 --:--:-- --:--:-- --:--:-- 5954
Online main: 8
Online minor: 101
Let's install Java! Main online version is equal than installed version, but minor version is higher.
Start installing Java
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 945 0 945 0 0 5708 0 --:--:-- --:--:-- --:--:-- 5762

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
7 64.3M 7 4753k 0 0 4035k 0 0:00:16 0:00:01 0:00:15 4758k
23 64.3M 23 14.9M 0 0 7008k 0 0:00:09 0:00:02 0:00:07 7638k
40 64.3M 40 26.1M 0 0 8417k 0 0:00:07 0:00:03 0:00:04 8921k
58 64.3M 58 37.3M 0 0 9152k 0 0:00:07 0:00:04 0:00:03 9564k
73 64.3M 73 47.0M 0 0 9313k 0 0:00:07 0:00:05 0:00:02 9648k
90 64.3M 90 58.3M 0 0 9666k 0 0:00:06 0:00:06 --:--:-- 10.7M
100 64.3M 100 64.3M 0 0 9810k 0 0:00:06 0:00:06 --:--:-- 10.8M
/dev/disk2 GUID_partition_scheme
/dev/disk2s1 Apple_HFS /Volumes/java_eight.DTf1
installing Java from /Volumes/java_eight.DTf1/Java 8 Update 101.app/Contents/Resources/JavaAppletPlugin.pkg...
"disk2" unmounted.
"disk2" ejected.

Try running my modified script above, it handles both 2 and 3 digit version numbers.

@peterloobuyck Have you modified your script for the new 3 digit version numbers?


peterlbk
Forum|alt.badge.img+11
  • Author
  • Jamf Heroes
  • 68 replies
  • August 12, 2016

@bjones @bbot Yep!

1#!/bin/sh
2# Determine OS version
3osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
4
5# check if newer version exists
6plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
7if [ -f "$plugin" ]
8then
9 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
10 echo " Current version is $currentver"
11 currentvermain=${currentver:5:1}
12 echo "Installed main version is $currentvermain"
13 currentvermin=${currentver:14:2}
14 echo "Installed minor version is $currentvermin"
15 onlineversionmain=`curl http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $4}'`
16 echo "Online main: $onlineversionmain"
17 onlineversionmin1=`curl http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $6}' | awk -F "<" '{ print $1}'`
18 onlineversionmin=${onlineversionmin1:0:3}
19 echo "Online minor: $onlineversionmin"
20 if [ -z "$currentvermain" ] || [ "$onlineversionmain" -gt "$currentvermain" ]
21 then
22 echo "Let's install Java! Main online version is higher than installed version."
23 installjava=1
24 fi
25 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" -gt "$currentvermin" ]
26 then
27 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
28 installjava=1
29 fi
30 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" = "$currentvermin" ]
31 then
32 echo "Java is up-to-date!"
33 fi
34else
35 echo "No java installed, let's install"
36 installjava=1
37fi
38
39
40# Find Download URL
41fileURL=`curl http://www.java.com/en/download/manual.jsp | grep "Download Java for Mac OS X" | awk -F """ '{ print $4;exit}'`
42
43
44# Specify name of downloaded disk image
45
46java_eight_dmg="/tmp/java_eight.dmg"
47
48if [[ ${osvers} -lt 7 ]]; then
49 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
50 exit 0
51fi

Forum|alt.badge.img+4
  • New Contributor
  • 14 replies
  • August 31, 2016

Made minor modification to lines 11, 13, and 18 to grab the word rather than a specific number of characters. Should keep this from needing a change (or breaking) when version numbers increase or decrease in digits.

1#!/bin/sh
2# Determine OS version
3osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
4
5# check if newer version exists
6plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
7if [ -f "$plugin" ]
8then
9 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
10 echo " Current version is $currentver"
11 currentvermain=$(echo $currentver | awk '{ print $2}')
12 echo "Installed main version is $currentvermain"
13 currentvermin=$(echo $currentver | awk '{ print $4}')
14 echo "Installed minor version is $currentvermin"
15 onlineversionmain=`curl http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $4}'`
16 echo "Online main: $onlineversionmain"
17 onlineversionmin1=`curl http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $6}' | awk -F "<" '{ print $1}'`
18 onlineversionmin=$(echo $onlineversionmin1 | awk '{ print $1}')
19 echo "Online minor: $onlineversionmin"
20 if [ -z "$currentvermain" ] || [ "$onlineversionmain" -gt "$currentvermain" ]
21 then
22 echo "Let's install Java! Main online version is higher than installed version."
23 installjava=1
24 fi
25 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" -gt "$currentvermin" ]
26 then
27 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
28 installjava=1
29 fi
30 if [ "$onlineversionmain" = "$currentvermain" ] && [ "$onlineversionmin" = "$currentvermin" ]
31 then
32 echo "Java is up-to-date!"
33 fi
34else
35 echo "No java installed, let's install"
36 installjava=1
37fi
38
39
40# Find Download URL
41fileURL=`curl http://www.java.com/en/download/manual.jsp | grep "Download Java for Mac OS X" | awk -F """ '{ print $4;exit}'`
42
43
44# Specify name of downloaded disk image
45
46java_eight_dmg="/tmp/java_eight.dmg"
47
48if [[ ${osvers} -lt 7 ]]; then
49 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
50 exit 0
51fi
52if [ "$installjava" = 1 ]
53then
54 echo "Start installing Java"
55 if [[ ${osvers} -ge 7 ]]; then
56
57 # Download the latest Oracle Java 8 software disk image
58
59 /usr/bin/curl --retry 3 -Lo "$java_eight_dmg" "$fileURL"
60
61 # Specify a /tmp/java_eight.XXXX mountpoint for the disk image
62
63 TMPMOUNT=`/usr/bin/mktemp -d /Volumes/java_eight.XXXX`
64
65 # Mount the latest Oracle Java disk image to /tmp/java_eight.XXXX mountpoint
66
67 hdiutil attach "$java_eight_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
68
69 # Install Oracle Java 8 from the installer package.
70
71 if [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.pkg)" ]]; then
72 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.pkg`
73 elif [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.mpkg)" ]]; then
74 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.mpkg`
75 fi
76
77 # Before installation, the installer's developer certificate is checked
78
79 if [[ "${pkg_path}" != "" ]]; then
80 echo "installing Java from ${pkg_path}..."
81 /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" > /dev/null 2>&1
82
83 fi
84
85 # Clean-up
86
87 # Unmount the disk image from /tmp/java_eight.XXXX
88
89 /usr/bin/hdiutil detach -force "$TMPMOUNT"
90
91 # Remove the /tmp/java_eight.XXXX mountpoint
92
93 /bin/rm -rf "$TMPMOUNT"
94
95 # Remove the downloaded disk image
96
97 /bin/rm -rf "$java_eight_dmg"
98
99 # Remove xml file
100 /bin/rm -rf /tmp/au-1.8.0_20.xml
101 fi
102fi

Forum|alt.badge.img+17
  • Valued Contributor
  • 404 replies
  • November 8, 2016

@Rocky I'm getting an error in line 20 when it tries to get/use (?) the minor version.

1Online minor:
2./test.sh: line 20: [: : integer expression expected

I'm running Java 8 Update 111 build 14 on my test machine.

1 Current version is Java 8 Update 111 build 14
2Installed main version is 8
3Installed minor version is 111

peterlbk
Forum|alt.badge.img+11
  • Author
  • Jamf Heroes
  • 68 replies
  • November 8, 2016

@cwaldrip and @Rocky

Did some cleaning up. You should be able to use this one... Oracle did some changes on their website...

1#!/bin/sh
2# Determine OS version
3osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
4
5# check if newer version exists
6plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
7if [ -f "$plugin" ]
8then
9 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
10 echo " Current version is $currentver"
11 currentvermain=${currentver:5:1}
12 echo "Installed main version is $currentvermain"
13 currentvermin=${currentver:14:3}
14 echo "Installed minor version is $currentvermin"
15 onlineversionmain=`curl -L http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $4}'`
16 echo "Online main: $onlineversionmain"
17 onlineversionmin1=`curl -L http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $6}' | awk -F "<" '{ print $1}'`
18 onlineversionmin=${onlineversionmin1:0:3}
19 echo "Online minor: $onlineversionmin"
20 if [ -z "${currentvermain}" ] || [ "${onlineversionmain}" -gt "${currentvermain}" ]
21 then
22 echo "Let's install Java! Main online version is higher than installed version."
23 installjava=1
24 fi
25 if [ "${onlineversionmain}" = "${currentvermain}" ] && [ "${onlineversionmin}" -gt "${currentvermin}" ]
26 then
27 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
28 installjava=1
29 fi
30 if [ "${onlineversionmain}" = "${currentvermain}" ] && [ "${onlineversionmin}" = "${currentvermin}" ]
31 then
32 echo "Java is up-to-date!"
33 fi
34else
35 echo "No java installed, let's install"
36 installjava=1
37fi
38
39
40# Find Download URL
41fileURL=`curl -L http://www.java.com/en/download/manual.jsp | grep "Download Java for Mac OS X" | awk -F """ '{ print $4;exit}'`
42
43
44# Specify name of downloaded disk image
45
46java_eight_dmg="/tmp/java_eight.dmg"
47
48if [[ ${osvers} -lt 7 ]]; then
49 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
50 exit 0
51fi
52
53if [ "$installjava" = 1 ]
54then
55 echo "Start installing Java"
56 if [[ ${osvers} -ge 7 ]]; then
57
58 # Download the latest Oracle Java 8 software disk image
59
60 /usr/bin/curl --retry 3 -Lo "$java_eight_dmg" "$fileURL"
61
62 # Specify a /tmp/java_eight.XXXX mountpoint for the disk image
63
64 TMPMOUNT=`/usr/bin/mktemp -d /Volumes/java_eight.XXXX`
65
66 # Mount the latest Oracle Java disk image to /tmp/java_eight.XXXX mountpoint
67
68 hdiutil attach "$java_eight_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
69
70 # Install Oracle Java 8 from the installer package.
71
72 if [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.pkg)" ]]; then
73 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.pkg`
74 elif [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.mpkg)" ]]; then
75 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.mpkg`
76 fi
77
78 # Before installation, the installer's developer certificate is checked
79
80 if [[ "${pkg_path}" != "" ]]; then
81 echo "installing Java from ${pkg_path}..."
82 /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" > /dev/null 2>&1
83
84 fi
85
86 # Clean-up
87
88 # Unmount the disk image from /tmp/java_eight.XXXX
89
90 /usr/bin/hdiutil detach -force "$TMPMOUNT"
91
92 # Remove the /tmp/java_eight.XXXX mountpoint
93
94 /bin/rm -rf "$TMPMOUNT"
95
96 # Remove the downloaded disk image
97
98 /bin/rm -rf "$java_eight_dmg"
99
100 # Remove xml file
101 /bin/rm -rf /tmp/au-1.8.0_20.xml
102 fi
103fi

Forum|alt.badge.img+17
  • Valued Contributor
  • 404 replies
  • November 8, 2016

Yep, that did it. Thanks @peterloobuyck !


Forum|alt.badge.img+6
  • Contributor
  • 83 replies
  • January 18, 2017

Hmm, I tried the script posted on 11/8/16, and got this:

1Executing Policy Install Java
2Running script Install Java.sh...
3Script exit code: 0
4Script result: No java installed, let's install
5% Total % Received % Xferd Average Speed Time Time Time Current
6Dload Upload Total Spent Left Speed
7
80 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
90 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
10
110 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
120 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
130 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0
14100 36 100 36 0 0 9 0 0:00:04 0:00:03 0:00:01 16
15Start installing Java
16curl: (3) malformed
17hdiutil: attach failed - No such file or directory
18hdiutil: detach failed - No such file or directory

Any suggestions?


peterlbk
Forum|alt.badge.img+11
  • Author
  • Jamf Heroes
  • 68 replies
  • January 18, 2017

@stevenjklein Hi Steven, just ran another test and all runs smooth..

What version of MacOS did you run it on?
And just to be sure, I attach the latest version once more.

1#!/bin/sh
2# Determine OS version
3osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
4
5# check if newer version exists
6plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist"
7if [ -f "$plugin" ]
8then
9 currentver=`/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist" CFBundleShortVersionString`
10 echo " Current version is $currentver"
11 currentvermain=${currentver:5:1}
12 echo "Installed main version is $currentvermain"
13 currentvermin=${currentver:14:3}
14 echo "Installed minor version is $currentvermin"
15 onlineversionmain=`curl -L http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $4}'`
16 echo "Online main: $onlineversionmain"
17 onlineversionmin1=`curl -L http://www.java.com/en/download/manual.jsp | grep "Recommended Version" | awk '{ print $6}' | awk -F "<" '{ print $1}'`
18 onlineversionmin=${onlineversionmin1:0:3}
19 echo "Online minor: $onlineversionmin"
20 if [ -z "${currentvermain}" ] || [ "${onlineversionmain}" -gt "${currentvermain}" ]
21 then
22 echo "Let's install Java! Main online version is higher than installed version."
23 installjava=1
24 fi
25 if [ "${onlineversionmain}" = "${currentvermain}" ] && [ "${onlineversionmin}" -gt "${currentvermin}" ]
26 then
27 echo "Let's install Java! Main online version is equal than installed version, but minor version is higher."
28 installjava=1
29 fi
30 if [ "${onlineversionmain}" = "${currentvermain}" ] && [ "${onlineversionmin}" = "${currentvermin}" ]
31 then
32 echo "Java is up-to-date!"
33 fi
34else
35 echo "No java installed, let's install"
36 installjava=1
37fi
38
39
40# Find Download URL
41fileURL=`curl -L http://www.java.com/en/download/manual.jsp | grep "Download Java for Mac OS X" | awk -F """ '{ print $4;exit}'`
42
43
44# Specify name of downloaded disk image
45
46java_eight_dmg="/tmp/java_eight.dmg"
47
48if [[ ${osvers} -lt 7 ]]; then
49 echo "Oracle Java 8 is not available for Mac OS X 10.6.8 or earlier."
50 exit 0
51fi
52
53if [ "$installjava" = 1 ]
54then
55 echo "Start installing Java"
56 if [[ ${osvers} -ge 7 ]]; then
57
58 # Download the latest Oracle Java 8 software disk image
59
60 /usr/bin/curl --retry 3 -Lo "$java_eight_dmg" "$fileURL"
61
62 # Specify a /tmp/java_eight.XXXX mountpoint for the disk image
63
64 TMPMOUNT=`/usr/bin/mktemp -d /Volumes/java_eight.XXXX`
65
66 # Mount the latest Oracle Java disk image to /tmp/java_eight.XXXX mountpoint
67
68 hdiutil attach "$java_eight_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
69
70 # Install Oracle Java 8 from the installer package.
71
72 if [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.pkg)" ]]; then
73 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.pkg`
74 elif [[ -e "$(/usr/bin/find $TMPMOUNT -name *Java*.mpkg)" ]]; then
75 pkg_path=`/usr/bin/find $TMPMOUNT -name *Java*.mpkg`
76 fi
77
78 # Before installation, the installer's developer certificate is checked
79
80 if [[ "${pkg_path}" != "" ]]; then
81 echo "installing Java from ${pkg_path}..."
82 /usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" > /dev/null 2>&1
83
84 fi
85
86 # Clean-up
87
88 # Unmount the disk image from /tmp/java_eight.XXXX
89
90 /usr/bin/hdiutil detach -force "$TMPMOUNT"
91
92 # Remove the /tmp/java_eight.XXXX mountpoint
93
94 /bin/rm -rf "$TMPMOUNT"
95
96 # Remove the downloaded disk image
97
98 /bin/rm -rf "$java_eight_dmg"
99
100 # Remove xml file
101 /bin/rm -rf /tmp/au-1.8.0_20.xml
102 fi
103fi

Forum|alt.badge.img+6
  • Contributor
  • 83 replies
  • January 18, 2017

@peterloobuyck : Hi Peter. The target machine is running 10.12.2. I note that Oracle released a Java update in the last day or two, but I don't know if that's relevant.


peterlbk
Forum|alt.badge.img+11
  • Author
  • Jamf Heroes
  • 68 replies
  • January 18, 2017

@stevenjklein hi steven, i tested it on a similar machine. It should work even after the update. You're not behind a proxy are you?


Forum|alt.badge.img+6
  • Contributor
  • 83 replies
  • January 18, 2017

@peterloobuyck : Okay, I decided to save it as a shell script, make it executable, and run it on the target machine.

It refused to run.

I checked, and discovered it had Mac line breaks (CR instead of LF). (I know, rookie mistake!)

I used this nifty bit of PERL to fix it:

1perl -pi -e 's/
2/
3/g' install_Java.sh

And now it works.

Thanks for your help!


peterlbk
Forum|alt.badge.img+11
  • Author
  • Jamf Heroes
  • 68 replies
  • January 19, 2017

@stevenjklein Hi Steven, glad it's all working now!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings