Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unattended (no-prompt) Homebrew installation using expect

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?

like image 682
olerass Avatar asked Jun 26 '14 09:06

olerass


1 Answers

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
like image 137
KEINOS Avatar answered Nov 28 '22 21:11

KEINOS