使用expect的无人值守(无提示)Homebrew安装

时间:2014-06-26 09:01:46

标签: macos installation homebrew expect

根据Homebrew安装说明,可以使用以下命令进行安装:

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

这有效,但需要用户输入两次;确认安装并在脚本调用的sudo提示符中:

$ 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没有无人参与安装的参数,所以我能想到的唯一选择是以编程方式输入预期的数据。我尝试使用expect,但我无法正确理解语法:

$ 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""

我做错了什么?

1 个答案:

答案 0 :(得分:2)

如果要创建一个静默安装homebrew的安装脚本,则只需将空白的echo用管道传输到自制软件的安装程序。然后按照@ charles-duffy的建议将结果重定向到/dev/null

#!/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