Automatic Install via VMWare Workspace One

We have a fleet of macOS machines which we manage via VMWare Workspace One. We want to automate installing Homebrew as part of the initial machine set up. I am looking for a clean way of running the Bash installer script as root but knowing what the local username is.

I’ve tried something like the following, but it seems to error out unsuccessfully.

#!/usr/bin/env bash
CURRENTUSER=$(last | grep -m1 "still logged in" | cut -d' ' -f1)
su "${CURRENTUSER}" -c "/usr/bin/curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh | /bin/bash"

I feel like there must be a way to use su and the known username to make this work, but I’m missing some key flag or something?

[edit] When I run that same script after logging in and doing a sudo -s it works, but for some bizarre reason it fails when running as root via the agent.

Hey Alen,

I am attempting to do the same thing for our group. Sadly I am not great at Unix/Linux did you ever find a good way to do this?
We tried to create an item with this process that could be installed on command. (we haven’t thought about uninstalling yet. That is a future me problem.)
Then we have played with putting in line with the actual post-install of the terminal script in the .pkg and per/post-install on the WS1 side in the App setup. However, we have not gotten a script that will actually do the install.
If you found a script that seems to work I think I might be able to toss it in as a post install script.

Thanks