Skip to content

Commit

Permalink
Use full path and arguments for subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
khronokernel committed Dec 30, 2023
1 parent b46e55d commit 0dfcf03
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 154 deletions.
20 changes: 9 additions & 11 deletions Build-Binary.command
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class CreateBinary:
if Path(f"./dist/OpenCore-Patcher.app").exists():
print("Found OpenCore-Patcher.app, removing...")
rm_output = subprocess.run(
["rm", "-rf", "./dist/OpenCore-Patcher.app"],
["/bin/rm", "-rf", "./dist/OpenCore-Patcher.app"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if rm_output.returncode != 0:
Expand All @@ -152,13 +152,11 @@ class CreateBinary:
print("Embedding icns...")
for file in Path("payloads/Icon/AppIcons").glob("*.icns"):
subprocess.run(
["cp", str(file), "./dist/OpenCore-Patcher.app/Contents/Resources/"],
["/bin/cp", str(file), "./dist/OpenCore-Patcher.app/Contents/Resources/"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)




def _embed_key(self):
"""
Embed developer key into binary
Expand Down Expand Up @@ -252,12 +250,12 @@ class CreateBinary:
if file.name in whitelist_folders:
continue
print(f"- Deleting {file.name}")
subprocess.run(["rm", "-rf", file])
subprocess.run(["/bin/rm", "-rf", file])
else:
if file.name in whitelist_files:
continue
print(f"- Deleting {file.name}")
subprocess.run(["rm", "-f", file])
subprocess.run(["/bin/rm", "-f", file])


def _download_resources(self):
Expand All @@ -279,7 +277,7 @@ class CreateBinary:
assert resource, "Resource cannot be empty"
assert resource not in ("/", "."), "Resource cannot be root"
rm_output = subprocess.run(
["rm", "-rf", f"./{resource}"],
["/bin/rm", "-rf", f"./{resource}"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if rm_output.returncode != 0:
Expand All @@ -293,7 +291,7 @@ class CreateBinary:

download_result = subprocess.run(
[
"curl", "-LO",
"/usr/bin/curl", "-LO",
f"https://github.com/dortania/PatcherSupportPkg/releases/download/{patcher_support_pkg_version}/{resource}"
],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
Expand Down Expand Up @@ -322,7 +320,7 @@ class CreateBinary:

print("- Removing old payloads.dmg")
rm_output = subprocess.run(
["rm", "-rf", "./payloads.dmg"],
["/bin/rm", "-rf", "./payloads.dmg"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if rm_output.returncode != 0:
Expand All @@ -332,7 +330,7 @@ class CreateBinary:

print("- Generating DMG...")
dmg_output = subprocess.run([
'hdiutil', 'create', './payloads.dmg',
'/usr/bin/hdiutil', 'create', './payloads.dmg',
'-megabytes', '32000', # Overlays can only be as large as the disk image allows
'-format', 'UDZO', '-ov',
'-volname', 'OpenCore Patcher Resources (Base)',
Expand Down Expand Up @@ -410,7 +408,7 @@ class CreateBinary:
path = "./dist/OpenCore-Patcher"
print(f"- Removing {path}")
rm_output = subprocess.run(
["rm", "-rf", path],
["/bin/rm", "-rf", path],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if rm_output.returncode != 0:
Expand Down
28 changes: 14 additions & 14 deletions payloads/Kexts/Update-Kexts.command
Original file line number Diff line number Diff line change
Expand Up @@ -108,36 +108,36 @@ class GenerateKexts:
with tempfile.TemporaryDirectory() as temp_dir:
# Download source
weg_source_zip = f"{temp_dir}/WhateverGreen-{self.weg_version}.zip"
subprocess.run(["curl", "-L", weg_source_url, "-o", weg_source_zip], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["/usr/bin/curl", "--location", weg_source_url, "--output", weg_source_zip], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Unzip source
subprocess.run(["unzip", weg_source_zip, "-d", temp_dir], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["/usr/bin/unzip", weg_source_zip, "-d", temp_dir], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Git clone MacKernelSDK into source
subprocess.run(["git", "clone", "https://github.com/acidanthera/MacKernelSDK", f"{temp_dir}/WhateverGreen-{self.weg_version}/MacKernelSDK"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["/usr/bin/git", "clone", "https://github.com/acidanthera/MacKernelSDK", f"{temp_dir}/WhateverGreen-{self.weg_version}/MacKernelSDK"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Grab latest Lilu release, debug version
lilu_zip = f"{temp_dir}/Lilu-{self.lilu_version}-DEBUG.zip"
subprocess.run(["curl", "-L", lilu_url, "-o", lilu_zip], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["/usr/bin/curl", "--location", lilu_url, "--output", lilu_zip], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Unzip Lilu into WEG source
subprocess.run(["unzip", lilu_zip, "-d", f"{temp_dir}/WhateverGreen-{self.weg_version}"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["/usr/bin/unzip", lilu_zip, "-d", f"{temp_dir}/WhateverGreen-{self.weg_version}"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Apply patch
patch_path = Path("./Acidanthera/WhateverGreen-Navi-Backlight.patch").absolute()
subprocess.run(["git", "apply", patch_path], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=f"{temp_dir}/WhateverGreen-{self.weg_version}")
subprocess.run(["/usr/bin/git", "apply", patch_path], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=f"{temp_dir}/WhateverGreen-{self.weg_version}")

# Build WEG
for variant in ["Release", "Debug"]:
subprocess.run(["xcodebuild", "-configuration", variant], cwd=f"{temp_dir}/WhateverGreen-{self.weg_version}", check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["/usr/bin/xcodebuild", "-configuration", variant], cwd=f"{temp_dir}/WhateverGreen-{self.weg_version}", check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)


# Zip Release
for variant in ["RELEASE", "DEBUG"]:
dst_path = Path(f"./Acidanthera/WhateverGreen-v{self.weg_version}-Navi-{variant}.zip").absolute()
subprocess.run(["zip", "-r", dst_path, "WhateverGreen.kext"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=f"{temp_dir}/WhateverGreen-{self.weg_version}/build/{'Release' if variant == 'RELEASE' else 'Debug'}")
subprocess.run(["/usr/bin/zip", "-r", dst_path, "WhateverGreen.kext"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=f"{temp_dir}/WhateverGreen-{self.weg_version}/build/{'Release' if variant == 'RELEASE' else 'Debug'}")
if Path(f"./Acidanthera/WhateverGreen-v{self.weg_old}-Navi-{variant}.zip").exists():
subprocess.run(["rm", f"./Acidanthera/WhateverGreen-v{self.weg_old}-Navi-{variant}.zip"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["/bin/rm", f"./Acidanthera/WhateverGreen-v{self.weg_old}-Navi-{variant}.zip"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

self._update_constants_file("self.whatevergreen_navi_version", f"{self.weg_old}-Navi", f"{self.weg_version}-Navi")

Expand Down Expand Up @@ -212,14 +212,14 @@ class GenerateKexts:
zip_name = f"{override_kext_zip_name}-v{remote_version}-{variant}.zip" if override_kext_zip_name else f"{kext_name}-v{remote_version}-{variant}.zip"

if Path(f"./{kext_folder}/{zip_name.replace(f'v{remote_version}', f'v{local_version}')}").exists():
subprocess.run(["rm", "-rf", f"./{kext_folder}/{zip_name.replace(f'v{remote_version}', f'v{local_version}')}"])
subprocess.run(["/bin/rm", "-rf", f"./{kext_folder}/{zip_name.replace(f'v{remote_version}', f'v{local_version}')}"])
self._download_file(asset["browser_download_url"], f"./{kext_folder}/{zip_name}", f"{kext_name}.kext")
self._update_constants_file(KEXT_DICTIONARY[kext_folder][kext_name]["Constants Variable"], local_version, remote_version)

if override_kext_zip_name:
# rename zip file
os.rename(f"./{kext_folder}/{zip_name}", f"./{kext_folder}/{kext_name}-v{remote_version}-{variant}.zip")
subprocess.run(["rm", "-rf", f"./{kext_folder}/{kext_name}-v{local_version}-{variant}.zip"])
subprocess.run(["/bin/rm", "-rf", f"./{kext_folder}/{kext_name}-v{local_version}-{variant}.zip"])


def _get_local_version(self, kext_folder, kext_name, variant):
Expand Down Expand Up @@ -247,14 +247,14 @@ class GenerateKexts:
f.write(download.content)

# Unzip file
subprocess.run(["unzip", "-q", f"{temp_dir}/temp.zip", "-d", f"{temp_dir}"], check=True)
subprocess.run(["/usr/bin/unzip", "-q", f"{temp_dir}/temp.zip", "-d", f"{temp_dir}"], check=True)

print(f" Moving {file} to {file_path}...")
# Zip file
subprocess.run(["zip", "-q", "-r", Path(file_path).name, file], cwd=f"{temp_dir}", check=True)
subprocess.run(["/usr/bin/zip", "-q", "-r", Path(file_path).name, file], cwd=f"{temp_dir}", check=True)

# Move file
subprocess.run(["mv", f"{temp_dir}/{Path(file_path).name}", file_path], check=True)
subprocess.run(["/bin/mv", f"{temp_dir}/{Path(file_path).name}", file_path], check=True)


def _update_constants_file(self, variable_name, old_version, new_version):
Expand Down
32 changes: 16 additions & 16 deletions payloads/OpenCore/Update-OpenCore.command
Original file line number Diff line number Diff line change
Expand Up @@ -128,37 +128,37 @@ class GenerateOpenCore:
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}"],
["/bin/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}"],
["/bin/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}"],
["/bin/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"],
["/bin/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],
["/bin/rm", "-rf", self.debug_zip],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
# remove release_zip
subprocess.run (
["rm", "-rf", self.release_zip],
["/bin/rm", "-rf", self.release_zip],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)

Expand Down Expand Up @@ -194,7 +194,7 @@ class GenerateOpenCore:
if (self.working_dir / f"OpenCore-{variant}").exists():
print(f" Deleting old {variant} variant...")
subprocess.run (
["rm", "-rf", f"{self.working_dir}/OpenCore-{variant}"],
["/bin/rm", "-rf", f"{self.working_dir}/OpenCore-{variant}"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)

Expand All @@ -212,29 +212,29 @@ class GenerateOpenCore:
# Create S/L/C
print(" Creating SLC folder")
subprocess.run (
["mkdir", "-p", f"{self.working_dir}/OpenCore-{variant}/System/Library/CoreServices"],
["/bin/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"],
["/bin/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"],
["/bin/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"],
["/bin/rm", "-rf", f"{self.working_dir}/OpenCore-{variant}/EFI/BOOT"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)

Expand All @@ -244,7 +244,7 @@ class GenerateOpenCore:
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}"],
["/bin/rm", f"{self.working_dir}/OpenCore-{variant}/EFI/OC/Drivers/{driver}"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
else:
Expand All @@ -256,7 +256,7 @@ class GenerateOpenCore:
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}"],
["/bin/rm", f"{self.working_dir}/OpenCore-{variant}/EFI/OC/Tools/{tool}"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
else:
Expand All @@ -265,21 +265,21 @@ class GenerateOpenCore:
# 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"],
["/bin/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"],
["/usr/bin/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"],
["/bin/rm", "-rf", f"{self.working_dir}/OpenCore-Build"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)

Expand Down
4 changes: 2 additions & 2 deletions resources/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _cache_os_handler(self) -> None:
"""
Fetch KDK for incoming OS
"""
results = subprocess.run(["ps", "-ax"], stdout=subprocess.PIPE)
results = subprocess.run(["/bin/ps", "-ax"], stdout=subprocess.PIPE)
if results.stdout.decode("utf-8").count("OpenCore-Patcher --cache_os") > 1:
logging.info("Another instance of OS caching is running, exiting")
return
Expand Down Expand Up @@ -154,7 +154,7 @@ def _clean_le_handler(self) -> None:
if "GPUCompanionBundles" not in kext_plist:
continue
logging.info(f" - Removing {kext.name}")
subprocess.run(["rm", "-rf", kext])
subprocess.run(["/bin/rm", "-rf", kext])


def _build_handler(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions resources/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ def _gpu_probe(self) -> None:

for key in ["Moraea_BlurBeta"]:
# Enable BetaBlur if user hasn't disabled it
is_key_enabled = subprocess.run(["defaults", "read", "-g", key], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
is_key_enabled = subprocess.run(["/usr/bin/defaults", "read", "-globalDomain", key], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
if is_key_enabled not in ["false", "0"]:
subprocess.run(["defaults", "write", "-g", key, "-bool", "true"])
subprocess.run(["/usr/bin/defaults", "write", "-globalDomain", key, "-bool", "true"])

def _check_amfipass_supported(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion resources/global_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _fix_file_permission(self) -> None:
return

# Set file permission to allow any user to write to log file
result = subprocess.run(["chmod", "777", self.global_settings_plist], capture_output=True)
result = subprocess.run(["/bin/chmod", "777", self.global_settings_plist], capture_output=True)
if result.returncode != 0:
logging.warning("Failed to fix settings file permissions:")
if result.stderr:
Expand Down
Loading

0 comments on commit 0dfcf03

Please sign in to comment.