Skip to main content

I'm looking for advice on getting homebrew on new employee machines automatically. We have a work flow we would like to keep to as few clicks as possible.

I am trying to get the process of pulling down XCode CLI, installing homebrew, adding cask, and then installing third party apps for new employee machines.

I have the XCode CLI component down but having problems with installing homebrew and adding cask. Curious if anyone has a working script to make this happen. I am deploying this process through self service.

@kenny.botelho Your autobrew script is running homebrew installation as root, that's not recommended for good reasons. You are than changing the permissions of everything in /usr/local to be owned by that user, that is not not good security hygine.

@JustGoogleIt85 Cool script however the part below is unnecessary. Touch fails if the file already exists.

if [[ -f ~/.zshrc ]] ; then
    log ".zshrc already exists"
    echo "" >> ~/.zshrc
else
    log "Creating .zshrc"
    touch ~/.zshrc
fi

if [[ -f ~/.bash_profile ]] ; then
    log ".bash_profile already exists"
    echo "" >> ~/.bash_profile
else
    log "Creating .bash_profile"
    touch ~/.bash_profile
fi
QuotedText


@bobbyjohn That's actually the whole point of AutoBrew. So you CAN perform the Homebrew install as root, and it's not much different than running the original installer and interactively running through the sudo prompts. The chown is also standard practice for Homebrew installation repairs. Could you perhaps share a bit more about good security hygiene for /usr/local/ ?


/usr/local can contain binaries and other files that are owned by root and should not be writable by any other user and may cause privilege escalations or denial of service. The Jamf executable for example, can be in /usr/local and should be owned by ROOT only while others have permission to execute it. What happens when the current user is able to modify it? They can modify it, leading to priv escalation or delete it and so on. Maybe its not part of your specific threat model but say its a school where the student doesn't have root access but can get it with this? Or maybe just delete the binary because why not?

It is VERY different than the original installer because the original installer changes ownership of individual folders specific to its need.


@darren.leong The script works fine, due to where. the error is happening (SSL_read function) its something to do with issues at layer 4 or lower. Maybe some caching is preventing it, some security policy, something else? Try doing wget of the repo.


Fair point @bobbyjohn ,

I've updated the source to now have more precision permission changes with the Homebrew install. This would mimic the behavior of how the "original installer changes ownership of individual folders specific to its need."


@honestpuck I am trying the one you posted at the URL and I'm still getting this error:

Mon May 18 14:55:08 EDT 2020 - Updating Homebrew
Error: /usr/local is not writable. You should change the
ownership and permissions of /usr/local back to your
user account:
  sudo chown -R $(whoami) /usr/local

Any suggestions?


@mattsvensson Where did you add this?

Change ownership to user
/usr/sbin/chown -R $ConsoleUser /usr/local/*

NVM. I just tried AutoBrew by @kenny.botelho and it worked like magic. Thanks


@kenny.botelho Your Autobrew script seems to be failing whenever we try to install it... looks like Xcode related...

xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.
Failed during: git config --replace-all homebrew.analyticsmessage true
==> Next steps:
- Run `brew help` to get started
- Further documentation:
chown: /usr/local/bin/brew: No such file or directory
chown: /usr/local/share/doc/homebrew: No such file or directory
chown: /usr/local/share/man/man1/brew.1: No such file or directory
chown: /usr/local/share/zsh/site-functions/_brew: No such file or directory
chown: /usr/local/etc/bash_completion.d/brew: No such file or directory
bash: /usr/local/bin/brew: No such file or directory
bash: /usr/local/bin/brew: No such file or directory
bash: /usr/local/bin/brew: No such file or directory
AutoBrew Installation Failed

@jwojda This seems specific to your device I'm afraid so please ask for help in Homebrew Discourse instead.


Can someone share their script to install Homebrew on M1 Macs?


Can someone share their script to install Homebrew on M1 Macs?   Installomator does not put correct user/path.