forked from cha63506/jss-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_8_install_latest.sh
More file actions
75 lines (49 loc) · 2.65 KB
/
java_8_install_latest.sh
File metadata and controls
75 lines (49 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/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="/tmp/java_eight.dmg"
if [[ ${osvers} -lt 8 ]]; then
echo "Oracle Java 8 is not available for Mac OS X 10.7.5 or below."
fi
if [[ ${osvers} -ge 8 ]]; 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 /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 stored inside the disk image
/usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.pkg -o -iname \*\.mpkg \))" -target "/"
# 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_20