|
| 1 | +#!/bin/zsh |
| 2 | + |
| 3 | +# Copyright 2021 Massachusetts Institute of Technology. |
| 4 | +# Licensed under the BSD 3-Clause License. See LICENSE.TXT for details. |
| 5 | + |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +with_pip_install=0 |
| 9 | + |
| 10 | +while [ -n "${1:-}" ]; do |
| 11 | + case "$1" in |
| 12 | + --help) |
| 13 | + echo "usage: $0 [--help] [--with-pip-install]" >&2 |
| 14 | + exit 0 |
| 15 | + ;; |
| 16 | + --with-pip-install) |
| 17 | + with_pip_install=1 |
| 18 | + ;; |
| 19 | + *) |
| 20 | + echo "usage: $0 [--help] [--with-pip-install]" >&2 |
| 21 | + exit 1 |
| 22 | + ;; |
| 23 | + esac |
| 24 | + shift |
| 25 | +done |
| 26 | + |
| 27 | +if [[ "${EUID}" -eq 0 ]]; then |
| 28 | + echo 'FATAL: This script must NOT be run as root' >&2 |
| 29 | + exit 2 |
| 30 | +fi |
| 31 | + |
| 32 | +# Do not output a file containing dependency and system status information after |
| 33 | +# A successful call to brew(1) bundle. |
| 34 | +export HOMEBREW_BUNDLE_NO_LOCK=1 |
| 35 | + |
| 36 | +# Pass the --retry 4 argument when invoking curl(1). |
| 37 | +export HOMEBREW_CURL_RETRIES=4 |
| 38 | + |
| 39 | +# Do not send brew(1) usage analytics to Google Analytics. |
| 40 | +export HOMEBREW_NO_ANALYTICS=1 |
| 41 | + |
| 42 | +# Do not automatically update before running various brew(1) subcommands. |
| 43 | +export HOMEBREW_NO_AUTO_UPDATE=1 |
| 44 | + |
| 45 | +# Forbid redirects from secure HTTPS to insecure HTTP. |
| 46 | +export HOMEBREW_NO_INSECURE_REDIRECT=1 |
| 47 | + |
| 48 | +# Never automatically cleanup installed, upgraded, and/or reinstalled formulae. |
| 49 | +export HOMEBREW_NO_INSTALL_CLEANUP=1 |
| 50 | + |
| 51 | +# Only list updates to installed formulae. |
| 52 | +export HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED=1 |
| 53 | + |
| 54 | +if ! type brew &>/dev/null; then |
| 55 | + bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" |
| 56 | +fi |
| 57 | + |
| 58 | +# brew update uses git(1), so HOMEBREW_CURL_RETRIES does not take effect. |
| 59 | +brew update || (sleep 30; brew update) |
| 60 | +trap 'brew cleanup && rm -rf $(brew --cache)/* ${HOME}/Library/Logs/Homebrew/*' |
| 61 | + |
| 62 | +# The bazelisk formula conflicts with the bazel formula because because it |
| 63 | +# attempts to replace the installed version of bazel. |
| 64 | +brew uninstall -fq bazelisk |
| 65 | + |
| 66 | +brew bundle install --file="$(dirname ${(%):-%x})/Brewfile" |
| 67 | + |
| 68 | +if [[ "${with_pip_install}" -eq 1 ]]; then |
| 69 | + pip3.9 install --disable-pip-version-check --no-input --retries 4 \ |
| 70 | + -r "$(dirname ${(%):-%x})/requirements.txt" |
| 71 | +fi |
0 commit comments