kdk_handler.py: Download KDKs from mirror

Reference: https://github.com/dortania/OpenCore-Legacy-Patcher/issues/1016
This commit is contained in:
Mykola Grymalyuk
2022-11-16 16:26:10 -07:00
parent d5d2a7fbfe
commit f06d7f2179
2 changed files with 41 additions and 6 deletions
+2
View File
@@ -10,6 +10,8 @@
- Alleviates kernel panic when on prolonged idle - Alleviates kernel panic when on prolonged idle
- Automatically remove unsupported News Widgets on Ivy Bridge and Haswell iGPUs - Automatically remove unsupported News Widgets on Ivy Bridge and Haswell iGPUs
- Alleviates Notification Centre Crashing - 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 - Work-around MacPro6,1 and Lilu race condition
- Ensure Model and Board ID are set correctly before Lilu loads - Ensure Model and Board ID are set correctly before Lilu loads
- Publish Application Version in UI header - Publish Application Version in UI header
+38 -5
View File
@@ -180,18 +180,29 @@ class kernel_debug_kit_handler:
return False, msg, "" return False, msg, ""
elif result == 2: elif result == 2:
msg = "Could not contact Apple download servers" msg = "Could not contact Apple download servers"
print(f"- {msg}") download_link = self.kdk_backup_site(closest_build)
return False, msg, "" if download_link is None:
msg += " and could not find a backup copy online"
print(f"- {msg}")
return False, msg, ""
else: else:
msg = "Unknown error" msg = "Unknown error"
print(f"- {msg}") print(f"- {msg}")
return False, msg, "" return False, msg, ""
elif result == 2: elif result == 2:
msg = "Could not contact Apple download servers" msg = "Could not contact Apple download servers"
print(f"- {msg}") download_link = self.kdk_backup_site(build)
return False, msg, "" 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) result = subprocess.run(["hdiutil", "verify", self.constants.kdk_download_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0: if result.returncode != 0:
print(f"Error: Kernel Debug Kit checksum verification failed!") print(f"Error: Kernel Debug Kit checksum verification failed!")
@@ -248,3 +259,25 @@ class kernel_debug_kit_handler:
continue continue
print(f" - Removing {kdk_folder.name}") print(f" - Removing {kdk_folder.name}")
utilities.elevated(["rm", "-rf", kdk_folder], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 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