-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbrew-bootstrap.inc.sh
executable file
·133 lines (117 loc) · 4.91 KB
/
brew-bootstrap.inc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
set -euo pipefail
function bootstrap_has_brew() {
if command -v brew >/dev/null 2>&1; then
# using tail or else broken pipe. see https://github.com/Homebrew/homebrew-cask/issues/36218
# exe_and_grep_q "brew --version | head -1" "^Homebrew 3." || return 1
exe_and_grep_q "brew --version | tail -n+1 | head -1" "^Homebrew 3\." || return 1
echo_info "brew: Executable brew v3 found."
else
echo_info "brew: Executable brew v3 not found."
return 1
fi
}
function bootstrap_brew() {
local RAW_GUC_URL="https://raw.githubusercontent.com"
local BREWFILE_LOCK=${GIT_ROOT}/Brewfile.lock
local BREW_INSTALL_GIT_REF=refs/heads/master
local BREW_GIT_REF=refs/heads/master
local BREW_CORE_GIT_REF=refs/heads/master
[[ "${CI}" != "true" ]] || {
[[ ! -f ${BREWFILE_LOCK} ]] || {
BREW_INSTALL_LOCK=$(cat "${BREWFILE_LOCK}" | grep "^homebrew/install " || true)
[[ -z "${BREW_INSTALL_LOCK}" ]] || \
BREW_INSTALL_GIT_REF=$(echo "${BREW_INSTALL_LOCK}" | cut -d" " -f2)
BREW_LOCK=$(cat "${BREWFILE_LOCK}" | grep "^homebrew/brew " || true)
[[ -z "${BREW_LOCK}" ]] || \
BREW_GIT_REF=$(echo "${BREW_LOCK}" | cut -d" " -f2)
case "${OS_SHORT}" in
darwin|linux)
BREW_CORE_LOCK=$(cat "${BREWFILE_LOCK}" | grep "^homebrew/homebrew-core " || true)
;;
*)
echo_err "OS_SHORT=${OS_SHORT}"
;;
esac
[[ -z "${BREW_CORE_LOCK}" ]] || \
BREW_CORE_GIT_REF=$(echo "${BREW_CORE_LOCK}" | cut -d" " -f2)
}
}
# bootstrap/brew-util/homebrew-install.sh
export HOMEBREW_BREW_GIT_REF=$(echo ${BREW_GIT_REF} | sed "s|^refs/heads/|refs/remotes/origin/|")
export HOMEBREW_CORE_GIT_REF=$(echo ${BREW_CORE_GIT_REF} | sed "s|^refs/heads/|refs/remotes/origin/|")
BREW_INSTALL_GIT_REF=$(echo ${BREW_INSTALL_GIT_REF} | sed "s|^refs/heads/||" | sed "s|^refs/tags/||")
BREW_GIT_REF=$(echo ${BREW_GIT_REF} | sed "s|^refs/heads/||" | sed "s|^refs/tags/||")
BREW_CORE_GIT_REF=$(echo ${BREW_CORE_GIT_REF} | sed "s|^refs/heads/||" | sed "s|^refs/tags/||")
local BREW_INSTALL_URL=${RAW_GUC_URL}/Homebrew/install/${BREW_INSTALL_GIT_REF}
[[ "${CI}" != "true" ]] || {
if command -v brew >/dev/null 2>&1; then
if [[ "${YP_SKIP_BREW_UNINSTALL:-}" = "true" ]]; then
echo_skip "brew: Uninstalling homebrew..."
else
brew_uninstall_brew "${BREW_INSTALL_URL}"
fi
fi
}
local HAS_BREW=true
bootstrap_has_brew || HAS_BREW=false
case ${HAS_BREW}-${OS_SHORT}-${YP_SUDO:-false} in
true-darwin-*|true-linux-*)
echo_skip "brew: Installing homebrew..."
;;
false-linux-false|false-linux-yp_nosudo|false-linux-yp_nosudo_fallback)
HOMEBREW_PREFIX=${HOME}/.linuxbrew
echo_do "brew: Installing homebrew without sudo into ${HOMEBREW_PREFIX}..."
mkdir -p ${HOMEBREW_PREFIX}
curl -qfsSL https://github.com/Homebrew/brew/tarball/${BREW_GIT_REF} | \
tar xz --strip 1 -C ${HOMEBREW_PREFIX}
echo_done
yp::env_force
;;
false-darwin-*|false-linux-*)
echo_do "brew: Installing homebrew..."
(
# FIXME needed for HOMEBREW_FORCE_BREWED_{CURL,GIT}
# see https://github.com/Homebrew/install/issues/522
# shellcheck disable=SC2030,SC2031
export HOMEBREW_NO_AUTO_UPDATE=
# </dev/null /bin/bash -c "$(curl -qfsSL ${BREW_INSTALL_URL}/install.sh)"
if [[ "${CI:-}" = "true" ]]; then
export HOMEBREW_DEGIT=${YP_DIR}/bin/degit
fi
</dev/null /bin/bash -c "$(cat ${YP_DIR}/bootstrap/brew-util/homebrew-install.sh)"
)
echo_done
yp::env_force
;;
*)
echo_err "brew: Cannot handle HAS_BREW=${HAS_BREW} OS_SHORT=${OS_SHORT} YP_SUDO=${YP_SUDO}."
return 1
;;
esac
[[ "${CI}" != "true" ]] || {
brew_autoremove
brew_cleanup
}
}
bootstrap_brew
brew_config
brew_doctor
[[ "${OS_RELEASE_ID}" != "alpine" ]] || apk list --installed | grep -q glibc || {
apk_install_one libc6-compat # skipped in bootstrap/bootstrap-sudo-alpine
# NOTE as per https://github.com/Linuxbrew/docker/blob/2c7ecfe/alpine/Dockerfile
brew install -s patchelf
brew install --ignore-dependencies binutils gmp [email protected] libmpc linux-headers mpfr zlib
brew install --ignore-dependencies gcc || true
brew install glibc
brew postinstall gcc
brew remove patchelf
brew install -s patchelf
}
if [[ -f ${GIT_ROOT}/Brewfile.lock ]]; then
brew_lockfile
else
brew_update
fi
brew_config
brew_doctor