Fix for os comparisons where none is given in the softwarecatalog

This commit is contained in:
Graham R Pugh 2020-12-10 14:46:58 +01:00
parent 202b59d7f2
commit 660134e0e5

View File

@ -76,7 +76,9 @@ def get_board_id():
line_decoded = line.decode("utf8") line_decoded = line.decode("utf8")
if "board-id" in line_decoded: if "board-id" in line_decoded:
board_id = line_decoded.split("<")[-1] board_id = line_decoded.split("<")[-1]
board_id = board_id[board_id.find('<"') + 2 : board_id.find('">')] board_id = board_id[
board_id.find('<"') + 2 : board_id.find('">') # noqa: E203
]
return board_id return board_id
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
raise ReplicationError(err) raise ReplicationError(err)
@ -244,7 +246,7 @@ def make_sparse_image(volume_name, output_path):
exit(-1) exit(-1)
try: try:
return read_plist_from_string(output)[0] return read_plist_from_string(output)[0]
except IndexError as err: except IndexError:
print("Unexpected output from hdiutil: %s" % output, file=sys.stderr) print("Unexpected output from hdiutil: %s" % output, file=sys.stderr)
exit(-1) exit(-1)
except ExpatError as err: except ExpatError as err:
@ -507,7 +509,8 @@ def get_board_ids(filename):
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.* - not checked in older builds""" Device IDs. These are used for identifying T2 chips in the dist files of 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:
@ -570,20 +573,26 @@ def find_mac_os_installers(catalog, installassistant_pkg_only=False):
# account for args.pkg # account for args.pkg
if installassistant_pkg_only: if installassistant_pkg_only:
try: try:
if product['ExtendedMetaInfo']['InstallAssistantPackageIdentifiers']['SharedSupport']: if product["ExtendedMetaInfo"][
"InstallAssistantPackageIdentifiers"
]["SharedSupport"]:
mac_os_installer_products.append(product_key) mac_os_installer_products.append(product_key)
except KeyError: except KeyError:
continue continue
else: else:
try: try:
if product["ExtendedMetaInfo"]["InstallAssistantPackageIdentifiers"]: if product["ExtendedMetaInfo"][
"InstallAssistantPackageIdentifiers"
]:
mac_os_installer_products.append(product_key) mac_os_installer_products.append(product_key)
except KeyError: except KeyError:
continue continue
return mac_os_installer_products return mac_os_installer_products
def os_installer_product_info(catalog, workdir, installassistant_pkg_only, ignore_cache=False): def os_installer_product_info(
catalog, workdir, installassistant_pkg_only, ignore_cache=False
):
"""Returns a dict of info about products that look like macOS installers""" """Returns a dict of info about products that look like macOS installers"""
product_info = {} product_info = {}
installer_products = find_mac_os_installers(catalog, installassistant_pkg_only) installer_products = find_mac_os_installers(catalog, installassistant_pkg_only)
@ -814,7 +823,7 @@ def main():
is_vm = is_a_vm() is_vm = is_a_vm()
print("This Mac:") print("This Mac:")
if is_vm == True: if is_vm is True:
print("Identified as a Virtual Machine") print("Identified as a Virtual Machine")
print("%-17s: %s" % ("Model Identifier", hw_model)) print("%-17s: %s" % ("Model Identifier", hw_model))
print("%-17s: %s" % ("Bridge ID", bridge_id)) print("%-17s: %s" % ("Bridge ID", bridge_id))
@ -891,7 +900,7 @@ def main():
# this is where we do checks for validity based on model type and version # this is where we do checks for validity based on model type and version
for index, product_id in enumerate(product_info): for index, product_id in enumerate(product_info):
not_valid = "" not_valid = ""
if is_vm == False: if is_vm is False:
# first look for a BoardID (not present in modern hardware) # first look for a BoardID (not present in modern hardware)
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"]:
@ -950,9 +959,13 @@ def main():
# skip if an OS is selected and it does not match # skip if an OS is selected and it does not match
if args.os: if args.os:
os_version = product_info[product_id]["version"].split(".")[0] os_version = product_info[product_id]["version"].split(".")[0]
if int(os_version) == 10: try:
major = product_info[product_id]["version"].split(".", 2)[:2] if int(os_version) == 10:
os_version = ".".join(major) major = product_info[product_id]["version"].split(".", 2)[:2]
os_version = ".".join(major)
except ValueError:
#  Account for when no version information is given
os_version = ""
if args.os != os_version: if args.os != os_version:
continue continue
@ -1025,7 +1038,7 @@ def main():
# Stop here if no valid builds found # Stop here if no valid builds found
if ( if (
valid_build_found == False valid_build_found is False
and not args.build and not args.build
and not args.current and not args.current
and not args.validate and not args.validate
@ -1175,23 +1188,27 @@ def main():
print("Exiting.") print("Exiting.")
exit(0) exit(0)
# shortened workflow if we just want a macOS Big Sur+ package #  shortened workflow if we just want a macOS Big Sur+ package
# taken from @scriptingosx's Fetch-Installer-Pkg project #  taken from @scriptingosx's Fetch-Installer-Pkg project
# (https://github.com/scriptingosx/fetch-installer-pkg) # (https://github.com/scriptingosx/fetch-installer-pkg)
if args.pkg: if args.pkg:
product = catalog['Products'][product_id] product = catalog["Products"][product_id]
# determine the InstallAssistant pkg url # determine the InstallAssistant pkg url
for package in product['Packages']: for package in product["Packages"]:
package_url = package['URL'] package_url = package["URL"]
if package_url.endswith('InstallAssistant.pkg'): if package_url.endswith("InstallAssistant.pkg"):
break break
# print("Package URL is %s" % package_url) # print("Package URL is %s" % package_url)
download_pkg = replicate_url(package_url, args.workdir, True, ignore_cache=args.ignore_cache) download_pkg = replicate_url(
package_url, args.workdir, True, ignore_cache=args.ignore_cache
)
pkg_name = ('InstallAssistant-%s-%s.pkg' % (product_info[product_id]['version'], pkg_name = "InstallAssistant-%s-%s.pkg" % (
product_info[product_id]['BUILD'])) product_info[product_id]["version"],
product_info[product_id]["BUILD"],
)
# hard link the downloaded file to cwd # hard link the downloaded file to cwd
local_pkg = os.path.join(args.workdir, pkg_name) local_pkg = os.path.join(args.workdir, pkg_name)
@ -1200,7 +1217,9 @@ def main():
else: else:
# download all the packages for the selected product # download all the packages for the selected product
replicate_product(catalog, product_id, args.workdir, ignore_cache=args.ignore_cache) replicate_product(
catalog, product_id, args.workdir, ignore_cache=args.ignore_cache
)
# generate a name for the sparseimage # generate a name for the sparseimage
volname = "Install_macOS_%s-%s" % ( volname = "Install_macOS_%s-%s" % (
@ -1233,7 +1252,9 @@ def main():
"Adding seeding program %s extended attribute to app" "Adding seeding program %s extended attribute to app"
% seeding_program % seeding_program
) )
xattr.setxattr(installer_app, "SeedProgram", seeding_program.encode()) xattr.setxattr(
installer_app, "SeedProgram", seeding_program.encode()
)
print("Product downloaded and installed to %s" % sparse_diskimage_path) print("Product downloaded and installed to %s" % sparse_diskimage_path)
if args.raw: if args.raw:
unmountdmg(mountpoint) unmountdmg(mountpoint)