forked from dortania/OpenCore-Legacy-Patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOCLP-CLI.command
executable file
·165 lines (144 loc) · 8.73 KB
/
OCLP-CLI.command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python3
# Copyright (C) 2020-2021 Mykola Grymalyuk
from __future__ import print_function
import subprocess
import sys
import time
import platform
import argparse
from pathlib import Path
from Resources import Build, ModelArray, Constants, SysPatch, Utilities, CliMenu
class OpenCoreLegacyPatcher():
def __init__(self):
self.constants = Constants.Constants()
self.current_model: str = None
opencore_model: str = subprocess.run("nvram 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:oem-product".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
if not opencore_model.startswith("nvram: Error getting variable"):
opencore_model = [line.strip().split(":oem-product ", 1)[1] for line in opencore_model.split("\n") if line.strip().startswith("4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:")][0]
self.current_model = opencore_model
else:
self.current_model = subprocess.run("system_profiler SPHardwareDataType".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
self.current_model = [line.strip().split(": ", 1)[1] for line in self.current_model.stdout.decode().split("\n") if line.strip().startswith("Model Identifier")][0]
self.constants.detected_os = int(platform.uname().release.partition(".")[0])
if self.current_model in ModelArray.NoAPFSsupport:
self.constants.serial_settings = "Moderate"
if self.current_model in ModelArray.LegacyGPU:
Build.BuildOpenCore(self.constants.custom_model or self.current_model, self.constants).check_pciid(False)
if not (self.constants.dgpu_vendor == self.constants.pci_amd_ati and self.constants.dgpu_device in ModelArray.AMDMXMGPUs) or not (self.constants.dgpu_vendor == self.constants.pci_nvidia and self.constants.dgpu_device in ModelArray.NVIDIAMXMGPUs):
self.constants.sip_status = False
self.constants.secure_status = False
# Logic for when user runs custom OpenCore build and do not expose it
# Note: This logic currently only applies for iMacPro1,1 users, see below threads on the culprits:
# - https://forums.macrumors.com/threads/2011-imac-graphics-card-upgrade.1596614/post-17425857
# - https://forums.macrumors.com/threads/opencore-on-the-mac-pro.2207814/
# PLEASE FOR THE LOVE OF GOD JUST SET ExposeSensitiveData CORRECTLY!!!
if self.current_model == "iMacPro1,1":
serial: str = subprocess.run("system_profiler SPHardwareDataType | grep Serial".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
serial = [line.strip().split("Number (system): ", 1)[1] for line in serial.split("\n") if line.strip().startswith("Serial")][0]
true_model = subprocess.run([str(self.constants.macserial_path), "--info", str(serial)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
true_model = [i.partition(" - ")[2] for i in true_model.stdout.decode().split("\n") if "Model: " in i][0]
print(f"True Model: {true_model}")
if not true_model.startswith("Unknown"):
self.current_model = true_model
parser = argparse.ArgumentParser()
# Generic building args
parser.add_argument('--build', help='Build OpenCore', action='store_true', required=False)
parser.add_argument('--verbose', help='Enable verbose boot', action='store_true', required=False)
parser.add_argument('--debug_oc', help='Enable OpenCore DEBUG', action='store_true', required=False)
parser.add_argument('--debug_kext', help='Enable kext DEBUG', action='store_true', required=False)
parser.add_argument('--skip_wifi', help='Skip wifi patches', action='store_true', required=False)
parser.add_argument('--hide_picker', help='Hide OpenCore picker', action='store_true', required=False)
parser.add_argument('--disable_sip', help='Disable SIP', action='store_true', required=False)
parser.add_argument('--disable_smb', help='Disable SecureBootModel', action='store_true', required=False)
parser.add_argument('--vault', help='Enable OpenCore Vaulting', action='store_true', required=False)
# Building args requiring value values
parser.add_argument('--model', action='store', help='Set custom model', required=False)
parser.add_argument('--metal_gpu', action='store', help='Set Metal GPU Vendor', required=False)
parser.add_argument('--smbios_spoof', action='store', help='Set SMBIOS patching mode', required=False)
# SysPatch args
parser.add_argument('--patch_sys_vol', help='Patches root volume', action='store_true', required=False)
parser.add_argument('--unpatch_sys_vol', help='Unpatches root volume, EXPERIMENTAL', action='store_true', required=False)
parser.add_argument('--custom_repo', action='store', help='Set SMBIOS patching mode', required=False)
args = parser.parse_args()
self.constants.gui_mode = True
self.constants.current_path = Path.cwd()
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
print("- Rerouting payloads location")
self.constants.payload_path = sys._MEIPASS / Path("payloads")
else:
print("- Using default payloads location")
if args.verbose:
print("- Set verbose configuration")
self.constants.verbose_debug = True
if args.debug_oc:
print("- Set OpenCore DEBUG configuration")
self.constants.opencore_debug = True
self.constants.opencore_build = "DEBUG"
if args.debug_kext:
print("- Set kext DEBUG configuration")
self.constants.kext_debug = True
if args.skip_wifi:
print("- Set wifi skip configuration")
self.constants.wifi_build = True
if args.hide_picker:
print("- Set HidePicker configuration")
self.constants.showpicker = False
if args.disable_sip:
print("- Set Disable SIP configuration")
self.constants.sip_status = False
if args.disable_smb:
print("- Set Disable SecureBootModel configuration")
self.constants.secure_status = False
if args.vault:
print("- Set Vault configuration")
self.constants.vault = True
if args.metal_gpu:
if args.metal_gpu == "Nvidia":
print("- Set Metal GPU patches to Nvidia")
self.constants.metal_build = True
self.constants.imac_vendor = "Nvidia"
elif args.metal_gpu == "AMD":
print("- Set Metal GPU patches to AMD")
self.constants.metal_build = True
self.constants.imac_vendor = "AMD"
else:
print(f"- Unknown GPU arg passed: {args.metal_gpu}")
self.constants.metal_build = False
self.constants.imac_vendor = "None"
if args.smbios_spoof:
if args.smbios_spoof == "Minimal":
self.constants.serial_settings = "Minimal"
elif args.smbios_spoof == "Moderate":
self.constants.serial_settings = "Moderate"
elif args.smbios_spoof == "Advanced":
self.constants.serial_settings = "Advanced"
else:
print(f"- Unknown SMBIOS arg passed: {args.smbios_spoof}")
if args.build:
if args.model:
print(f"- Using custom model: {args.model}")
self.constants.custom_model = args.model
self.build_opencore()
else:
print(f"- Using detected model: {self.current_model}")
self.build_opencore()
if args.patch_sys_vol:
print("- Set System Volume patching")
if args.custom_repo:
self.constants.url_apple_binaries = args.custom_repo
print(f"- Custom set repo to: {self.constants.url_apple_binaries}")
self.patch_vol()
elif args.unpatch_sys_vol:
print("- Set System Volume unpatching")
self.unpatch_vol()
def patch_vol(self):
SysPatch.PatchSysVolume(self.constants.custom_model or self.current_model, self.constants).start_patch()
def unpatch_vol(self):
SysPatch.PatchSysVolume(self.constants.custom_model or self.current_model, self.constants).start_unpatch()
def build_opencore(self):
Build.BuildOpenCore(self.constants.custom_model or self.current_model, self.constants).build_opencore()
def install_opencore(self):
Build.BuildOpenCore(self.constants.custom_model or self.current_model, self.constants).copy_efi()
OpenCoreLegacyPatcher()
# Example arg for OCLP command line
# ./OCLP-CLI --build --verbose --debug_oc --debug_kext --model iMac11,2