From a60e90d5a84f7c0d75845f26cf0b2cc6dceb4622 Mon Sep 17 00:00:00 2001 From: Greg Neagle Date: Sat, 8 Aug 2020 07:46:40 -0700 Subject: [PATCH] Workaround to reliably get 'real' OS version on Big Sur. Addresses #1009 --- code/client/munkilib/osutils.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/code/client/munkilib/osutils.py b/code/client/munkilib/osutils.py index cd848b44..283a4a6e 100644 --- a/code/client/munkilib/osutils.py +++ b/code/client/munkilib/osutils.py @@ -51,7 +51,18 @@ def getOsVersion(only_major_minor=True, as_tuple=False): only_major_minor: Boolean. If True, only include major/minor versions. as_tuple: Boolean. If True, return a tuple of ints, otherwise a string. """ - os_version_tuple = platform.mac_ver()[0].split('.') + # platform.mac_ver() returns 10.16-style version info on Big Sur + # and is likely to do so until Python is compiled with the macOS 11 SDK + # which may not happen for a while. And Apple's odd tricks mean that even + # reading /System/Library/CoreServices/SystemVersion.plist is unreliable. + # So let's use a different method. + try: + os_version_tuple = subprocess.check_output( + ('/usr/bin/sw_vers', '-productVersion'), + env={'SYSTEM_VERSION_COMPAT': '0'} + ).decode('UTF-8').rstrip().split('.') + except subprocess.CalledProcessError: + os_version_tuple = platform.mac_ver()[0].split(".") if only_major_minor: os_version_tuple = os_version_tuple[0:2] if as_tuple: