Implement DMG-based PatcherSupportPkg

This commit is contained in:
Mykola Grymalyuk
2023-05-04 15:02:41 -06:00
parent c308bcb993
commit d21b984918
6 changed files with 68 additions and 58 deletions

1
.gitignore vendored
View File

@@ -33,3 +33,4 @@ __pycache__/
/payloads/OpenCore-Legacy-Patcher-*.plist /payloads/OpenCore-Legacy-Patcher-*.plist
/payloads/KDK.dmg /payloads/KDK.dmg
*.log *.log
/Universal-Binaries.dmg

View File

@@ -236,7 +236,6 @@ class CreateBinary:
"launcher.sh", "launcher.sh",
"OC-Patcher-TUI.icns", "OC-Patcher-TUI.icns",
"OC-Patcher.icns", "OC-Patcher.icns",
"Universal-Binaries.zip",
] ]
@@ -261,16 +260,16 @@ class CreateBinary:
patcher_support_pkg_version = constants.Constants().patcher_support_pkg_version patcher_support_pkg_version = constants.Constants().patcher_support_pkg_version
required_resources = [ required_resources = [
"Universal-Binaries.zip" "Universal-Binaries.dmg"
] ]
print("- Downloading required resources...") print("- Downloading required resources...")
for resource in required_resources: for resource in required_resources:
if Path(f"./payloads/{resource}").exists(): if Path(f"./{resource}").exists():
if self.args.reset_binaries: if self.args.reset_binaries:
print(f" - Removing old {resource}") print(f" - Removing old {resource}")
rm_output = subprocess.run( rm_output = subprocess.run(
["rm", "-rf", f"./payloads/{resource}"], ["rm", "-rf", f"./{resource}"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE stdout=subprocess.PIPE, stderr=subprocess.PIPE
) )
if rm_output.returncode != 0: if rm_output.returncode != 0:
@@ -298,13 +297,6 @@ class CreateBinary:
print(f" - {resource} not found") print(f" - {resource} not found")
raise Exception(f"{resource} not found") raise Exception(f"{resource} not found")
print(" - Moving into payloads")
mv_output = subprocess.run(["mv", resource, "./payloads/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if mv_output.returncode != 0:
print(" - Move failed")
print(mv_output.stderr.decode('utf-8'))
raise Exception("Move failed")
def _generate_payloads_dmg(self): def _generate_payloads_dmg(self):
""" """
@@ -331,9 +323,9 @@ class CreateBinary:
print(" - Generating DMG...") print(" - Generating DMG...")
dmg_output = subprocess.run([ dmg_output = subprocess.run([
'hdiutil', 'create', './payloads.dmg', 'hdiutil', 'create', './payloads.dmg',
'-megabytes', '32000', '-megabytes', '32000', # Overlays can only be as large as the disk image allows
'-format', 'UDZO', '-ov', '-format', 'UDZO', '-ov',
'-volname', 'OpenCore Patcher Resources', '-volname', 'OpenCore Patcher Resources (Base)',
'-fs', 'HFS+', '-fs', 'HFS+',
'-srcfolder', './payloads', '-srcfolder', './payloads',
'-passphrase', 'password', '-encryption' '-passphrase', 'password', '-encryption'

View File

@@ -9,7 +9,7 @@ block_cipher = None
a = Analysis(['OpenCore-Patcher-GUI.command'], a = Analysis(['OpenCore-Patcher-GUI.command'],
pathex=[], pathex=[],
binaries=[], binaries=[],
datas=[('payloads.dmg', '.')], datas=[('payloads.dmg', '.'), ('Universal-Binaries.dmg', '.')],
hiddenimports=[], hiddenimports=[],
hookspath=[], hookspath=[],
hooksconfig={}, hooksconfig={},

View File

@@ -13,7 +13,7 @@ class Constants:
def __init__(self) -> None: def __init__(self) -> None:
# Patcher Versioning # Patcher Versioning
self.patcher_version: str = "0.6.6" # OpenCore-Legacy-Patcher self.patcher_version: str = "0.6.6" # OpenCore-Legacy-Patcher
self.patcher_support_pkg_version: str = "0.9.7" # PatcherSupportPkg self.patcher_support_pkg_version: str = "1.0.0" # PatcherSupportPkg
self.copyright_date: str = "Copyright © 2020-2023 Dortania" self.copyright_date: str = "Copyright © 2020-2023 Dortania"
# URLs # URLs
@@ -231,6 +231,12 @@ class Constants:
@property @property
def payload_path_dmg(self): def payload_path_dmg(self):
return self.original_path / Path("payloads.dmg") return self.original_path / Path("payloads.dmg")
@property
def payload_local_binaries_root_path_dmg(self):
return self.original_path / Path("Universal-Binaries.dmg")
# OpenCore # OpenCore
@property @property
def opencore_zip_source(self): def opencore_zip_source(self):
@@ -656,10 +662,6 @@ class Constants:
def payload_local_binaries_root_path(self): def payload_local_binaries_root_path(self):
return self.payload_path / Path("Universal-Binaries") return self.payload_path / Path("Universal-Binaries")
@property
def payload_local_binaries_root_path_zip(self):
return self.payload_path / Path("Universal-Binaries.zip")
@property @property
def kdk_download_path(self): def kdk_download_path(self):
return self.payload_path / Path("KDK.dmg") return self.payload_path / Path("KDK.dmg")

View File

@@ -67,13 +67,6 @@ class PatchSysVolume:
self.skip_root_kmutil_requirement = self.hardware_details["Settings: Supports Auxiliary Cache"] self.skip_root_kmutil_requirement = self.hardware_details["Settings: Supports Auxiliary Cache"]
def __del__(self) -> None:
"""
Ensures that each time we're patching, we're using a clean PatcherSupportPkg folder
"""
if Path(self.constants.payload_local_binaries_root_path).exists():
shutil.rmtree(self.constants.payload_local_binaries_root_path)
def _init_pathing(self, custom_root_mount_path: Path = None, custom_data_mount_path: Path = None) -> None: def _init_pathing(self, custom_root_mount_path: Path = None, custom_data_mount_path: Path = None) -> None:
""" """
@@ -854,10 +847,27 @@ class PatchSysVolume:
logging.info("- Local PatcherSupportPkg resources available, continuing...") logging.info("- Local PatcherSupportPkg resources available, continuing...")
return True return True
if Path(self.constants.payload_local_binaries_root_path_zip).exists(): if Path(self.constants.payload_local_binaries_root_path_dmg).exists():
logging.info("- Local PatcherSupportPkg resources available, unzipping...") logging.info("- Local PatcherSupportPkg resources available, mounting...")
logging.info("- Unzipping binaries...")
utilities.process_status(subprocess.run(["ditto", "-V", "-x", "-k", "--sequesterRsrc", "--rsrc", self.constants.payload_local_binaries_root_path_zip, self.constants.payload_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) output = subprocess.run(
[
"hdiutil", "attach", "-noverify", f"{self.constants.payload_local_binaries_root_path_dmg}",
"-mountpoint", Path(self.constants.payload_path / Path("Universal-Binaries")),
"-nobrowse",
"-shadow", Path(self.constants.payload_path / Path("Universal-Binaries_overlay")),
"-passphrase", "password"
],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
if output.returncode != 0:
logging.info("- Failed to mount Universal-Binaries.dmg")
logging.info(f"Output: {output.stdout.decode()}")
logging.info(f"Return Code: {output.returncode}")
return False
logging.info("- Mounted Universal-Binaries.dmg")
return True return True
logging.info("- PatcherSupportPkg resources missing, Patcher likely corrupted!!!") logging.info("- PatcherSupportPkg resources missing, Patcher likely corrupted!!!")

View File

@@ -133,18 +133,34 @@ class PatcherValidation:
Validates sys_patch modules Validates sys_patch modules
""" """
if Path(self.constants.payload_local_binaries_root_path_zip).exists(): if not Path(self.constants.payload_local_binaries_root_path_dmg).exists():
logging.info("- Skipping Root Patch File integrity validation")
return
logging.info("Validating Root Patch File integrity") logging.info("Validating Root Patch File integrity")
if not Path(self.constants.payload_local_binaries_root_path).exists(): output = subprocess.run(
subprocess.run(
[ [
"ditto", "-V", "-x", "-k", "--sequesterRsrc", "--rsrc", "hdiutil", "attach", "-noverify", f"{self.constants.payload_local_binaries_root_path_dmg}",
self.constants.payload_local_binaries_root_path_zip, "-mountpoint", Path(self.constants.payload_path / Path("Universal-Binaries")),
self.constants.payload_path "-nobrowse",
"-shadow", Path(self.constants.payload_path / Path("Universal-Binaries_overlay")),
"-passphrase", "password"
], ],
stdout=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
stderr=subprocess.STDOUT
) )
if output.returncode != 0:
logging.info("- Failed to mount Universal-Binaries.dmg")
logging.info(f"Output: {output.stdout.decode()}")
logging.info(f"Return Code: {output.returncode}")
print(self.constants.payload_local_binaries_root_path_dmg)
raise Exception("Failed to mount Universal-Binaries.dmg")
logging.info("- Mounted Universal-Binaries.dmg")
for supported_os in [os_data.os_data.big_sur, os_data.os_data.monterey, os_data.os_data.ventura]: for supported_os in [os_data.os_data.big_sur, os_data.os_data.monterey, os_data.os_data.ventura]:
for i in range(0, 10): for i in range(0, 10):
self._validate_root_patch_files(supported_os, i) self._validate_root_patch_files(supported_os, i)
@@ -152,17 +168,6 @@ class PatcherValidation:
self.constants.computer.reported_board_id = "Mac-7BA5B2DFE22DDD8C" self.constants.computer.reported_board_id = "Mac-7BA5B2DFE22DDD8C"
sys_patch_helpers.SysPatchHelpers(self.constants).snb_board_id_patch(self.constants.payload_local_binaries_root_path) sys_patch_helpers.SysPatchHelpers(self.constants).snb_board_id_patch(self.constants.payload_local_binaries_root_path)
# Clean up
subprocess.run(
[
"rm", "-rf", self.constants.payload_local_binaries_root_path
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
else:
logging.info("- Skipping Root Patch File integrity validation")
def _validate_configs(self) -> None: def _validate_configs(self) -> None:
""" """