这是将自制软件安装程序包装在bash函数中的版本,可以从您的部署脚本中运行该函数:
install_homebrew_if_not_present() {
echo "Checking for homebrew installation"
which -s brew
if [[ $? != 0 ]] ; then
echo "Homebrew not found. Installing..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
echo "Homebrew already installed! Updating..."
brew update
fi
}
如果尚未安装自制方法,则另一个函数将安装该方法:
brew_install () {
if brew ls --versions $1 > /dev/null; then
echo "already installed: $1"
else
echo "Installing forumula: $1..."
brew install $1
fi
}
一旦定义了这些功能,就可以在bash脚本中按以下方式使用它们:
install_homebrew_if_not_present
brew_install wget
brew_install openssl
...