refactor: finish moving ssh-* scripts to own installers
[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     if [[ -n "$(uname -a | grep -i darwin)" ]]; then
11         needs_xcode="$(/usr/bin/xcode-select -p > /dev/null 2> /dev/null || echo "true")"
12         if [[ -n ${needs_xcode} ]]; 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         fi
22     else
23         if [ -z "$(command -v gcc)" ]; then
24             echo >&2 "Warning: to install 'gcc' et al on Linux use the built-in package manager."
25             echo >&2 "       For example, try: sudo apt install -y build-essential"
26         fi
27         if [ -z "$(command -v git)" ]; then
28             echo >&2 "Error: to install 'git' on Linux use the built-in package manager."
29             echo >&2 "       For example, try: sudo apt install -y git"
30             exit 1
31         fi
32     fi
33
34     # From Straight from https://brew.sh
35     if ! [ -d "$HOME/.local/opt/brew" ]; then
36         echo "Installing to '$HOME/.local/opt/brew'"
37         echo ""
38         echo "If you prefer to have brew installed to '/usr/local' cancel now and do the following:"
39         echo "        rm -rf '$HOME/.local/opt/brew'"
40         echo '        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"'
41         echo ""
42         sleep 3
43         git clone --depth=1 https://github.com/Homebrew/brew "$HOME/.local/opt/brew"
44     fi
45
46     webi_path_add "$HOME/.local/opt/brew/bin"
47     export PATH="$HOME/.local/opt/brew/bin:$PATH"
48
49     echo "Updating brew..."
50     brew update
51
52     webi_path_add "$HOME/.local/opt/brew/sbin"
53     export PATH="$HOME/.local/opt/brew/sbin:$PATH"
54
55     echo "Installed 'brew' to '$HOME/.local/opt/brew'"
56     echo ""
57     echo "If you prefer to have brew installed to '/usr/local' do the following:"
58     echo "        mv '$HOME/.local/opt/brew' '$HOME/.local/opt/brew.$(date '+%F_%H-%M-%S').bak'"
59     echo '        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"'
60     echo ""
61 }
62
63 _install_brew