From f06d7f2179f327acdfbd611da1a5ed8591a599fd Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Wed, 16 Nov 2022 16:26:10 -0700 Subject: [PATCH] kdk_handler.py: Download KDKs from mirror Reference: https://github.com/dortania/OpenCore-Legacy-Patcher/issues/1016 --- CHANGELOG.md | 2 ++ resources/kdk_handler.py | 45 ++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c94b2272..315624d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - Alleviates kernel panic when on prolonged idle - Automatically remove unsupported News Widgets on Ivy Bridge and Haswell iGPUs - Alleviates Notification Centre Crashing + - Implement downloading from Kernel Debug Kit Backup Repository + - Alleviates issues with Apple blocking KDK downloads from OCLP (Ref: [Issue #1016](https://github.com/dortania/OpenCore-Legacy-Patcher/issues/1016)) - Work-around MacPro6,1 and Lilu race condition - Ensure Model and Board ID are set correctly before Lilu loads - Publish Application Version in UI header diff --git a/resources/kdk_handler.py b/resources/kdk_handler.py index 04c1d1faf..dbebefac7 100644 --- a/resources/kdk_handler.py +++ b/resources/kdk_handler.py @@ -180,18 +180,29 @@ class kernel_debug_kit_handler: return False, msg, "" elif result == 2: msg = "Could not contact Apple download servers" - print(f"- {msg}") - return False, msg, "" + download_link = self.kdk_backup_site(closest_build) + if download_link is None: + msg += " and could not find a backup copy online" + print(f"- {msg}") + return False, msg, "" else: msg = "Unknown error" print(f"- {msg}") return False, msg, "" elif result == 2: msg = "Could not contact Apple download servers" - print(f"- {msg}") - return False, msg, "" + download_link = self.kdk_backup_site(build) + if download_link is None: + msg += " and could not find a backup copy online" + print(f"- {msg}") + return False, msg, "" - if utilities.download_apple_developer_portal(download_link, self.constants.kdk_download_path): + if "github" in download_link: + result = utilities.download_file(download_link, self.constants.kdk_download_path) + else: + result = utilities.download_apple_developer_portal(download_link, self.constants.kdk_download_path) + + if result: result = subprocess.run(["hdiutil", "verify", self.constants.kdk_download_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if result.returncode != 0: print(f"Error: Kernel Debug Kit checksum verification failed!") @@ -247,4 +258,26 @@ class kernel_debug_kit_handler: if should_remove is False: continue print(f" - Removing {kdk_folder.name}") - utilities.elevated(["rm", "-rf", kdk_folder], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) \ No newline at end of file + utilities.elevated(["rm", "-rf", kdk_folder], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + + def kdk_backup_site(self, build): + KDK_MIRROR_REPOSITORY = "https://api.github.com/repos/khronokernel/KDK-Mirror/releases" + + # Check if tag exists + catalog = requests.get(KDK_MIRROR_REPOSITORY) + if catalog.status_code != 200: + print(f"- Could not contact KDK mirror repository") + return None + + catalog = catalog.json() + + for release in catalog: + if release["tag_name"] == build: + print(f"- Found KDK mirror for build: {build}") + for asset in release["assets"]: + if asset["name"].endswith(".dmg"): + return asset["browser_download_url"] + + print(f"- Could not find KDK mirror for build {build}") + return None \ No newline at end of file