-
-
Save n8felton/622f2ec2cb42d6da67423f144aff896d 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
#!/usr/local/munki/munki-python | |
import plistlib, os.path, os, logging, pprint | |
# Based off of https://forums.developer.apple.com/message/6741 | |
# and http://apple.stackexchange.com/a/136976 | |
# Downloaded from https://gist.github.com/pudquick/349f063c242239952a2e | |
log_fmt = "[%(asctime)s] [%(levelname)-8s] %(message)s" | |
logging.basicConfig(format=log_fmt, level=logging.DEBUG) | |
def jdk_info_plists(): | |
# Find all the JDK Info.plist files | |
JDK_ROOT = "/Library/Java/JavaVirtualMachines" | |
logging.debug("JDK_ROOT: {}".format(JDK_ROOT)) | |
if (os.path.exists(JDK_ROOT) and os.path.isdir(JDK_ROOT)): | |
# It's present, let's look for installs | |
for file in os.listdir(JDK_ROOT): | |
jdk_dir = os.path.join(JDK_ROOT, file) | |
if (os.path.isdir(jdk_dir)): | |
# Check for Info.plist | |
info_plist = os.path.join(jdk_dir, "Contents", "Info.plist") | |
if (os.path.isfile(info_plist)): | |
logging.debug("Found JVM Info: {}".format(info_plist)) | |
yield info_plist | |
for info_plist in jdk_info_plists(): | |
# Change all the plists of all the installed JDKs | |
with open(info_plist, 'rb') as info_plist_file: | |
info = plistlib.load(info_plist_file) | |
logging.debug("Current Info.plist: {}".format(pprint.pformat(info))) | |
# Get the CFBundleGetInfoString to report back | |
logging.info("Bundle Name: {}".format(info['CFBundleGetInfoString'])) | |
# Convert the capabilities into a set | |
capabilities = set(info['JavaVM']['JVMCapabilities']) | |
logging.debug("Existing JVMCapabilities: {}".format(capabilities)) | |
capabilities.add('JNI') | |
capabilities.add('BundledApp') | |
# Update our changes | |
info['JavaVM']['JVMCapabilities'] = sorted(capabilities) | |
logging.debug("Updated JVMCapabilities: {}".format(info['JavaVM']['JVMCapabilities'])) | |
# Write back our changes | |
logging.debug("Updated Info.plist: {}".format(pprint.pformat(info))) | |
with open(info_plist, 'wb') as info_plist_file: | |
plistlib.dump(info, info_plist_file) | |
# Create a symlink to fix legacy applications | |
# Find the Contents directory | |
contents_path = os.path.dirname(info_plist) | |
logging.debug("Bundle Contents: {}".format(contents_path)) | |
# make the bundle/Libraries subpath | |
bundle_libraries = os.path.join(contents_path, "Home", "bundle", "Libraries") | |
logging.debug("Bundle Libraries: {}".format(bundle_libraries)) | |
try: | |
# Just in case you run this script multiple times, we'll fail if the directory already exists | |
os.makedirs(os.path.join(bundle_libraries)) | |
except: | |
pass | |
# create the symlink between libjvm.dylib and libserver.dylib | |
libjvm_dylib = os.path.join(contents_path, "Home", "jre", "lib", "server", "libjvm.dylib") | |
libserver_dylib = os.path.join(bundle_libraries, "libserver.dylib") | |
try: | |
# Just in case you run this script multiple times, we'll fail if the file already exists | |
logging.debug("Creating symlink: {} -> {}".format(libserver_dylib, libjvm_dylib)) | |
os.symlink(libjvm_dylib, libserver_dylib) | |
except: | |
logging.debug("Symlink exists: {}".format(libserver_dylib)) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment