mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-13 20:28:21 +10:00
OpenCore: Refactor generation script
Ensures utilities shipped with OpenCorePkg are always in-sync
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,89 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# Simple script to delete unnecessary files from OpenCore and move into place
|
||||
# To use, simply :
|
||||
# - Download an OpenCore build
|
||||
# - Place the X64 folder in the /payloads/OpenCore folder
|
||||
# - Rename to OpenCore-VERSION (ie. DEBUG or RELEASE)
|
||||
# - Run script
|
||||
# - Rename folders to appropriate versions (ie. OpenCore-Build)
|
||||
# - Zip folders
|
||||
# TODO:
|
||||
# - Download latest builds from dortania.github.io
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
build_types = [
|
||||
"DEBUG",
|
||||
"RELEASE",
|
||||
]
|
||||
|
||||
bad_drivers = [
|
||||
"AudioDxe.efi",
|
||||
"BiosVideo.efi",
|
||||
"CrScreenshotDxe.efi",
|
||||
"Ext4Dxe.efi",
|
||||
"HiiDatabase.efi",
|
||||
"NvmExpressDxe.efi",
|
||||
"OpenHfsPlus.efi",
|
||||
"OpenNtfsDxe.efi",
|
||||
"OpenPartitionDxe.efi",
|
||||
"OpenUsbKbDxe.efi",
|
||||
"OpenVariableRuntimeDxe.efi",
|
||||
"Ps2KeyboardDxe.efi",
|
||||
"Ps2MouseDxe.efi",
|
||||
"ToggleSipEntry.efi",
|
||||
"UsbMouseDxe.efi",
|
||||
"XhciDxe.efi",
|
||||
"Udp4Dxe.efi",
|
||||
"TcpDxe.efi",
|
||||
"SnpDxe.efi",
|
||||
"MnpDxe.efi",
|
||||
"Ip4Dxe.efi",
|
||||
"HttpUtilitiesDxe.efi",
|
||||
"HttpDxe.efi",
|
||||
"HttpBootDxe.efi",
|
||||
"DpcDxe.efi",
|
||||
"DnsDxe.efi",
|
||||
"Dhcp4Dxe.efi",
|
||||
"ArpDxe.efi",
|
||||
]
|
||||
|
||||
bad_tools = [
|
||||
"ChipTune.efi",
|
||||
"CleanNvram.efi",
|
||||
"ControlMsrE2.efi",
|
||||
"GopStop.efi",
|
||||
"KeyTester.efi",
|
||||
"MmapDump.efi",
|
||||
"OpenControl.efi",
|
||||
"ResetSystem.efi",
|
||||
"RtcRw.efi",
|
||||
"CsrUtil.efi",
|
||||
"TpmInfo.efi",
|
||||
]
|
||||
|
||||
for version in build_types:
|
||||
print("- Creating S/L/C")
|
||||
subprocess.run(f"mkdir -p ./OpenCore-{version}/System/Library/CoreServices".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
print("- Creating boot.efi Bootstrap")
|
||||
subprocess.run(f"cp ./OpenCore-{version}/EFI/BOOT/BOOTx64.efi ./OpenCore-{version}/System/Library/CoreServices/boot.efi".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
print("- Deleting old BOOTx64.efi")
|
||||
subprocess.run(f"rm -R ./OpenCore-{version}/EFI/BOOT/".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
for delete_drivers in bad_drivers:
|
||||
if Path(f"./OpenCore-{version}/EFI/OC/Drivers/{delete_drivers}").exists():
|
||||
print(f"- Deleting {delete_drivers}")
|
||||
subprocess.run(f"rm ./OpenCore-{version}/EFI/OC/Drivers/{delete_drivers}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
else:
|
||||
print(f"- Unable to find {delete_drivers}, skipping")
|
||||
for delete_tools in bad_tools:
|
||||
if Path(f".//OpenCore-{version}/EFI/OC/Tools/{delete_tools}").exists():
|
||||
print(f"- Deleting {delete_tools}")
|
||||
subprocess.run(f"rm ./OpenCore-{version}/EFI/OC/Tools/{delete_tools}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
else:
|
||||
print(f"- Unable to find {delete_tools}, skipping")
|
||||
|
||||
print("- Renaming folder to OpenCore-Build and zipping")
|
||||
subprocess.run(f"mv ./OpenCore-{version} ./OpenCore-Build".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
subprocess.run(f"zip -r ./OpenCore-{version}.zip ./OpenCore-Build".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
subprocess.run(f"rm -rf ./OpenCore-Build".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
|
||||
258
payloads/OpenCore/generate.command
Executable file
258
payloads/OpenCore/generate.command
Executable file
@@ -0,0 +1,258 @@
|
||||
#!/usr/bin/env python3
|
||||
# Simple script to delete unnecessary files from OpenCore and move into place
|
||||
# To use, simply :
|
||||
# - Download OpenCore-{VERSION}-{VARIANT}.zip
|
||||
# - https://github.com/acidanthera/OpenCorePkg/releases
|
||||
# - Place zips in same directory as this script
|
||||
# - Run script
|
||||
# TODO:
|
||||
# - Download latest builds from dortania.github.io
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
BUILD_VARIANTS = [
|
||||
"DEBUG",
|
||||
"RELEASE"
|
||||
]
|
||||
|
||||
UNUSED_DRIVERS = [
|
||||
"AudioDxe.efi",
|
||||
"BiosVideo.efi",
|
||||
"CrScreenshotDxe.efi",
|
||||
"Ext4Dxe.efi",
|
||||
"HiiDatabase.efi",
|
||||
"NvmExpressDxe.efi",
|
||||
"OpenHfsPlus.efi",
|
||||
"OpenNtfsDxe.efi",
|
||||
"OpenPartitionDxe.efi",
|
||||
"OpenUsbKbDxe.efi",
|
||||
"OpenVariableRuntimeDxe.efi",
|
||||
"Ps2KeyboardDxe.efi",
|
||||
"Ps2MouseDxe.efi",
|
||||
"ToggleSipEntry.efi",
|
||||
"UsbMouseDxe.efi",
|
||||
"XhciDxe.efi",
|
||||
"Udp4Dxe.efi",
|
||||
"TcpDxe.efi",
|
||||
"SnpDxe.efi",
|
||||
"MnpDxe.efi",
|
||||
"Ip4Dxe.efi",
|
||||
"HttpUtilitiesDxe.efi",
|
||||
"HttpDxe.efi",
|
||||
"HttpBootDxe.efi",
|
||||
"DpcDxe.efi",
|
||||
"DnsDxe.efi",
|
||||
"Dhcp4Dxe.efi",
|
||||
"ArpDxe.efi",
|
||||
]
|
||||
|
||||
UNUSED_TOOLS = [
|
||||
"ChipTune.efi",
|
||||
"CleanNvram.efi",
|
||||
"ControlMsrE2.efi",
|
||||
"GopStop.efi",
|
||||
"KeyTester.efi",
|
||||
"MmapDump.efi",
|
||||
"OpenControl.efi",
|
||||
"ResetSystem.efi",
|
||||
"RtcRw.efi",
|
||||
"CsrUtil.efi",
|
||||
"TpmInfo.efi",
|
||||
]
|
||||
|
||||
IMPORTANT_UTILITIES = [
|
||||
"macserial",
|
||||
"ocvalidate",
|
||||
]
|
||||
|
||||
|
||||
|
||||
class GenerateOpenCore:
|
||||
|
||||
def __init__(self):
|
||||
print("Generating new OpenCore bundles...")
|
||||
|
||||
self.working_dir = None
|
||||
|
||||
self.set_directory()
|
||||
self.validate_files()
|
||||
self.generate()
|
||||
|
||||
print("New OpenCore bundles generated!")
|
||||
|
||||
def set_directory(self):
|
||||
self.working_dir = Path(__file__).parent.absolute()
|
||||
print(f"Working directory: {self.working_dir}")
|
||||
|
||||
self.debug_zip = None
|
||||
self.release_zip = None
|
||||
|
||||
# Find OpenCore DEBUG zip
|
||||
for file in self.working_dir.iterdir():
|
||||
if file.name.endswith(".zip") and "DEBUG" in file.name:
|
||||
print(f" Found DEBUG zip: {file.name}")
|
||||
self.debug_zip = file
|
||||
|
||||
# Find OpenCore RELEASE zip
|
||||
for file in self.working_dir.iterdir():
|
||||
if file.name.endswith(".zip") and "RELEASE" in file.name:
|
||||
print(f" Found RELEASE zip: {file.name}")
|
||||
self.release_zip = file
|
||||
|
||||
if self.debug_zip is None:
|
||||
raise FileNotFoundError("DEBUG zip not found!")
|
||||
|
||||
if self.release_zip is None:
|
||||
raise FileNotFoundError("RELEASE zip not found!")
|
||||
|
||||
|
||||
# Unzip both, rename to OpenCore-DEBUG and OpenCore-RELEASE
|
||||
print("Unzipping DEBUG zip...")
|
||||
subprocess.run (
|
||||
["unzip", f"{self.debug_zip}", "-d", f"{self.working_dir}/OpenCore-DEBUG-ROOT"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
print("Unzipping RELEASE zip...")
|
||||
subprocess.run (
|
||||
["unzip", f"{self.release_zip}", "-d", f"{self.working_dir}/OpenCore-RELEASE-ROOT"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
for variant in BUILD_VARIANTS:
|
||||
print(f"Moving {variant} folder...")
|
||||
subprocess.run (
|
||||
["mv", f"{self.working_dir}/OpenCore-{variant}-ROOT/X64", f"{self.working_dir}/OpenCore-{variant}"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
if variant == "DEBUG":
|
||||
for utility in IMPORTANT_UTILITIES:
|
||||
print(f"Moving {utility} from {variant} variant...")
|
||||
subprocess.run (
|
||||
["rm", "-rf", f"{self.working_dir}/{utility}"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
subprocess.run (
|
||||
["mv", f"{self.working_dir}/OpenCore-{variant}-ROOT/Utilities/{utility}/{utility}", f"{self.working_dir}/{utility}"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
# Remove root folder
|
||||
subprocess.run (
|
||||
["rm", "-rf", f"{self.working_dir}/OpenCore-{variant}-ROOT"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
# Remove zip files
|
||||
print("Removing zip files...")
|
||||
# remove debug_zip
|
||||
subprocess.run (
|
||||
["rm", "-rf", self.debug_zip],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
# remove release_zip
|
||||
subprocess.run (
|
||||
["rm", "-rf", self.release_zip],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
|
||||
def clean_old_bundles(self):
|
||||
print("Cleaning old bundles...")
|
||||
for variant in BUILD_VARIANTS:
|
||||
if (self.working_dir / f"OpenCore-{variant}").exists():
|
||||
print(f" Deleting old {variant} variant...")
|
||||
subprocess.run (
|
||||
["rm", "-rf", f"{self.working_dir}/OpenCore-{variant}"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
def validate_files(self):
|
||||
for variant in BUILD_VARIANTS:
|
||||
if not (self.working_dir / f"OpenCore-{variant}").exists():
|
||||
raise FileNotFoundError(f"OpenCore-{variant} folder not found!")
|
||||
|
||||
def generate(self):
|
||||
for variant in BUILD_VARIANTS:
|
||||
print(f"Generating {variant} variant...")
|
||||
self.generate_opencore(variant)
|
||||
|
||||
def generate_opencore(self, variant):
|
||||
# Create S/L/C
|
||||
print(" Creating SLC folder")
|
||||
subprocess.run (
|
||||
["mkdir", "-p", f"{self.working_dir}/OpenCore-{variant}/System/Library/CoreServices"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
# Relocate contents of /EFI/BOOT to /S/L/C
|
||||
print(" Relocating BOOT folder to SLC")
|
||||
for file in (self.working_dir / f"OpenCore-{variant}/EFI/BOOT").iterdir():
|
||||
subprocess.run (
|
||||
["mv", f"{file}", f"{self.working_dir}/OpenCore-{variant}/System/Library/CoreServices"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
# Rename BOOTx64.efi to boot.efi
|
||||
print(" Renaming BOOTx64.efi to boot.efi")
|
||||
subprocess.run (
|
||||
["mv", f"{self.working_dir}/OpenCore-{variant}/System/Library/CoreServices/BOOTx64.efi", f"{self.working_dir}/OpenCore-{variant}/System/Library/CoreServices/boot.efi"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
# Delete BOOT folder
|
||||
print(" Deleting BOOT folder")
|
||||
subprocess.run (
|
||||
["rm", "-rf", f"{self.working_dir}/OpenCore-{variant}/EFI/BOOT"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
# Delete unused drivers
|
||||
print(" Deleting unused drivers")
|
||||
for driver in UNUSED_DRIVERS:
|
||||
if Path(f"{self.working_dir}/OpenCore-{variant}/EFI/OC/Drivers/{driver}").exists():
|
||||
print(f" Deleting {driver}")
|
||||
subprocess.run (
|
||||
["rm", f"{self.working_dir}/OpenCore-{variant}/EFI/OC/Drivers/{driver}"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
else:
|
||||
print(f" {driver} not found")
|
||||
|
||||
# Delete unused tools
|
||||
print(" Deleting unused tools")
|
||||
for tool in UNUSED_TOOLS:
|
||||
if Path(f"{self.working_dir}/OpenCore-{variant}/EFI/OC/Tools/{tool}").exists():
|
||||
print(f" Deleting {tool}")
|
||||
subprocess.run (
|
||||
["rm", f"{self.working_dir}/OpenCore-{variant}/EFI/OC/Tools/{tool}"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
else:
|
||||
print(f" {tool} not found")
|
||||
|
||||
# Rename OpenCore-<variant> to OpenCore-Build
|
||||
print(" Renaming OpenCore folder")
|
||||
subprocess.run (
|
||||
["mv", f"{self.working_dir}/OpenCore-{variant}", f"{self.working_dir}/OpenCore-Build"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
# Create OpenCore-<variant>.zip
|
||||
print(" Creating OpenCore.zip")
|
||||
subprocess.run (
|
||||
["ditto", "-c", "-k", "--sequesterRsrc", "--keepParent", f"{self.working_dir}/OpenCore-Build", f"{self.working_dir}/OpenCore-{variant}.zip"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
# Delete OpenCore-Build
|
||||
print(" Deleting OpenCore-Build")
|
||||
subprocess.run (
|
||||
["rm", "-rf", f"{self.working_dir}/OpenCore-Build"],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
GenerateOpenCore()
|
||||
BIN
payloads/OpenCore/macserial
Executable file
BIN
payloads/OpenCore/macserial
Executable file
Binary file not shown.
Binary file not shown.
@@ -570,7 +570,7 @@ class Constants:
|
||||
# Tools
|
||||
@property
|
||||
def macserial_path(self):
|
||||
return self.payload_path / Path("Tools/macserial")
|
||||
return self.payload_path / Path("OpenCore/macserial")
|
||||
|
||||
@property
|
||||
def gfxutil_path(self):
|
||||
@@ -582,7 +582,7 @@ class Constants:
|
||||
|
||||
@property
|
||||
def ocvalidate_path(self):
|
||||
return self.payload_path / Path(f"Tools/ocvalidate-{self.opencore_version}")
|
||||
return self.payload_path / Path(f"OpenCore/ocvalidate")
|
||||
|
||||
@property
|
||||
def oclp_helper_path(self):
|
||||
|
||||
Reference in New Issue
Block a user