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

@@ -428,8 +428,8 @@ class macOSInstallerFlashFrame(wx.Frame):
if not str(path).endswith(".zip"):
return
if Path(self.constants.installer_pkg_path).exists():
subprocess.run(["rm", self.constants.installer_pkg_path])
subprocess.run(["ditto", "-V", "-x", "-k", "--sequesterRsrc", "--rsrc", self.constants.installer_pkg_zip_path, self.constants.payload_path])
subprocess.run(["/bin/rm", self.constants.installer_pkg_path])
subprocess.run(["/usr/bin/ditto", "-V", "-x", "-k", "--sequesterRsrc", "--rsrc", self.constants.installer_pkg_zip_path, self.constants.payload_path])
def _install_installer_pkg(self, disk):
@@ -448,8 +448,8 @@ class macOSInstallerFlashFrame(wx.Frame):
logging.info("Installer unsupported, requires Big Sur or newer")
return
subprocess.run(["mkdir", "-p", f"{path}/Library/Packages/"])
subprocess.run(["cp", "-r", self.constants.installer_pkg_path, f"{path}/Library/Packages/"])
subprocess.run(["/bin/mkdir", "-p", f"{path}/Library/Packages/"])
subprocess.run(["/bin/cp", "-r", self.constants.installer_pkg_path, f"{path}/Library/Packages/"])
self._kdk_chainload(os_version["ProductBuildVersion"], os_version["ProductVersion"], Path(path + "/Library/Packages/"))
@@ -512,17 +512,17 @@ class macOSInstallerFlashFrame(wx.Frame):
# Now that we have a KDK, extract it to get the pkg
with tempfile.TemporaryDirectory() as mount_point:
logging.info("Mounting KDK")
result = subprocess.run(["hdiutil", "attach", kdk_dmg_path, "-mountpoint", mount_point, "-nobrowse"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = subprocess.run(["/usr/bin/hdiutil", "attach", kdk_dmg_path, "-mountpoint", mount_point, "-nobrowse"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if result.returncode != 0:
logging.info("Failed to mount KDK")
logging.info(result.stdout.decode("utf-8"))
return
logging.info("Copying KDK")
subprocess.run(["cp", "-r", f"{mount_point}/KernelDebugKit.pkg", kdk_pkg_path])
subprocess.run(["/bin/cp", "-r", f"{mount_point}/KernelDebugKit.pkg", kdk_pkg_path])
logging.info("Unmounting KDK")
result = subprocess.run(["hdiutil", "detach", mount_point], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = subprocess.run(["/usr/bin/hdiutil", "detach", mount_point], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if result.returncode != 0:
logging.info("Failed to unmount KDK")
logging.info(result.stdout.decode("utf-8"))
@@ -545,7 +545,7 @@ class macOSInstallerFlashFrame(wx.Frame):
logging.error(f"Failed to find {dmg_path}")
error_message = f"Failed to find {dmg_path}"
return error_message
result = subprocess.run(["hdiutil", "verify", dmg_path],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = subprocess.run(["/usr/bin/hdiutil", "verify", dmg_path],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0:
if result.stdout:
logging.error(result.stdout.decode("utf-8"))

View File

@@ -261,13 +261,13 @@ class MainFrame(wx.Frame):
if Path("/Applications/OpenCore-Patcher.app").exists() and Path("/Applications/OpenCore-Patcher.app").is_symlink() is False:
logging.info("Found user-installed app in /Applications, replacing with symlink")
# Delete app
result = subprocess.run(["rm", "-rf", "/Applications/OpenCore-Patcher.app"], capture_output=True)
result = subprocess.run(["/bin/rm", "-rf", "/Applications/OpenCore-Patcher.app"], capture_output=True)
if result.returncode != 0:
logging.info("Failed to delete app from /Applications")
return
# Create symlink
result = subprocess.run(["ln", "-s", "/Library/Application Support/Dortania/OpenCore-Patcher.app", "/Applications/OpenCore-Patcher.app"], capture_output=True)
result = subprocess.run(["/bin/ln", "-s", "/Library/Application Support/Dortania/OpenCore-Patcher.app", "/Applications/OpenCore-Patcher.app"], capture_output=True)
if result.returncode != 0:
logging.info("Failed to create symlink to /Applications")
return

View File

@@ -1110,7 +1110,7 @@ Hardware Information:
value_type = "-bool"
logging.info(f"Updating System Defaults: {variable} = {value} ({value_type})")
subprocess.run(["defaults", "write", "-g", variable, value_type, str(value)])
subprocess.run(["/usr/bin/defaults", "write", "-globalDomain", variable, value_type, str(value)])
def _find_parent_for_key(self, key: str) -> str:
@@ -1256,7 +1256,7 @@ Hardware Information:
def _get_system_settings(self, variable) -> bool:
result = subprocess.run(["defaults", "read", "-g", variable], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = subprocess.run(["/usr/bin/defaults", "read", "-globalDomain", variable], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if result.returncode == 0:
try:
return bool(int(result.stdout.decode().strip()))

View File

@@ -64,7 +64,7 @@ class GenerateMenubar:
self.frame.Bind(wx.EVT_MENU, lambda event: gui_about.AboutFrame(self.constants), aboutItem)
self.frame.Bind(wx.EVT_MENU, lambda event: RelaunchApplicationAsRoot(self.frame, self.constants).relaunch(None), relaunchItem)
self.frame.Bind(wx.EVT_MENU, lambda event: subprocess.run(["open", "-R", self.constants.log_filepath]), revealLogItem)
self.frame.Bind(wx.EVT_MENU, lambda event: subprocess.run(["/usr/bin/open", "--reveal", self.constants.log_filepath]), revealLogItem)
if os.geteuid() == 0:
relaunchItem.Enable(False)
@@ -329,7 +329,7 @@ class RelaunchApplicationAsRoot:
# Relaunch as root
args = [
"osascript",
"/usr/bin/osascript",
"-e",
f'''do shell script "{program_arguments}"'''
' with prompt "OpenCore Legacy Patcher needs administrator privileges to relaunch as admin."'

View File

@@ -318,7 +318,7 @@ class SysPatchStartFrame(wx.Frame):
if answer == wx.ID_YES:
output =subprocess.run(
[
"osascript", "-e",
"/usr/bin/osascript", "-e",
'tell app "System Preferences" to activate',
"-e", 'tell app "System Preferences" to reveal anchor "General" of pane id "com.apple.preference.security"',
],
@@ -327,7 +327,7 @@ class SysPatchStartFrame(wx.Frame):
)
if output.returncode != 0:
# Some form of fallback if unaccelerated state errors out
subprocess.run(["open", "-a", "System Preferences"])
subprocess.run(["/usr/bin/open", "-a", "System Preferences"])
time.sleep(5)
sys.exit(0)

View File

@@ -184,13 +184,13 @@ class UpdateFrame(wx.Frame):
"""
logging.info("Extracting update")
if Path(self.application_path).exists():
subprocess.run(["rm", "-rf", str(self.application_path)])
subprocess.run(["/bin/rm", "-rf", str(self.application_path)])
# Some hell spawn at Github decided to double zip our Github Actions artifacts
# So we need to unzip it twice
for i in range(2):
result = subprocess.run(
["ditto", "-xk", str(self.constants.payload_path / "OpenCore-Patcher-GUI.app.zip"), str(self.constants.payload_path)], capture_output=True
["/usr/bin/ditto", "-xk", str(self.constants.payload_path / "OpenCore-Patcher-GUI.app.zip"), str(self.constants.payload_path)], capture_output=True
)
if result.returncode != 0:
logging.error(f"Failed to extract update. Error: {result.stderr.decode('utf-8')}")