mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-23 03:20:16 +10:00
Remove stop gap “supports_privileged_helper()” code
Intended to handle transition better, now that it’s complete the code is no longer required
This commit is contained in:
@@ -116,9 +116,6 @@ class GlobalEnviromentSettings:
|
|||||||
This in turn breaks normal OCLP execution to write to settings file
|
This in turn breaks normal OCLP execution to write to settings file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Set file permission to allow any user to write to log file
|
# Set file permission to allow any user to write to log file
|
||||||
result = subprocess_wrapper.run_as_root(["/bin/chmod", "777", self.global_settings_plist], capture_output=True)
|
result = subprocess_wrapper.run_as_root(["/bin/chmod", "777", self.global_settings_plist], capture_output=True)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
|
|||||||
@@ -92,19 +92,6 @@ class tui_disk_installation:
|
|||||||
def install_opencore(self, full_disk_identifier: str):
|
def install_opencore(self, full_disk_identifier: str):
|
||||||
# TODO: Apple Script fails in Yosemite(?) and older
|
# TODO: Apple Script fails in Yosemite(?) and older
|
||||||
logging.info(f"Mounting partition: {full_disk_identifier}")
|
logging.info(f"Mounting partition: {full_disk_identifier}")
|
||||||
if self.constants.detected_os >= os_data.os_data.el_capitan and not self.constants.recovery_status and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
try:
|
|
||||||
applescript.AppleScript(f'''do shell script "diskutil mount {full_disk_identifier}" with prompt "OpenCore Legacy Patcher needs administrator privileges to mount this volume." with administrator privileges without altering line endings''').run()
|
|
||||||
except applescript.ScriptError as e:
|
|
||||||
if "User canceled" in str(e):
|
|
||||||
logging.info("Mount cancelled by user")
|
|
||||||
return
|
|
||||||
logging.info(f"An error occurred: {e}")
|
|
||||||
if utilities.check_boot_mode() == "safe_boot":
|
|
||||||
logging.info("\nSafe Mode detected. FAT32 is unsupported by macOS in this mode.")
|
|
||||||
logging.info("Please disable Safe Mode and try again.")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
result = subprocess_wrapper.run_as_root(["/usr/sbin/diskutil", "mount", full_disk_identifier], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
result = subprocess_wrapper.run_as_root(["/usr/sbin/diskutil", "mount", full_disk_identifier], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
logging.info("Mount failed")
|
logging.info("Mount failed")
|
||||||
|
|||||||
@@ -464,10 +464,6 @@ class KernelDebugKitObject:
|
|||||||
if self.passive is True:
|
if self.passive is True:
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.getuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
logging.warning("Cannot remove KDK, not running as root")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not Path(kdk_path).exists():
|
if not Path(kdk_path).exists():
|
||||||
logging.warning(f"KDK does not exist: {kdk_path}")
|
logging.warning(f"KDK does not exist: {kdk_path}")
|
||||||
return
|
return
|
||||||
@@ -579,10 +575,6 @@ class KernelDebugKitUtilities:
|
|||||||
bool: True if successful, False if not
|
bool: True if successful, False if not
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if os.getuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
logging.warning("Cannot install KDK, not running as root")
|
|
||||||
return False
|
|
||||||
|
|
||||||
logging.info(f"Installing KDK package: {kdk_path.name}")
|
logging.info(f"Installing KDK package: {kdk_path.name}")
|
||||||
logging.info(f"- This may take a while...")
|
logging.info(f"- This may take a while...")
|
||||||
|
|
||||||
@@ -607,10 +599,6 @@ class KernelDebugKitUtilities:
|
|||||||
bool: True if successful, False if not
|
bool: True if successful, False if not
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if os.getuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
logging.warning("Cannot install KDK, not running as root")
|
|
||||||
return False
|
|
||||||
|
|
||||||
logging.info(f"Extracting downloaded KDK disk image")
|
logging.info(f"Extracting downloaded KDK disk image")
|
||||||
with tempfile.TemporaryDirectory() as mount_point:
|
with tempfile.TemporaryDirectory() as mount_point:
|
||||||
result = subprocess_wrapper.run_as_root(["/usr/bin/hdiutil", "attach", kdk_path, "-mountpoint", mount_point, "-nobrowse"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
result = subprocess_wrapper.run_as_root(["/usr/bin/hdiutil", "attach", kdk_path, "-mountpoint", mount_point, "-nobrowse"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
@@ -669,10 +657,6 @@ class KernelDebugKitUtilities:
|
|||||||
logging.warning("Malformed KDK Info.plist provided, cannot create backup")
|
logging.warning("Malformed KDK Info.plist provided, cannot create backup")
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.getuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
logging.warning("Cannot create KDK backup, not running as root")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not Path(KDK_INSTALL_PATH).exists():
|
if not Path(KDK_INSTALL_PATH).exists():
|
||||||
subprocess_wrapper.run_as_root(["/bin/mkdir", "-p", KDK_INSTALL_PATH], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
subprocess_wrapper.run_as_root(["/bin/mkdir", "-p", KDK_INSTALL_PATH], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
|||||||
@@ -131,9 +131,6 @@ class InitializeLoggingSupport:
|
|||||||
This in turn breaks normal OCLP execution to write to log file
|
This in turn breaks normal OCLP execution to write to log file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
return
|
|
||||||
|
|
||||||
paths = [
|
paths = [
|
||||||
self.log_filepath, # ~/Library/Logs/Dortania/OpenCore-Patcher_{version}_{date}.log
|
self.log_filepath, # ~/Library/Logs/Dortania/OpenCore-Patcher_{version}_{date}.log
|
||||||
self.log_filepath.parent, # ~/Library/Logs/Dortania
|
self.log_filepath.parent, # ~/Library/Logs/Dortania
|
||||||
|
|||||||
@@ -64,19 +64,6 @@ class InstallerCreation():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
logging.info("Extracting macOS installer from InstallAssistant.pkg")
|
logging.info("Extracting macOS installer from InstallAssistant.pkg")
|
||||||
if subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
try:
|
|
||||||
applescript.AppleScript(
|
|
||||||
f'''do shell script "installer -pkg {Path(download_path)}/InstallAssistant.pkg -target /"'''
|
|
||||||
' with prompt "OpenCore Legacy Patcher needs administrator privileges to extract the installer."'
|
|
||||||
" with administrator privileges"
|
|
||||||
" without altering line endings",
|
|
||||||
).run()
|
|
||||||
except Exception as e:
|
|
||||||
logging.info("Failed to install InstallAssistant")
|
|
||||||
logging.info(f" Error Code: {e}")
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
result = subprocess_wrapper.run_as_root(["/usr/sbin/installer", "-pkg", f"{Path(download_path)}/InstallAssistant.pkg", "-target", "/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
result = subprocess_wrapper.run_as_root(["/usr/sbin/installer", "-pkg", f"{Path(download_path)}/InstallAssistant.pkg", "-target", "/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
logging.info("Failed to install InstallAssistant")
|
logging.info("Failed to install InstallAssistant")
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ import logging
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from functools import cache
|
|
||||||
|
|
||||||
from . import utilities
|
|
||||||
|
|
||||||
|
|
||||||
OCLP_PRIVILEGED_HELPER = "/Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper"
|
OCLP_PRIVILEGED_HELPER = "/Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper"
|
||||||
@@ -37,17 +34,6 @@ class PrivilegedHelperErrorCodes(enum.IntEnum):
|
|||||||
OCLP_PHT_ERROR_CATCH_ALL = 170
|
OCLP_PHT_ERROR_CATCH_ALL = 170
|
||||||
|
|
||||||
|
|
||||||
@cache
|
|
||||||
def supports_privileged_helper() -> bool:
|
|
||||||
"""
|
|
||||||
Check if Privileged Helper Tool is supported.
|
|
||||||
|
|
||||||
When privileged helper is officially shipped, this function should always return True.
|
|
||||||
Something would have gone very wrong if it doesn't exist past that point.
|
|
||||||
"""
|
|
||||||
return Path(OCLP_PRIVILEGED_HELPER).exists()
|
|
||||||
|
|
||||||
|
|
||||||
def run(*args, **kwargs) -> subprocess.CompletedProcess:
|
def run(*args, **kwargs) -> subprocess.CompletedProcess:
|
||||||
"""
|
"""
|
||||||
Basic subprocess.run wrapper.
|
Basic subprocess.run wrapper.
|
||||||
@@ -66,14 +52,6 @@ def run_as_root(*args, **kwargs) -> subprocess.CompletedProcess:
|
|||||||
if not Path(args[0][0]).exists():
|
if not Path(args[0][0]).exists():
|
||||||
raise FileNotFoundError(f"File not found: {args[0][0]}")
|
raise FileNotFoundError(f"File not found: {args[0][0]}")
|
||||||
|
|
||||||
if supports_privileged_helper() is False:
|
|
||||||
# Fall back to old logic
|
|
||||||
# This should be removed when we start shipping the helper tool officially
|
|
||||||
if os.getuid() == 0 or utilities.check_cli_args() is not None:
|
|
||||||
return subprocess.run(*args, **kwargs)
|
|
||||||
else:
|
|
||||||
return subprocess.run(["/usr/bin/sudo"] + [args[0][0]] + args[0][1:], **kwargs)
|
|
||||||
|
|
||||||
return subprocess.run([OCLP_PRIVILEGED_HELPER] + [args[0][0]] + args[0][1:], **kwargs)
|
return subprocess.run([OCLP_PRIVILEGED_HELPER] + [args[0][0]] + args[0][1:], **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -336,11 +336,7 @@ Please check the Github page for more information about this release."""
|
|||||||
|
|
||||||
def install_auto_patcher_launch_agent(self, kdk_caching_needed: bool = False):
|
def install_auto_patcher_launch_agent(self, kdk_caching_needed: bool = False):
|
||||||
"""
|
"""
|
||||||
Install the Auto Patcher Launch Agent
|
Install patcher launch services
|
||||||
|
|
||||||
Installs the following:
|
|
||||||
- OpenCore-Patcher.app in /Library/Application Support/Dortania/
|
|
||||||
- com.dortania.opencore-legacy-patcher.auto-patch.plist in /Library/LaunchAgents/
|
|
||||||
|
|
||||||
See start_auto_patch() comments for more info
|
See start_auto_patch() comments for more info
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1325,9 +1325,6 @@ Hardware Information:
|
|||||||
raise Exception("Test Exception")
|
raise Exception("Test Exception")
|
||||||
|
|
||||||
def on_mount_root_vol(self, event: wx.Event) -> None:
|
def on_mount_root_vol(self, event: wx.Event) -> None:
|
||||||
if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
wx.MessageDialog(self.parent, "Please relaunch as Root to mount the Root Volume", "Error", wx.OK | wx.ICON_ERROR).ShowModal()
|
|
||||||
else:
|
|
||||||
#Don't need to pass model as we're bypassing all logic
|
#Don't need to pass model as we're bypassing all logic
|
||||||
if sys_patch.PatchSysVolume("",self.constants)._mount_root_vol() == True:
|
if sys_patch.PatchSysVolume("",self.constants)._mount_root_vol() == True:
|
||||||
wx.MessageDialog(self.parent, "Root Volume Mounted, remember to fix permissions before saving the Root Volume", "Success", wx.OK | wx.ICON_INFORMATION).ShowModal()
|
wx.MessageDialog(self.parent, "Root Volume Mounted, remember to fix permissions before saving the Root Volume", "Success", wx.OK | wx.ICON_INFORMATION).ShowModal()
|
||||||
@@ -1335,9 +1332,6 @@ Hardware Information:
|
|||||||
wx.MessageDialog(self.parent, "Root Volume Mount Failed, check terminal output", "Error", wx.OK | wx.ICON_ERROR).ShowModal()
|
wx.MessageDialog(self.parent, "Root Volume Mount Failed, check terminal output", "Error", wx.OK | wx.ICON_ERROR).ShowModal()
|
||||||
|
|
||||||
def on_bless_root_vol(self, event: wx.Event) -> None:
|
def on_bless_root_vol(self, event: wx.Event) -> None:
|
||||||
if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False:
|
|
||||||
wx.MessageDialog(self.parent, "Please relaunch as Root to save changes", "Error", wx.OK | wx.ICON_ERROR).ShowModal()
|
|
||||||
else:
|
|
||||||
#Don't need to pass model as we're bypassing all logic
|
#Don't need to pass model as we're bypassing all logic
|
||||||
if sys_patch.PatchSysVolume("",self.constants)._rebuild_root_volume() == True:
|
if sys_patch.PatchSysVolume("",self.constants)._rebuild_root_volume() == True:
|
||||||
wx.MessageDialog(self.parent, "Root Volume saved, please reboot to apply changes", "Success", wx.OK | wx.ICON_INFORMATION).ShowModal()
|
wx.MessageDialog(self.parent, "Root Volume saved, please reboot to apply changes", "Success", wx.OK | wx.ICON_INFORMATION).ShowModal()
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ class GenerateMenubar:
|
|||||||
|
|
||||||
aboutItem = fileMenu.Append(wx.ID_ABOUT, "&About OpenCore Legacy Patcher")
|
aboutItem = fileMenu.Append(wx.ID_ABOUT, "&About OpenCore Legacy Patcher")
|
||||||
fileMenu.AppendSeparator()
|
fileMenu.AppendSeparator()
|
||||||
relaunchItem = fileMenu.Append(wx.ID_ANY, "&Relaunch as Root")
|
|
||||||
fileMenu.AppendSeparator()
|
|
||||||
revealLogItem = fileMenu.Append(wx.ID_ANY, "&Reveal Log File")
|
revealLogItem = fileMenu.Append(wx.ID_ANY, "&Reveal Log File")
|
||||||
|
|
||||||
menubar.Append(fileMenu, "&File")
|
menubar.Append(fileMenu, "&File")
|
||||||
@@ -76,9 +74,6 @@ class GenerateMenubar:
|
|||||||
self.frame.Bind(wx.EVT_MENU, lambda event: gui_about.AboutFrame(self.constants), aboutItem)
|
self.frame.Bind(wx.EVT_MENU, lambda event: gui_about.AboutFrame(self.constants), aboutItem)
|
||||||
self.frame.Bind(wx.EVT_MENU, lambda event: subprocess.run(["/usr/bin/open", "--reveal", 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 or subprocess_wrapper.supports_privileged_helper() is True:
|
|
||||||
relaunchItem.Enable(False)
|
|
||||||
|
|
||||||
|
|
||||||
class GaugePulseCallback:
|
class GaugePulseCallback:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user