KosalaHerath / macos-installer-builder

Generate macOS installers for your applications and products from one command
Apache License 2.0
320 stars 92 forks source link

Determine username of installing user (not root) in post install script? #34

Closed whydna closed 5 months ago

whydna commented 9 months ago

Great library, thank you for making this.

Question - In the post install script, I want to know the user who initiated the installer. Because the post install script is initiated by root, whoami returns root.

KosalaHerath commented 5 months ago

When running a script with root privileges on macOS, you can determine the original user by checking the $SUDO_USER environment variable. This variable holds the username of the user who invoked the script with sudo.

Refer: https://www.sudo.ws/docs/man/1.8.10/sudo.man/#x454e5649524f4e4d454e54