macoshomebrewinstall4j

install4j "Request privileges" not working as expected on macOS


We ran into a problem when trying to install Homebrew on macOS using a Custom Action in our install4j installer. Before executing the Homebrew installation script, we request admin privileges as shown in the logs below (the user that runs the installer is an Administrator). However, the installation script does not seem to be executed as an admin, it fails with the error message Need sudo access on macOS (e.g. the user xxx needs to be an Administrator)!.

Our Custom Action has the elevation type "Elevate to maximum available privileges", shouldn't this lead to the action using admin privileges?

[INFO] com.install4j.runtime.beans.actions.misc.RequestPrivilegesAction [ID 22]: Execute action
       Property linuxPrivilegeRequirement: None
       Property allRequested: true
       Property failIfNotObtainedLinux: false
       Property failIfNotObtainedMac: true
       Property failIfNotObtainedWin: true
       Property failIfNotRootUnix: true
       Property obtainIfAdminMac: true
       Property obtainIfAdminWin: true
       Property obtainIfNormalMac: true
       Property obtainIfNormalWin: true
       Property rollbackSupported: false
       Property updateInstallationDirectory: true
       args: ...
       Execute action successful after 7597 ms
[INFO] com.example.HomebrewInstaller [ID 161]: Using communication backend com.install4j.runtime.installer.platform.unix.PipeCommunicationBackend
       Execute action
       Property context: null
       Property rollbackSupported: false
       Executing commands: [/bin/zsh, -c, NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"]
       Output: ==> Running in non-interactive mode because `$NONINTERACTIVE` is set.==> Checking for `sudo` access (which may request your password)...Need sudo access on macOS (e.g. the user xxx needs to be an Administrator)!
       Execute action successful after 312 ms

Solution

  • The elevated helper process in install4j runs as root. It looks like Homebrew does not want to run as root. You would have to wrap the sudo calls in the installer into a graphical sudo like described here:

    https://stackoverflow.com/a/3034671/936832

    and run the "Run executable action" without elevated privileges.