-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·82 lines (73 loc) · 2.48 KB
/
bootstrap.sh
File metadata and controls
executable file
·82 lines (73 loc) · 2.48 KB
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
#!/bin/bash
# * Bash 3.2 (2007)
# This is the entrypoint
# Run to setup a new Mac or reconfigure an existing Mac
# Bash strict mode
set -euo pipefail
# Guard: refuse to run as root
if [ "$(id -u)" -eq 0 ]; then
echo "Error: Do not run this script as root" >&2
exit 1
fi
# Trap handler for cleanup on interruption
CURRENT_STEP=""
# shellcheck disable=SC2329 # Function appears unused but is invoked by trap
cleanup_on_interrupt() {
echo "" >&2
echo "Bootstrap interrupted!" >&2
if [ "$CURRENT_STEP" != "" ]; then
echo "Stopped during: $CURRENT_STEP" >&2
fi
echo "To resume, re-run: curl -s https://raw.githubusercontent.com/nickineering/setup/master/bootstrap.sh | /bin/bash" >&2
exit 130
}
trap cleanup_on_interrupt INT TERM
# Colors for output
green='\033[32m'
yellow='\033[33m'
cyan='\033[36m'
bold='\033[1m'
reset='\033[0m'
echo -e "${bold}${cyan}=== AUTOMATICALLY CONFIGURING MAC ===${reset}"
echo -e "${green}Please leave everything closed and wait for your Mac to be configured. This will take a while.${reset}"
CURRENT_STEP="installing Homebrew"
# Install Homebrew, a Mac package manager
if command -v brew; then
echo -e "${green}Homebrew already installed${reset}"
else
echo -e "${green}Installing Homebrew...${reset}"
HOMEBREW_INSTALL_SCRIPT=$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
if [ "$HOMEBREW_INSTALL_SCRIPT" = "" ]; then
echo "Error: Failed to download Homebrew installer" >&2
exit 1
fi
if ! NONINTERACTIVE=1 /bin/bash -c "$HOMEBREW_INSTALL_SCRIPT"; then
echo "Error: Homebrew installation failed" >&2
exit 1
fi
eval "$(/opt/homebrew/bin/brew shellenv)"
echo -e "${green}Installed Homebrew${reset}"
fi
CURRENT_STEP="cloning setup repository"
# Make a projects directory and clone the repo into it
mkdir -p ~/projects
export SETUP=~/projects/setup
brew install git # Use Homebrew so that updates are easy
if [ -d "$SETUP" ]; then
git -C "$SETUP" pull || echo -e "${yellow}Warning: Failed to pull latest commits${reset}"
echo -e "${green}Pulled latest commits from repo${reset}"
else
if ! git clone https://github.com/nickineering/setup.git "$SETUP"; then
echo "Error: Failed to clone setup repo" >&2
exit 1
fi
echo -e "${green}Cloned setup repo into projects directory${reset}"
fi
CURRENT_STEP="installing modern Bash"
# MacOS comes with Bash 3.2, but we want the latest. Download the latest Bash and then
# continue using it.
if ! brew install bash; then
echo "Error: Failed to install bash via Homebrew" >&2
exit 1
fi
"$SETUP"/run.sh