-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-mac.sh
More file actions
365 lines (312 loc) · 10 KB
/
setup-mac.sh
File metadata and controls
365 lines (312 loc) · 10 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#!/bin/bash
#############################################################
# Mac Setup Automation Script for macOS 15.x and later
# This script automates the setup of a fresh Mac installation
# with development tools, apps, and system configurations
#
# Tested on: macOS Sequoia 15.1+
# Compatible with: macOS 15.x through latest beta versions
#############################################################
set -euo pipefail # Exit on error, undefined variables, and pipe failures
# Script configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="${SCRIPT_DIR}/logs"
LOG_FILE="${LOG_DIR}/setup-$(date +%Y-%m-%d-%H%M%S).log"
DRY_RUN=false
COMPONENTS_TO_RUN=()
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Create log directory if it doesn't exist
mkdir -p "$LOG_DIR"
#############################################################
# Utility Functions
#############################################################
log() {
local message="$1"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "${BLUE}[${timestamp}]${NC} $message" | tee -a "$LOG_FILE"
}
success() {
local message="$1"
echo -e "${GREEN}✅${NC} $message" | tee -a "$LOG_FILE"
}
error() {
local message="$1"
echo -e "${RED}❌ ERROR:${NC} $message" | tee -a "$LOG_FILE"
}
warning() {
local message="$1"
echo -e "${YELLOW}⚠️ WARNING:${NC} $message" | tee -a "$LOG_FILE"
}
info() {
local message="$1"
echo -e "${BLUE}ℹ️${NC} $message" | tee -a "$LOG_FILE"
}
# Check if running in dry-run mode
run_command() {
local cmd="$1"
if [[ "$DRY_RUN" == true ]]; then
log "[DRY-RUN] Would execute: $cmd"
else
log "Executing: $cmd"
eval "$cmd" 2>&1 | tee -a "$LOG_FILE"
fi
}
# Check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Get system architecture
get_architecture() {
uname -m
}
# Check if running on Apple Silicon
is_apple_silicon() {
[[ "$(get_architecture)" == "arm64" ]]
}
# Check if a package is installed via Homebrew
brew_installed() {
if command_exists brew; then
brew list --formula 2>/dev/null | grep -q "^$1$" || brew list --cask 2>/dev/null | grep -q "^$1$"
else
return 1
fi
}
# Verify macOS version
check_macos_version() {
local os_version
os_version=$(sw_vers -productVersion)
local major_version
major_version=$(echo "$os_version" | cut -d. -f1)
log "Current macOS version: $os_version"
# Check if macOS version is 15 or higher
if [[ "$major_version" -lt 15 ]]; then
warning "This script is designed for macOS 15.x and later. Current version: $os_version"
warning "Some features may not work correctly on older versions."
read -p "Do you want to continue anyway? (y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
error "Exiting due to macOS version requirement not met"
exit 1
fi
elif [[ "$major_version" -gt 15 ]]; then
info "Running on macOS $os_version (newer than tested version 15.x)"
info "The script should work, but some settings may need adjustment."
else
success "Running on supported macOS version: $os_version"
fi
}
# Get macOS major version number
get_macos_major_version() {
sw_vers -productVersion | cut -d. -f1
}
# Compare macOS version (returns 0 if current >= required, 1 otherwise)
version_gte() {
local required="$1"
local current
current=$(get_macos_major_version)
[[ "$current" -ge "$required" ]]
}
# Check for admin privileges
check_admin_privileges() {
if ! sudo -n true 2>/dev/null; then
log "Requesting administrator privileges..."
sudo -v
# Keep sudo alive
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
fi
success "Administrator privileges confirmed"
}
# Check internet connectivity
check_internet() {
if ping -c 1 google.com &> /dev/null; then
success "Internet connection verified"
else
error "No internet connection. Please check your network settings."
exit 1
fi
}
# Check and log system architecture
check_system_architecture() {
local arch
arch=$(get_architecture)
log "System Architecture: $arch"
if is_apple_silicon; then
success "Running on Apple Silicon (arm64)"
info "This script is optimized for Apple Silicon Macs"
else
warning "Running on Intel (x86_64)"
warning "This script is optimized for Apple Silicon Macs"
warning "Some features may work differently on Intel hardware"
info "The script will continue, but Apple Silicon is recommended for best results"
fi
}
# Parse command line arguments
parse_arguments() {
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run)
DRY_RUN=true
info "Running in dry-run mode - no changes will be made"
shift
;;
--only)
IFS=',' read -ra COMPONENTS_TO_RUN <<< "$2"
info "Running only: ${COMPONENTS_TO_RUN[*]}"
shift 2
;;
--help|-h)
show_help
exit 0
;;
*)
error "Unknown option: $1"
show_help
exit 1
;;
esac
done
}
# Show help message
show_help() {
cat << EOF
Mac Setup Automation Script
Usage: $0 [OPTIONS]
OPTIONS:
--dry-run Run in dry-run mode (no actual changes)
--only <list> Run only specified components (comma-separated)
Components: xcode,homebrew,settings,brew-packages,native-apps,shell,dotfiles,bun-packages,app-replacements,defaults
--help, -h Show this help message
Examples:
$0 # Run full setup
$0 --dry-run # Test run without making changes
$0 --only homebrew,settings # Run only specific components
EOF
}
#############################################################
# Source component functions
#############################################################
# Source all function files
# shellcheck source=/dev/null
for func_file in "${SCRIPT_DIR}"/functions/*.sh; do
if [[ -f "$func_file" ]]; then
# shellcheck source=/dev/null
source "$func_file"
fi
done
#############################################################
# Main Setup Flow
#############################################################
main() {
log "======================================================"
log "Starting Mac Setup Automation Script"
log "======================================================"
if [[ ${#COMPONENTS_TO_RUN[@]} -eq 0 ]]; then
log "Running all components."
fi
# Prerequisites
check_macos_version
check_system_architecture
check_admin_privileges
check_internet
# Run components
if should_run_component "xcode"; then
info "Installing Xcode Command Line Tools..."
install_xcode_tools
fi
if should_run_component "homebrew"; then
info "Setting up Homebrew..."
install_homebrew
fi
if should_run_component "settings"; then
info "Configuring macOS settings..."
configure_macos_settings
fi
if should_run_component "brew-packages"; then
info "Installing packages from Brewfile..."
install_brewfile_packages
fi
if should_run_component "native-apps"; then
info "Installing native applications..."
install_native_apps
fi
if should_run_component "shell"; then
info "Setting up shell environment..."
setup_shell_environment
fi
if should_run_component "dotfiles"; then
info "Configuring dotfiles..."
configure_dotfiles
fi
if should_run_component "bun-packages"; then
info "Installing Bun global packages..."
install_bun_packages
fi
if should_run_component "app-replacements"; then
info "Configuring app replacements..."
configure_app_replacements
fi
if should_run_component "defaults"; then
info "Setting default applications..."
set_default_apps
fi
log "======================================================"
success "Mac setup completed successfully!"
log "Log file saved to: $LOG_FILE"
log "======================================================"
# Show post-installation instructions
show_post_install_instructions
}
# Show post-installation instructions
show_post_install_instructions() {
echo ""
echo -e "${GREEN}Setup Complete!${NC}"
echo ""
echo -e "${YELLOW}Manual Steps Required:${NC}"
echo ""
echo -e "1. ${BLUE}Sign in to applications:${NC}"
echo " - 1Password"
echo " - Tailscale"
echo " - Proton Mail & VPN"
echo " - Discord"
echo " - Filen"
echo " - Postman"
echo ""
echo -e "2. ${BLUE}Configure Raycast:${NC}"
echo " - Open Raycast preferences"
echo " - Import your settings/extensions"
echo " - Verify Cmd+Space hotkey is working"
echo ""
echo -e "3. ${BLUE}VS Code Insiders Setup:${NC}"
echo " - Sign in with GitHub for settings sync"
echo " - Install your preferred extensions"
echo ""
echo -e "4. ${BLUE}Generate SSH Keys:${NC}"
echo " ssh-keygen -t ed25519 -C \"your.email@example.com\""
echo ""
echo -e "5. ${BLUE}Restart your Mac${NC} to ensure all settings take effect"
echo ""
}
# Parse arguments and run main
# Check if component should run
should_run_component() {
local component="$1"
if [[ ${#COMPONENTS_TO_RUN[@]} -eq 0 ]]; then
return 0
fi
for c in "${COMPONENTS_TO_RUN[@]}"; do
if [[ "$c" == "$component" ]]; then
log "Component '$component' is in the list to run."
return 0
fi
done
log "Skipping component '$component'."
return 1
}
parse_arguments "$@"
main