Use full path and arguments for subprocess

This commit is contained in:
Mykola Grymalyuk
2023-12-30 13:49:59 -07:00
parent b46e55d3f6
commit 0dfcf03c0c
23 changed files with 152 additions and 154 deletions

View File

@@ -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")
@@ -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):
@@ -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):

View File

@@ -128,24 +128,24 @@ 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
)
@@ -153,12 +153,12 @@ class GenerateOpenCore:
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
)
@@ -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
)
@@ -212,7 +212,7 @@ 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
)
@@ -220,21 +220,21 @@ class GenerateOpenCore:
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
)
@@ -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:
@@ -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:
@@ -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
)