New Munki 7 Feature : version_script
An interesting new Munki
feature that came with the major release of version 7 is the version_script pkgsinfo key
.
I previously
wrote about the use of an installcheck_script for MATLAB which stores it’s version information in a nonstandard location. While using an installcheck_script works for this, there are some limitations :
- The script needs to know the desired version (meaning this must be updated with each version)
- The script must contain the version comparison logic
That second point is an important one. Munki already has robust version comparison logic, so leveraging that would be preferable to reinventing the wheel.
Enter version_script! A version_script just needs to output the version, or if not installed a blank version or non-zero exit code. Munki then uses that version and it’s existing version comparison logic to evaluate whether the item should be installed. This allows the script to me much simpler than an installcheck_script
For comparison :
My old MATLAB installcheck_script
#!/usr/local/bin/managed_python3
import os
import xml.etree.ElementTree as ET
currentVersion = "24.2.0.2740171"
xmlPath = '/Applications/MATLAB_R2024b.app/VersionInfo.xml'
if os.path.isfile(xmlPath):
tree = ET.parse(xmlPath)
root = tree.getroot()
installedVersion = (root[0].text)
else:
installedVersion = "0"
if installedVersion < currentVersion:
print("Installation/Upgrade required")
exit(0)
else:
print("MATLAB " + currentVersion + " or newer already installed")
exit(1)
My new MATLAB version_script :
#!/usr/local/bin/managed_python3
import os
import xml.etree.ElementTree as ET
xmlPath = '/Applications/MATLAB_R2025b.app/VersionInfo.xml'
installedVersion = ""
if os.path.isfile(xmlPath):
tree = ET.parse(xmlPath)
root = tree.getroot()
installedVersion = (root[0].text)
print(installedVersion)
Significantly simpler :-)