-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·130 lines (112 loc) · 3.76 KB
/
bootstrap.sh
File metadata and controls
executable file
·130 lines (112 loc) · 3.76 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
set -euo pipefail
# Thin bootstrap for macOS setup
# Installs prerequisites that mise needs, then hands off to mise tasks.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/lib/output.sh"
# Abort if not macOS
if [[ "$(uname -s)" != "Darwin" ]]; then
die "This script can only be run on macOS."
fi
# Load and confirm configuration
_configure() {
local _system_computer
_system_computer=$(scutil --get ComputerName)
read -rp "Computer name [${COMPUTER_NAME:-$_system_computer}]: " input
COMPUTER_NAME=${input:-${COMPUTER_NAME:-$_system_computer}}
read -rp "Dotfiles repo [${DOTFILES_REPO:-https://github.com/mphstudios/dotfiles.git}]: " input
DOTFILES_REPO=${input:-${DOTFILES_REPO:-https://github.com/mphstudios/dotfiles.git}}
read -rp "Git user name [${GIT_USER_NAME:-}]: " input
GIT_USER_NAME=${input:-${GIT_USER_NAME:-}}
read -rp "Git email [${GIT_USER_EMAIL:-}]: " input
GIT_USER_EMAIL=${input:-${GIT_USER_EMAIL:-}}
read -rp "Lock screen message [${LOCK_SCREEN_MESSAGE:-We have achieved normality}]: " input
LOCK_SCREEN_MESSAGE=${input:-${LOCK_SCREEN_MESSAGE:-We have achieved normality}}
printf '%s\n' \
"COMPUTER_NAME=$COMPUTER_NAME" \
"DOTFILES_REPO=$DOTFILES_REPO" \
"GIT_USER_EMAIL=$GIT_USER_EMAIL" \
"GIT_USER_NAME=$GIT_USER_NAME" \
"LOCK_SCREEN_MESSAGE=$LOCK_SCREEN_MESSAGE" \
> .env
printf "\n.env written.\n\n"
}
if [[ -f .env ]]; then
source .env
printf "Current configuration:\n"
printf " Computer name: %s\n" "$COMPUTER_NAME"
printf " Dotfiles repo: %s\n" "$DOTFILES_REPO"
printf " Git email: %s\n" "$GIT_USER_EMAIL"
printf " Git user name: %s\n" "$GIT_USER_NAME"
printf " Lock screen: %s\n" "${LOCK_SCREEN_MESSAGE:-}"
printf "\n"
read -rp "Keep current configuration? [Y/n]: " keep
if [[ "${keep:-Y}" =~ ^[Nn] ]]; then
printf "\n"
_configure
fi
else
printf "First run — let's configure your machine.\n\n"
_configure
fi
# Prompt for sudo, keep-alive
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Set lock screen message
if [[ -n "${LOCK_SCREEN_MESSAGE:-}" ]]; then
sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "$LOCK_SCREEN_MESSAGE"
ok "Lock screen message set"
fi
# Install Rosetta 2 on Apple Silicon
if [[ "$(uname -m)" == "arm64" ]]; then
if ! pkgutil --pkg-info=com.apple.pkg.RosettaUpdateAuto > /dev/null 2>&1; then
info "Installing Rosetta 2..."
softwareupdate --install-rosetta --agree-to-license
ok "Rosetta 2"
else
skip "Rosetta 2"
fi
fi
# Install Xcode Command Line Tools
if ! xcode-select -p &>/dev/null; then
info "Installing Xcode Command Line Tools..."
xcode-select --install
# Poll until installed (the UI installer runs asynchronously)
# Timeout after 30 minutes in case the dialog is dismissed
elapsed=0
until xcode-select -p &>/dev/null; do
sleep 5
elapsed=$((elapsed + 5))
if [[ $elapsed -ge 1800 ]]; then
die "Xcode CLT installation timed out. Install manually: xcode-select --install"
fi
done
ok "Xcode CLT installed"
else
skip "Xcode CLT"
fi
# Install Homebrew
if ! command -v brew &>/dev/null; then
info "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH for this session
if [[ "$(uname -m)" == "arm64" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi
ok "Homebrew installed"
else
skip "Homebrew"
fi
# Install mise
if ! command -v mise &>/dev/null; then
info "Installing mise..."
brew install mise
ok "mise installed"
else
skip "mise"
fi
# Hand off to mise
printf "\nBootstrap complete. Running mise setup...\n\n"
mise run setup