forked from HariSekhon/DevOps-Bash-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_homebrew.sh
executable file
·73 lines (70 loc) · 2.63 KB
/
install_homebrew.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
#!/usr/bin/env bash
#
# Author: Hari Sekhon
# Date: 2019-09-12
#
# https://github.com/harisekhon/devops-bash-tools
#
# License: see accompanying LICENSE file
#
# https://www.linkedin.com/in/harisekhon
#
# Install Homebrew on Mac OS X or Linux (used by AWS CLI on Linux)
#
# doesn't install on CentOS 6 any more
#
# https://github.com/Homebrew/brew/issues/7583#issuecomment-640379742
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(dirname "${BASH_SOURCE[0]}")"
if type -P brew &>/dev/null; then
echo "HomeBrew already installed, skipping install..."
else
echo "==================="
echo "Installing HomeBrew"
echo "==================="
echo
# root installs to first one, user installs to the latter
for x in /home/linuxbrew/.linuxbrew/bin ~/.linuxbrew/bin; do
if [ -d "$x" ]; then
export PATH="$PATH:$x"
fi
done
"$srcdir/../install_packages_if_absent.sh" bash curl git sudo
if [ "$(uname -s)" = Linux ]; then
# if we're in debug mode enable set -x inside the HomeBrew script so we can see what inside it is causing breakage
cmds=""
if [ -n "${DEBUG_HOMEBREW:-}" ]; then
cmds="set -x"
fi
{
echo "$cmds"
# LinuxBrew has migrated to HomeBrew now
curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh
# but this requires newer curl and fails many CI builds - https://github.com/Homebrew/install/issues/367
#curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh
} |
{
# XXX: requires 'sudo' command to install now no matter whether run as root or a regular user :-/
if [ "$EUID" -eq 0 ]; then
user=linuxbrew
echo "Installing HomeBrew on Linux as user $user"
# Alpine has adduser
id "$user" || useradd "$user" || adduser -D "$user"
mkdir -p -v "/home/$user"
chown -R "$user" "/home/$user"
# can't just pass bash, and -s shell needs to be fully qualified path
su "$user" -s /bin/bash
else
echo "Installing HomeBrew on Linux as user $USER"
# newer versions of HomeBrew require bash not sh due to use of [[
bash
fi
}
else
echo "Installing HomeBrew on Mac as user $USER"
# now deprecated and replaced with the shell version below
#curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install | ruby
bash -c "$(echo "$cmds"; curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
fi