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,6 +64,7 @@ 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: try:
applescript.AppleScript( applescript.AppleScript(
f'''do shell script "installer -pkg {Path(download_path)}/InstallAssistant.pkg -target /"''' f'''do shell script "installer -pkg {Path(download_path)}/InstallAssistant.pkg -target /"'''
@@ -74,6 +76,12 @@ class InstallerCreation():
logging.info("Failed to install InstallAssistant") logging.info("Failed to install InstallAssistant")
logging.info(f" Error Code: {e}") logging.info(f" Error Code: {e}")
return False 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