installer.py: Parse SharedSupport.dmg

This commit is contained in:
Mykola Grymalyuk
2022-08-24 12:19:52 -06:00
parent 14528b904c
commit c1ba7cd6cb
3 changed files with 88 additions and 4 deletions

View File

@@ -47,6 +47,14 @@ def list_local_macOS_installers():
can_add = False
else:
can_add = True
# Check SharedSupport.dmg's data
results = parse_sharedsupport_version(Path("/Applications") / Path(application)/ Path("Contents/SharedSupport/SharedSupport.dmg"))
if results[0] is not None:
app_sdk = results[0]
if results[1] is not None:
app_version = results[1]
if can_add is True:
application_list.update({
application: {
@@ -64,6 +72,46 @@ def list_local_macOS_installers():
application_list = {k: v for k, v in sorted(application_list.items(), key=lambda item: item[1]["Version"])}
return application_list
def parse_sharedsupport_version(sharedsupport_path):
detected_build = None
detected_os = None
sharedsupport_path = Path(sharedsupport_path)
if not sharedsupport_path.exists():
return (detected_build, detected_os)
if not sharedsupport_path.name.endswith(".dmg"):
return (detected_build, detected_os)
# Create temporary directory to extract SharedSupport.dmg to
with tempfile.TemporaryDirectory() as tmpdir:
output = subprocess.run(
[
"hdiutil", "attach", "-noverify", sharedsupport_path,
"-mountpoint", tmpdir,
"-nobrowse",
],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
if output.returncode != 0:
return (detected_build, detected_os)
ss_info = Path("SFR/com_apple_MobileAsset_SFRSoftwareUpdate/com_apple_MobileAsset_SFRSoftwareUpdate.xml")
if Path(tmpdir / ss_info).exists():
plist = plistlib.load((tmpdir / ss_info).open("rb"))
if "Build" in plist["Assets"][0]:
detected_build = plist["Assets"][0]["Build"]
if "OSVersion" in plist["Assets"][0]:
detected_os = plist["Assets"][0]["OSVersion"]
# Unmount SharedSupport.dmg
output = subprocess.run(["hdiutil", "detach", tmpdir], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return (detected_build, detected_os)
def create_installer(installer_path, volume_name):
# Creates a macOS installer
# Takes a path to the installer and the Volume