Add test for remotectl command for older Macs

This commit is contained in:
Graham R Pugh 2020-08-18 15:00:53 +02:00
parent 9a53656ebf
commit 1283058653

View File

@ -81,7 +81,7 @@ def get_board_id():
def is_a_vm(): def is_a_vm():
"""Determines if the script is being run in a virtual machine""" """Determines if the script is being run in a virtual machine"""
sysctl_cmd = ["/usr/sbin/sysctl", "machdep.cpu.features"] sysctl_cmd = ["/usr/sbin/sysctl", "-n", "machdep.cpu.features"]
try: try:
sysctl_output = subprocess.check_output(sysctl_cmd) sysctl_output = subprocess.check_output(sysctl_cmd)
cpu_features = sysctl_output.decode("utf8").split(" ") cpu_features = sysctl_output.decode("utf8").split(" ")
@ -96,18 +96,24 @@ def is_a_vm():
def get_hw_model(): def get_hw_model():
"""Gets the local system ModelIdentifier""" """Gets the local system ModelIdentifier"""
sysctl_cmd = ["/usr/sbin/sysctl", "hw.model"] sysctl_cmd = ["/usr/sbin/sysctl", "-n", "hw.model"]
try: try:
sysctl_output = subprocess.check_output(sysctl_cmd) sysctl_output = subprocess.check_output(sysctl_cmd)
hw_model = sysctl_output.decode("utf8").split(" ")[-1].split("\n")[0] hw_model = sysctl_output.decode("utf8")
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
raise ReplicationError(err) raise ReplicationError(err)
return hw_model return hw_model
def get_bridge_id(): def get_bridge_id():
"""Gets the local system DeviceID for T2 Macs""" """Gets the local system DeviceID for T2 Macs - note only works on 10.13+"""
remotectl_cmd = ["/usr/libexec/remotectl", "get-property", "localbridge", "HWModel"] if os.path.exists("/usr/libexec/remotectl"):
remotectl_cmd = [
"/usr/libexec/remotectl",
"get-property",
"localbridge",
"HWModel",
]
try: try:
remotectl_output = subprocess.check_output( remotectl_output = subprocess.check_output(
remotectl_cmd, stderr=subprocess.STDOUT remotectl_cmd, stderr=subprocess.STDOUT