now obtains Apple Silicon Device IDs.

This commit is contained in:
Graham R Pugh 2020-12-15 00:06:09 +01:00
parent 660134e0e5
commit f6df69e847

View File

@ -67,11 +67,13 @@ SEED_CATALOGS_PLIST = (
)
def get_board_id():
"""Gets the local system board ID"""
ioreg_cmd = ["/usr/sbin/ioreg", "-p", "IODeviceTree", "-r", "-n", "/", "-d", "1"]
def get_device_id():
"""Gets the local device ID on Apple Silicon Macs or the board_id of older Macs"""
ioreg_cmd = ["/usr/sbin/ioreg", "-c", "IOPlatformExpertDevice", "-d", "2"]
try:
ioreg_output = subprocess.check_output(ioreg_cmd).splitlines()
board_id = ""
device_id = ""
for line in ioreg_output:
line_decoded = line.decode("utf8")
if "board-id" in line_decoded:
@ -79,7 +81,18 @@ def get_board_id():
board_id = board_id[
board_id.find('<"') + 2 : board_id.find('">') # noqa: E203
]
return board_id
elif "compatible" in line_decoded:
device_details = line_decoded.split("<")[-1]
device_details = device_details[
device_details.find("<")
+ 2 : device_details.find(">") # noqa: E203
]
device_id = (
device_details.replace('","', ";").replace('"', "").split(";")[0]
)
if board_id:
device_id = ""
return board_id, device_id
except subprocess.CalledProcessError as err:
raise ReplicationError(err)
@ -501,16 +514,16 @@ def get_board_ids(filename):
# dist files for macOS 10.* list boardIDs whereas dist files for
# macOS 11.* list supportedBoardIDs
if "boardIds" in line:
supported_board_ids = line.lstrip("var boardIDs = ")
supported_board_ids = line.replace("var boardIDs = ", "")
elif "supportedBoardIDs" in line:
supported_board_ids = line.lstrip("var supportedBoardIDs = ")
supported_board_ids = line.replace("var supportedBoardIDs = ", "")
return supported_board_ids
def get_device_ids(filename):
"""Parses a softwareupdate dist file, returning a list of supported
Device IDs. These are used for identifying T2 chips in the dist files of macOS 11.*
- not checked in older builds"""
Device IDs. These are used for identifying T2 and Apple Silicon chips in the dist files of
macOS 11.* - not checked in older builds"""
supported_device_ids = ""
with open(filename) as search:
for line in search:
@ -518,7 +531,7 @@ def get_device_ids(filename):
line = line.decode("utf8")
line = line.rstrip() # remove '\n' at end of line
if "supportedDeviceIDs" in line:
supported_device_ids = line.lstrip("var supportedDeviceIDs = ")
supported_device_ids = line.replace("var supportedDeviceIDs = ", "")
return supported_device_ids
@ -817,7 +830,7 @@ def main():
# show this Mac's info
hw_model = get_hw_model()
board_id = get_board_id()
board_id, device_id = get_device_id()
bridge_id = get_bridge_id()
build_info = get_current_build_info()
is_vm = is_a_vm()
@ -825,9 +838,14 @@ def main():
print("This Mac:")
if is_vm is True:
print("Identified as a Virtual Machine")
if hw_model:
print("%-17s: %s" % ("Model Identifier", hw_model))
if bridge_id:
print("%-17s: %s" % ("Bridge ID", bridge_id))
if board_id:
print("%-17s: %s" % ("Board ID", board_id))
if device_id:
print("%-17s: %s" % ("Device ID", device_id))
print("%-17s: %s" % ("OS Version", build_info[0]))
print("%-17s: %s\n" % ("Build ID", build_info[1]))
@ -905,10 +923,14 @@ def main():
if board_id and product_info[product_id]["BoardIDs"]:
if board_id not in product_info[product_id]["BoardIDs"]:
not_valid = "Unsupported Board ID"
# if there's no Board ID there has to be a BridgeID:
# if there's no Board ID then try BridgeID (T2):
elif bridge_id and product_info[product_id]["DeviceIDs"]:
if bridge_id not in product_info[product_id]["DeviceIDs"]:
not_valid = "Unsupported Bridge ID"
# if there's no BridgeID try DeviceID (Apple Silicon):
elif device_id and product_info[product_id]["DeviceIDs"]:
if device_id not in product_info[product_id]["DeviceIDs"]:
not_valid = "Unsupported Device ID"
# finally we fall back on ModelIdentifiers for T1 and older
elif hw_model and product_info[product_id]["UnsupportedModels"]:
if hw_model in product_info[product_id]["UnsupportedModels"]: