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