diff --git a/installinstallmacos.py b/installinstallmacos.py index 9876e5d..8a23916 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -47,21 +47,31 @@ from distutils.version import LooseVersion DEFAULT_SUCATALOGS = { - "17": "https://swscan.apple.com/content/catalogs/others/" - "index-10.13-10.12-10.11-10.10-10.9" - "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog", - "18": "https://swscan.apple.com/content/catalogs/others/" - "index-10.14-10.13-10.12-10.11-10.10-10.9" - "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog", - "19": "https://swscan.apple.com/content/catalogs/others/" - "index-10.15-10.14-10.13-10.12-10.11-10.10-10.9" - "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog", - "20": "https://swscan.apple.com/content/catalogs/others/" - "index-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9" - "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog", - "21": "https://swscan.apple.com/content/catalogs/others/" - "index-12-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9" - "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog", + "17": ( + "https://swscan.apple.com/content/catalogs/others/" + "index-10.13-10.12-10.11-10.10-10.9" + "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog" + ), + "18": ( + "https://swscan.apple.com/content/catalogs/others/" + "index-10.14-10.13-10.12-10.11-10.10-10.9" + "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog" + ), + "19": ( + "https://swscan.apple.com/content/catalogs/others/" + "index-10.15-10.14-10.13-10.12-10.11-10.10-10.9" + "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog" + ), + "20": ( + "https://swscan.apple.com/content/catalogs/others/" + "index-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9" + "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog" + ), + "21": ( + "https://swscan.apple.com/content/catalogs/others/" + "index-12-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9" + "-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog" + ), } SEED_CATALOGS_PLIST = ( @@ -233,9 +243,10 @@ def get_seeding_programs(): return "" -def get_default_catalog(): +def get_default_catalog(darwin_major=None): """Returns the default softwareupdate catalog for the current OS""" - darwin_major = os.uname()[2].split(".")[0] + if not darwin_major: + darwin_major = os.uname()[2].split(".")[0] return DEFAULT_SUCATALOGS.get(darwin_major) @@ -678,10 +689,13 @@ def os_installer_product_info( def get_latest_version(current_item, latest_item): """Compares versions between two values and returns the latest (highest) value""" - if LooseVersion(current_item) > LooseVersion(latest_item): + try: + if LooseVersion(current_item) > LooseVersion(latest_item): + return current_item + else: + return latest_item + except TypeError: return current_item - else: - return latest_item def replicate_product(catalog, product_id, workdir, ignore_cache=False): @@ -751,6 +765,12 @@ def main(): help="Software Update catalog URL. This option " "overrides any seedprogram option.", ) + parser.add_argument( + "--catalog", + default="", + help="Software Update catalog for a specific macOS version. " + "This option overrides any seedprogram option.", + ) parser.add_argument( "--workdir", metavar="path_to_working_dir", @@ -900,7 +920,9 @@ def main(): su_catalog_url = args.catalogurl elif args.seedprogram: su_catalog_url = get_seed_catalog(args.seedprogram) - if not su_catalog_url: + if su_catalog_url: + print("Using catalog for Seed Program {}.\n".format(args.seedprogram)) + else: print( "Could not find a catalog url for seed program %s" % args.seedprogram, file=sys.stderr, @@ -910,6 +932,16 @@ def main(): file=sys.stderr, ) exit(-1) + elif args.catalog: + su_catalog_url = get_default_catalog(args.catalog) + if su_catalog_url: + print("Using catalog for Darwin v{}.\n".format(args.catalog)) + else: + print( + "Could not find a default catalog url for this OS version.", + file=sys.stderr, + ) + exit(-1) else: su_catalog_url = get_default_catalog() if not su_catalog_url: