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

View File

@@ -15,7 +15,8 @@ from ..datasets import os_data
from . import (
network_handler,
utilities
utilities,
subprocess_wrapper
)
@@ -63,17 +64,24 @@ class InstallerCreation():
"""
logging.info("Extracting macOS installer from InstallAssistant.pkg")
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
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)
if result.returncode != 0:
logging.info("Failed to install InstallAssistant")
subprocess_wrapper.log(result)
return False
logging.info("InstallAssistant installed")
return True