mirror of
https://github.com/grahampugh/macadmin-scripts.git
synced 2025-12-17 17:56:33 +00:00
now obtains Apple Silicon Device IDs.
This commit is contained in:
parent
660134e0e5
commit
f6df69e847
@ -67,11 +67,13 @@ SEED_CATALOGS_PLIST = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_board_id():
|
def get_device_id():
|
||||||
"""Gets the local system board ID"""
|
"""Gets the local device ID on Apple Silicon Macs or the board_id of older Macs"""
|
||||||
ioreg_cmd = ["/usr/sbin/ioreg", "-p", "IODeviceTree", "-r", "-n", "/", "-d", "1"]
|
ioreg_cmd = ["/usr/sbin/ioreg", "-c", "IOPlatformExpertDevice", "-d", "2"]
|
||||||
try:
|
try:
|
||||||
ioreg_output = subprocess.check_output(ioreg_cmd).splitlines()
|
ioreg_output = subprocess.check_output(ioreg_cmd).splitlines()
|
||||||
|
board_id = ""
|
||||||
|
device_id = ""
|
||||||
for line in ioreg_output:
|
for line in ioreg_output:
|
||||||
line_decoded = line.decode("utf8")
|
line_decoded = line.decode("utf8")
|
||||||
if "board-id" in line_decoded:
|
if "board-id" in line_decoded:
|
||||||
@ -79,7 +81,18 @@ def get_board_id():
|
|||||||
board_id = board_id[
|
board_id = board_id[
|
||||||
board_id.find('<"') + 2 : board_id.find('">') # noqa: E203
|
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:
|
except subprocess.CalledProcessError as err:
|
||||||
raise ReplicationError(err)
|
raise ReplicationError(err)
|
||||||
|
|
||||||
@ -501,16 +514,16 @@ def get_board_ids(filename):
|
|||||||
# dist files for macOS 10.* list boardIDs whereas dist files for
|
# dist files for macOS 10.* list boardIDs whereas dist files for
|
||||||
# macOS 11.* list supportedBoardIDs
|
# macOS 11.* list supportedBoardIDs
|
||||||
if "boardIds" in line:
|
if "boardIds" in line:
|
||||||
supported_board_ids = line.lstrip("var boardIDs = ")
|
supported_board_ids = line.replace("var boardIDs = ", "")
|
||||||
elif "supportedBoardIDs" in line:
|
elif "supportedBoardIDs" in line:
|
||||||
supported_board_ids = line.lstrip("var supportedBoardIDs = ")
|
supported_board_ids = line.replace("var supportedBoardIDs = ", "")
|
||||||
return supported_board_ids
|
return supported_board_ids
|
||||||
|
|
||||||
|
|
||||||
def get_device_ids(filename):
|
def get_device_ids(filename):
|
||||||
"""Parses a softwareupdate dist file, returning a list of supported
|
"""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.*
|
Device IDs. These are used for identifying T2 and Apple Silicon chips in the dist files of
|
||||||
- not checked in older builds"""
|
macOS 11.* - not checked in older builds"""
|
||||||
supported_device_ids = ""
|
supported_device_ids = ""
|
||||||
with open(filename) as search:
|
with open(filename) as search:
|
||||||
for line in search:
|
for line in search:
|
||||||
@ -518,7 +531,7 @@ def get_device_ids(filename):
|
|||||||
line = line.decode("utf8")
|
line = line.decode("utf8")
|
||||||
line = line.rstrip() # remove '\n' at end of line
|
line = line.rstrip() # remove '\n' at end of line
|
||||||
if "supportedDeviceIDs" in line:
|
if "supportedDeviceIDs" in line:
|
||||||
supported_device_ids = line.lstrip("var supportedDeviceIDs = ")
|
supported_device_ids = line.replace("var supportedDeviceIDs = ", "")
|
||||||
return supported_device_ids
|
return supported_device_ids
|
||||||
|
|
||||||
|
|
||||||
@ -817,7 +830,7 @@ def main():
|
|||||||
|
|
||||||
# show this Mac's info
|
# show this Mac's info
|
||||||
hw_model = get_hw_model()
|
hw_model = get_hw_model()
|
||||||
board_id = get_board_id()
|
board_id, device_id = get_device_id()
|
||||||
bridge_id = get_bridge_id()
|
bridge_id = get_bridge_id()
|
||||||
build_info = get_current_build_info()
|
build_info = get_current_build_info()
|
||||||
is_vm = is_a_vm()
|
is_vm = is_a_vm()
|
||||||
@ -825,9 +838,14 @@ def main():
|
|||||||
print("This Mac:")
|
print("This Mac:")
|
||||||
if is_vm is True:
|
if is_vm is True:
|
||||||
print("Identified as a Virtual Machine")
|
print("Identified as a Virtual Machine")
|
||||||
|
if hw_model:
|
||||||
print("%-17s: %s" % ("Model Identifier", hw_model))
|
print("%-17s: %s" % ("Model Identifier", hw_model))
|
||||||
|
if bridge_id:
|
||||||
print("%-17s: %s" % ("Bridge ID", bridge_id))
|
print("%-17s: %s" % ("Bridge ID", bridge_id))
|
||||||
|
if board_id:
|
||||||
print("%-17s: %s" % ("Board ID", 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" % ("OS Version", build_info[0]))
|
||||||
print("%-17s: %s\n" % ("Build ID", build_info[1]))
|
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 and product_info[product_id]["BoardIDs"]:
|
||||||
if board_id not in product_info[product_id]["BoardIDs"]:
|
if board_id not in product_info[product_id]["BoardIDs"]:
|
||||||
not_valid = "Unsupported Board ID"
|
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"]:
|
elif bridge_id and product_info[product_id]["DeviceIDs"]:
|
||||||
if bridge_id not in product_info[product_id]["DeviceIDs"]:
|
if bridge_id not in product_info[product_id]["DeviceIDs"]:
|
||||||
not_valid = "Unsupported Bridge ID"
|
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
|
# finally we fall back on ModelIdentifiers for T1 and older
|
||||||
elif hw_model and product_info[product_id]["UnsupportedModels"]:
|
elif hw_model and product_info[product_id]["UnsupportedModels"]:
|
||||||
if hw_model in product_info[product_id]["UnsupportedModels"]:
|
if hw_model in product_info[product_id]["UnsupportedModels"]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user