Created
July 11, 2020 19:23
-
-
Save apizz/1bd1ebc58f13fba5fb1939be9c14a2aa to your computer and use it in GitHub Desktop.
Script to be used as a munki preinstall_script which will only succeed and subsequently install software if the Mac's macOS version matches one in the SUPPORTED_VERS list
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
#!/bin/bash | |
# Method inspired by: | |
# https://stackoverflow.com/questions/12768265/bash-compare-a-string-vs-a-list-of-strings | |
# Usage: | |
# | |
# While munki provides minimum_os_version and maximum_os_version to define a supported | |
# OS version range, some software define individual macOS versions as officially | |
# supported. In these cases, defining a supported range is helpful, but ultimately | |
# insufficient. | |
# | |
# Adding this script as a munki 'preinstall_script' and defining supported versions | |
# in the SUPPORTED_VERS variable (separated by spaces) will either match (exit 0) causing | |
# the software to be installed or not match (exit 1) and not install the software. | |
# Admin-provided supported version list, separated by spaces | |
SUPPORTED_VERS=( 10.13.6 10.14.6 10.15.3 10.15.5 ) | |
# Get a Mac's installed OS product version (ex. 10.14.6) | |
OSVERS=$(/usr/bin/sw_vers -productVersion) | |
# Set blank value | |
SUPPORTED="" | |
# Populate list with supported versions | |
VERS_LIST=$(/usr/bin/printf '%s\n' "${SUPPORTED_VERS[@]}") | |
# Compare installed OS version to supported version list, break loop if match found | |
for v in $VERS_LIST; do | |
if [[ "$v" = "$OSVERS" ]]; then | |
SUPPORTED="yes" | |
break | |
fi | |
done | |
# Verify result & exit 0 if matched and install software, exit 1 if not matched | |
# and don't install | |
if [ "$SUPPORTED" = "yes" ]; then | |
/bin/echo "VERIFIED: macOS version ${OSVERS} is listed in the supported OS list." | |
/bin/echo "Proceeding with install ..." | |
exit 0 | |
else | |
/bin/echo "FAILED: macOS version ${OSVERS} is not in the supported OS list." | |
/bin/echo "Cancelling install ..." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment