Created
January 16, 2019 13:40
-
-
Save rickheil/1e13a72ed7a2088645dcbb2da387f0b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>autoremove</key> | |
<false/> | |
<key>catalogs</key> | |
<array> | |
<string>testing</string> | |
</array> | |
<key>description</key> | |
<string>This update removes insecure and outdated versions of Oracle Java JDKs. If your software stops working after this runs, please install the Oracle Java JDK v11 or higher.</string> | |
<key>display_name</key> | |
<string>Remove Outdated JDKs</string> | |
<key>installcheck_script</key> | |
<string>#!/usr/bin/python | |
import re | |
import os | |
import sys | |
from distutils.version import StrictVersion | |
jvm_path = "/Library/Java/JavaVirtualMachines/" | |
jdks = os.listdir(jvm_path) | |
for jdk in jdks: | |
major_re = re.search('[0-9]+\.[0-9]\.[0-9]', jdk, re.IGNORECASE) | |
if major_re: | |
major = major_re.group(0) | |
else: | |
print "Skipping %s - unable to parse." | |
update_re = re.search('\_[0-9]+', jdk, re.IGNORECASE) | |
if update_re: | |
update = update_re.group(0).replace("_", "") | |
if StrictVersion(major) < StrictVersion("11.0.0"): | |
print "Found JDK %su%s - needs removal." % (major, update) | |
sys.exit(0) | |
else: | |
continue | |
sys.exit(1) | |
</string> | |
<key>installer_type</key> | |
<string>nopkg</string> | |
<key>minimum_os_version</key> | |
<string>10.4.0</string> | |
<key>name</key> | |
<string>Remove Outdated JDKs</string> | |
<key>notes</key> | |
<string>This nopkg uninstalls any Oracle Java JDK version older than 11.0.0 that may be installed on a user’s machine. Since Oracle is requiring licensing payments for using anything older than 11 now, we need to make sure we are in compliance by uninstalling old versions. | |
If Oracle changes their version support matrix in the future, simply bump the strict version compare up to the desired minimum and the script will re-process.</string> | |
<key>postinstall_script</key> | |
<string>#!/usr/bin/python | |
"""Removes all Oracle JDKs from the user's machine.""" | |
import sys | |
import os | |
import shutil | |
import subprocess | |
import re | |
from distutils.version import StrictVersion | |
jvm_path = "/Library/Java/JavaVirtualMachines/" | |
jdks = os.listdir(jvm_path) | |
for jdk in jdks: | |
major_re = re.search('[0-9]+\.[0-9]\.[0-9]', jdk, re.IGNORECASE) | |
if major_re: | |
major = major_re.group(0) | |
else: | |
print "Skipping %s - unable to parse." | |
update_re = re.search('\_[0-9]+', jdk, re.IGNORECASE) | |
if update_re: | |
update = update_re.group(0).replace("_", "") | |
if StrictVersion(major) < StrictVersion("11.0.0"): | |
print "Removing %s" % jdk | |
shutil.rmtree(os.path.join(jvm_path, jdk)) | |
version = major.split(".")[1] | |
receipt_id = "com.oracle.jdk%su%s" % (version, update) | |
cmd = ['/usr/sbin/pkgutil', '--pkgs='+receipt_id] | |
if subprocess.call(cmd): | |
print "No receipt found for %s" % receipt_id | |
else: | |
print "Forgetting pkg receipt %s" % receipt_id | |
cmd = ['/usr/sbin/pkgutil', '--forget', receipt_id] | |
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
out, err = sp.communicate() | |
if err: | |
print err | |
sys.exit(-1) | |
else: | |
print "Skipping %s" % jdk | |
continue | |
</string> | |
<key>version</key> | |
<string>1.0</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment