-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·291 lines (243 loc) · 7.33 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·291 lines (243 loc) · 7.33 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
#!/bin/bash
#
# setup.sh — Main dotfiles setup orchestrator
#
# Usage:
# ./setup.sh # Auto-detect OS and run full setup
# ./setup.sh --info # Show detected environment
# ./setup.sh --validate # Check setup scripts exist
# ./setup.sh --force-platform macos # Force specific platform
# ./setup.sh --help # Show help
#
# Environment variables:
# GIT_USER_NAME — skip git name prompt
# GIT_USER_EMAIL — skip git email prompt
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPTS_DIR="$SCRIPT_DIR/scripts"
# Logging functions
log_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
log_success() {
echo -e "${GREEN}✅ $1${NC}"
}
log_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
log_error() {
echo -e "${RED}❌ $1${NC}"
}
log_header() {
echo -e "\n${BLUE}🚀 $1${NC}"
}
# Environment detection
detect_os() {
case "$(uname -s)" in
Darwin*)
echo "macos"
;;
Linux*)
echo "linux"
;;
*)
echo "unknown"
;;
esac
}
detect_environment() {
echo "host"
}
# Display environment information
show_environment_info() {
local os=$(detect_os)
local env=$(detect_environment)
log_header "Environment Detection"
echo " 🖥️ Operating System: $os"
echo " 🏠 Environment: $env"
echo " 📁 Project Directory: $SCRIPT_DIR"
echo
}
# Validate setup scripts exist
validate_setup_scripts() {
log_info "Validating setup scripts..."
local required_scripts=(
"$SCRIPTS_DIR/setup-common.sh"
"$SCRIPTS_DIR/setup-macos.sh"
"$SCRIPTS_DIR/setup-linux.sh"
)
local missing_scripts=()
for script in "${required_scripts[@]}"; do
if [[ ! -f "$script" ]]; then
missing_scripts+=("$(basename "$script")")
fi
done
if [[ ${#missing_scripts[@]} -gt 0 ]]; then
log_error "Missing required setup scripts: ${missing_scripts[*]}"
log_info "Please ensure all setup scripts are present in the scripts/ directory"
return 1
fi
# Make scripts executable
chmod +x "$SCRIPTS_DIR"/*.sh
log_success "All setup scripts validated and made executable"
}
# Select and run appropriate setup script
run_platform_setup() {
local os=$(detect_os)
local script_to_run=""
# Determine which script to run based on OS
if [[ "$os" == "macos" ]]; then
script_to_run="$SCRIPTS_DIR/setup-macos.sh"
log_info "Using macOS setup"
elif [[ "$os" == "linux" ]]; then
script_to_run="$SCRIPTS_DIR/setup-linux.sh"
log_info "Using Linux setup"
else
log_error "Unsupported operating system: $os"
log_info "Supported platforms: macOS, Linux"
return 1
fi
# Verify script exists
if [[ ! -f "$script_to_run" ]]; then
log_error "Setup script not found: $script_to_run"
return 1
fi
log_header "Running Platform Setup"
log_info "Executing: $(basename "$script_to_run")"
# Run the appropriate setup script
bash "$script_to_run" "$@"
}
# Show help information
show_help() {
cat << EOF
Modern Dotfiles Setup - Main Orchestrator
USAGE:
$0 [OPTIONS]
DESCRIPTION:
Automatically detects your environment and runs the appropriate setup script:
• macOS → scripts/setup-macos.sh
• Linux → scripts/setup-linux.sh
OPTIONS:
--help, -h Show this help message
--info Show environment information only
--validate Validate setup scripts only
--force-platform Force specific platform script
Values: macos, linux
EXAMPLES:
$0 # Auto-detect and run setup
$0 --info # Show detected environment
$0 --force-platform linux # Force Linux setup
ENVIRONMENT VARIABLES:
GIT_USER_NAME Git user name (skips interactive prompt)
GIT_USER_EMAIL Git user email (skips interactive prompt)
SETUP SCRIPTS:
scripts/setup-common.sh Shared functions for all platforms
scripts/setup-macos.sh macOS-specific setup (Homebrew, etc.)
scripts/setup-linux.sh Linux-specific setup (apt/dnf/pacman)
For more information, see:
• README.md - Project overview
• spec/project.yaml - Architecture and conventions
EOF
}
# Force specific platform (for testing or special cases)
force_platform_setup() {
local platform="$1"
local script_to_run=""
case "$platform" in
macos)
script_to_run="$SCRIPTS_DIR/setup-macos.sh"
;;
linux)
script_to_run="$SCRIPTS_DIR/setup-linux.sh"
;;
*)
log_error "Invalid platform: $platform"
log_info "Valid platforms: macos, linux"
return 1
;;
esac
if [[ ! -f "$script_to_run" ]]; then
log_error "Setup script not found: $script_to_run"
return 1
fi
log_warning "Forcing platform setup: $platform"
bash "$script_to_run"
}
# Pre-flight checks
pre_flight_checks() {
# Check if we're in the right directory
if [[ ! -f "$SCRIPT_DIR/Makefile" ]] || [[ ! -d "$SCRIPT_DIR/src" ]]; then
log_error "This doesn't appear to be the dotfiles project directory"
log_info "Please run this script from the dotfiles project root"
return 1
fi
# Check if scripts directory exists
if [[ ! -d "$SCRIPTS_DIR" ]]; then
log_error "Scripts directory not found: $SCRIPTS_DIR"
log_info "Please ensure the scripts/ directory exists"
return 1
fi
log_success "Pre-flight checks passed"
}
# Main function
main() {
# Handle command line arguments
case "${1:-}" in
--help|-h)
show_help
exit 0
;;
--info)
show_environment_info
exit 0
;;
--validate)
pre_flight_checks
validate_setup_scripts
log_success "All validations passed"
exit 0
;;
--force-platform)
if [[ -z "${2:-}" ]]; then
log_error "--force-platform requires a platform argument"
log_info "Usage: $0 --force-platform <macos|linux>"
exit 1
fi
pre_flight_checks
validate_setup_scripts
force_platform_setup "$2"
exit 0
;;
"")
# Normal execution
;;
*)
log_error "Unknown option: $1"
log_info "Use --help for usage information"
exit 1
;;
esac
# Main setup flow
log_header "Modern Dotfiles Setup"
# Pre-flight checks
pre_flight_checks
# Show environment info
show_environment_info
# Validate scripts
validate_setup_scripts
# Run platform-specific setup
run_platform_setup "$@"
log_success "🎉 Setup orchestration complete!"
log_info "Check the output above for any platform-specific instructions"
}
# Run main function if script is executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi