I'm trying to create a script to deploy macOS and the last piece that isn't automated is installing Homebrew. Because of the unique scenario where Homebrew shouldn't be installed with sudo
, and it requires both the return
key to be pressed and the users password
, it's become a tricky thing to figure out. I've spent a few hours on this and found other unanswered questions on StackExchange with no luck on getting it completely automated.
My code:
echo "Password: "
read -s PASSWORD
echo $PASSWORD | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The echo skips the request to hit return
but doesn't pass in the password because I'm missing the -S
flag because I shouldn't include sudo when installing Homebrew. I ultimately need a setup that hits command AND passes in the password without using sudo. The rest of my script runs by using echo $PASSWORD | sudo -S my-command-here...
so I'd like to not deviate too far from that scheme if possible.
/usr/local
before you install Homebrew?echo PASSWORD | sudo -S
is a bad practice (at least from a security point of view) your problem seems to come from the fact thatsudo
gets called without-S
within the Homebrew install script. So you may want to ask for ways to prevent Homebrew from even trying to use sudo (don't know whether this is possible) or for ways to change your script to work around this.