8

According to the Homebrew installation instructions, the following command can be used to install:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

This works, but it needs user input two times; to confirm the install and in a sudo prompt invoked by the script:

$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /usr/local
Password:

Homebrew doesn't have arguments for unattended installations, so the only option I can think of is to programatically input the expected data. I tried using expect, but I can't quite get the syntax right:

$ expect -c 'spawn ruby -e \"\$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)\";expect "RETURN";send "\n"'
ruby: invalid option -f  (-h will show valid options) (RuntimeError)
send: spawn id exp7 not open
    while executing
"send "\n""

What am I doing wrong?

olerass
  • 410
  • 2
  • 4
  • 8
  • 3
    possible duplicate of [Bypassing prompt (to press return) in homebrew install script](http://stackoverflow.com/questions/25535407/bypassing-prompt-to-press-return-in-homebrew-install-script) – Charles Duffy Aug 27 '14 at 19:36
  • 1
    Short answer: There's no need to use `expect` -- homebrew's installer only prompts at all if stdin is a TTY. Just redirect stdin from `/dev/null`, and the prompt won't happen in the first place. – Charles Duffy Aug 27 '14 at 19:36

2 Answers2

4

Unattended installation is now officially supported https://docs.brew.sh/Installation#unattended-installation:

If you want a non-interactive run of the Homebrew installer that doesn't prompt for passwords (e.g. in automation scripts), prepend NONINTERACTIVE=1 to the installation command.

$ NONINTERACTIVE=1 /bin/bash -c \
   "$(curl -fsSL \
      https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
ten0s
  • 839
  • 8
  • 11
  • We like more detailed answers to be 'inlined' into Stack Overflow, instead of simply linked to on external resources. I'll edit your answer with a specific example. <3 – ELLIOTTCABLE Apr 13 '23 at 18:43
1

If you want to create a setup script which installs homebrew silently then just pipe a blank echo to the homebrew's installer. Then redirect the results to /dev/null as @charles-duffy suggested.

#!/usr/bin/env bash
# install.sh

URL_BREW='https://raw.githubusercontent.com/Homebrew/install/master/install'

echo -n '- Installing brew ... '
echo | /usr/bin/ruby -e "$(curl -fsSL $URL_BREW)" > /dev/null
if [ $? -eq 0 ]; then echo 'OK'; else echo 'NG'; fi
$ ./install.sh
KEINOS
  • 1,050
  • 2
  • 13
  • 32