macos_installer_handler.py: Add support for Privileged Helper

This commit is contained in:
Mykola Grymalyuk
2024-05-20 18:52:49 -06:00
parent 45651a9aec
commit 984eb67596
@@ -15,7 +15,8 @@ from ..datasets import os_data
from . import ( from . import (
network_handler, network_handler,
utilities utilities,
subprocess_wrapper
) )
@@ -63,17 +64,24 @@ class InstallerCreation():
""" """
logging.info("Extracting macOS installer from InstallAssistant.pkg") logging.info("Extracting macOS installer from InstallAssistant.pkg")
try: if subprocess_wrapper.supports_privileged_helper() is False:
applescript.AppleScript( try:
f'''do shell script "installer -pkg {Path(download_path)}/InstallAssistant.pkg -target /"''' applescript.AppleScript(
' with prompt "OpenCore Legacy Patcher needs administrator privileges to extract the installer."' f'''do shell script "installer -pkg {Path(download_path)}/InstallAssistant.pkg -target /"'''
" with administrator privileges" ' with prompt "OpenCore Legacy Patcher needs administrator privileges to extract the installer."'
" without altering line endings", " with administrator privileges"
).run() " without altering line endings",
except Exception as e: ).run()
logging.info("Failed to install InstallAssistant") except Exception as e:
logging.info(f" Error Code: {e}") logging.info("Failed to install InstallAssistant")
return False 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)
if result.returncode != 0:
logging.info("Failed to install InstallAssistant")
subprocess_wrapper.log(result)
return False
logging.info("InstallAssistant installed") logging.info("InstallAssistant installed")
return True return True