Skip to content

Commit

Permalink
Merge pull request #1134 from dortania/sanity-checks
Browse files Browse the repository at this point in the history
sys_patch: Implement sanity checks
  • Loading branch information
khronokernel authored May 31, 2024
2 parents 074d56e + 6daa038 commit 86e88bf
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion opencore_legacy_patcher/sys_patch/sys_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,30 @@ def _unmount_root_vol(self) -> None:
self.mount_obj.unmount(ignore_errors=True)


def _run_sanity_checks(self) -> bool:
"""
Run sanity check before continuing patching
"""
logging.info("- Running sanity checks before patching")

mounted_system_version = Path(self.mount_location) / "System/Library/CoreServices/SystemVersion.plist"

if not mounted_system_version.exists():
logging.error("- Failed to find SystemVersion.plist")
return False

try:
mounted_data = plistlib.load(open(mounted_system_version, "rb"))
if mounted_data["ProductBuildVersion"] != self.constants.detected_os_build:
logging.error(f"- SystemVersion.plist build version mismatch: {mounted_data['ProductBuildVersion']} vs {self.constants.detected_os_build}")
return False
except:
logging.error("- Failed to parse SystemVersion.plist")
return False

return True


def _merge_kdk_with_root(self, save_hid_cs: bool = False) -> None:
"""
Merge Kernel Debug Kit (KDK) with the root volume
Expand Down Expand Up @@ -927,7 +951,11 @@ def start_patch(self):
logging.info("- Patcher is capable of patching")
if self._check_files():
if self._mount_root_vol() is True:
self._patch_root_vol()
if self._run_sanity_checks():
self._patch_root_vol()
else:
self._unmount_root_vol()
logging.info("- Please ensure that you do not have any updates pending")
else:
logging.info("- Recommend rebooting the machine and trying to patch again")

Expand Down

0 comments on commit 86e88bf

Please sign in to comment.