76469b55679d39917066d1f60801089d0e2c2ee8
[webi-installers/.git] / brew / install.sh
1 #!/bin/bash
2
3 set -e
4 set -u
5
6 function _install_brew() {
7     # Straight from https://brew.sh
8     #/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
9
10     needs_xcode="$(/usr/bin/xcode-select -p > /dev/null 2> /dev/null || echo "true")"
11     if [[ -n ${needs_xcode} ]]; then
12         echo ""
13         echo ""
14         echo "ERROR: Run this command to install XCode Command Line Tools first:"
15         echo ""
16         echo "    xcode-select --install"
17         echo ""
18         echo "After the install, close this terminal, open a new one, and try again."
19         echo ""
20         exit 1
21     fi
22
23     # From Straight from https://brew.sh
24     if ! [ -d "$HOME/.local/opt/brew" ]; then
25         echo "Installing to '$HOME/.local/opt/brew'"
26         echo ""
27         echo "If you prefer to have brew installed to '/usr/local' cancel now and do the following:"
28         echo "        rm -rf '$HOME/.local/opt/brew'"
29         echo '        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"'
30         echo ""
31         sleep 3
32         git clone --depth=1 https://github.com/Homebrew/brew "$HOME/.local/opt/brew"
33     fi
34
35     webi_path_add "$HOME/.local/opt/brew/bin"
36     export PATH="$HOME/.local/opt/brew/bin:$PATH"
37
38     echo "Updating brew..."
39     brew update
40
41     webi_path_add "$HOME/.local/opt/brew/sbin"
42     export PATH="$HOME/.local/opt/brew/sbin:$PATH"
43
44     echo "Installed 'brew' to '$HOME/.local/opt/brew'"
45     echo ""
46     echo "If you prefer to have brew installed to '/usr/local' do the following:"
47     echo "        mv '$HOME/.local/opt/brew' '$HOME/.local/opt/brew.$(date '+%F_%H-%M-%S').bak'"
48     echo '        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"'
49     echo ""
50 }
51
52 _install_brew