-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
416 lines (378 loc) · 16.9 KB
/
Makefile
File metadata and controls
416 lines (378 loc) · 16.9 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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# =============================================================================
# Dotfiles Management Makefile - FIXED VERSION
# =============================================================================
SHELL := /bin/bash
.DEFAULT_GOAL := help
# Colors for output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[1;33m
RED := \033[0;31m
NC := \033[0m
# Variables
DOTFILES_DIR := $(HOME)/.dotfiles
DOTBOT_DIR := dotbot
LOG_DIR := logs
BACKUP_DIR := backup
PROFILE ?= workstation
# IMPORTANT: Don't use OS from environment - let script detect it
override OS :=
.PHONY: help install update-dotbot update check-updates backup restore clean test lint logs dry-run info bootstrap doctor init-submodules init-repo validate-structure
# =============================================================================
# General Commands
# =============================================================================
help: ## Display this help message
@echo -e "$(BLUE)Dotfiles Management Commands$(NC)\n"
@awk 'BEGIN {FS = ":.*##"; printf "Usage: make $(YELLOW)<target>$(NC)\n\n"} /^[a-zA-Z_-]+:.*?##/ { printf " $(GREEN)%-15s$(NC) %s\n", $$1, $$2 } /^##@/ { printf "\n$(BLUE)%s$(NC)\n", substr($$0, 5) }' $(MAKEFILE_LIST)
system-deps: ## Install system dependencies (requires sudo)
@echo "Installing system dependencies..."
@sudo apt-get update && sudo apt-get install -y git zsh vim tmux
# =============================================================================
# Installation Commands - FIXED
# =============================================================================
install: ## Install dotfiles with default profile
@echo -e "$(BLUE)Installing dotfiles with profile: $(PROFILE)$(NC)"
@chmod +x $(DOTFILES_DIR)/install
@cd $(DOTFILES_DIR) && \
env -u OS -u DETECTED_OS -u OS_TYPE ./install --profile $(PROFILE)
install-debug: ## Install dotfiles with debug output
@echo -e "$(BLUE)Installing dotfiles with profile: $(PROFILE) (debug mode)$(NC)"
@chmod +x $(DOTFILES_DIR)/install
@mkdir -p $(DOTFILES_DIR)/$(LOG_DIR)
@cd $(DOTFILES_DIR) && \
env -u OS -u DETECTED_OS -u OS_TYPE ./install --profile $(PROFILE) 2>&1 | tee $(LOG_DIR)/install_debug.log
install-continue: ## Continue installation ignoring errors
@echo -e "$(BLUE)Installing dotfiles with profile: $(PROFILE) (continue on error)$(NC)"
@chmod +x $(DOTFILES_DIR)/install
@cd $(DOTFILES_DIR) && \
env -u OS -u DETECTED_OS -u OS_TYPE ./install --profile $(PROFILE) || true
full-setup: system-deps install ## Complete setup (system deps + dotfiles)
install-workstation: ## Install workstation profile
@echo -e "$(BLUE)Installing workstation profile$(NC)"
@chmod +x $(DOTFILES_DIR)/install
@cd $(DOTFILES_DIR) && \
env -u OS -u DETECTED_OS -u OS_TYPE ./install --profile workstation
install-server: ## Install server profile
@echo -e "$(BLUE)Installing server profile$(NC)"
@chmod +x $(DOTFILES_DIR)/install
@cd $(DOTFILES_DIR) && \
env -u OS -u DETECTED_OS -u OS_TYPE ./install --profile server
install-home: ## Install home profile
@echo -e "$(BLUE)Installing home profile$(NC)"
@chmod +x $(DOTFILES_DIR)/install
@cd $(DOTFILES_DIR) && \
env -u OS -u DETECTED_OS -u OS_TYPE ./install --profile home
# Force specific OS if needed
install-linux: ## Force Linux installation
@echo -e "$(BLUE)Installing with forced Linux detection$(NC)"
@chmod +x $(DOTFILES_DIR)/install
@cd $(DOTFILES_DIR) && \
env -u OS -u DETECTED_OS -u OS_TYPE ./install --profile $(PROFILE) --os linux
install-macos: ## Force macOS installation
@echo -e "$(BLUE)Installing with forced macOS detection$(NC)"
@chmod +x $(DOTFILES_DIR)/install
@cd $(DOTFILES_DIR) && \
env -u OS -u DETECTED_OS -u OS_TYPE ./install --profile $(PROFILE) --os macos
# =============================================================================
# Maintenance Commands
# =============================================================================
update: update-dotbot install ## Update dotbot and reinstall dotfiles
@echo -e "$(GREEN)Update completed!$(NC)"
update-dotbot: ## Update dotbot submodule
@echo -e "$(BLUE)Checking for dotbot updates...$(NC)"
@cd $(DOTFILES_DIR)/$(DOTBOT_DIR) && \
CURRENT_COMMIT=$$(git rev-parse HEAD) && \
git fetch origin && \
LATEST_COMMIT=$$(git rev-parse origin/master) && \
if [ "$$CURRENT_COMMIT" != "$$LATEST_COMMIT" ]; then \
echo -e "$(YELLOW)Dotbot update available!$(NC)"; \
echo "Current: $$CURRENT_COMMIT"; \
echo "Latest: $$LATEST_COMMIT"; \
git checkout master && git pull origin master && \
echo -e "$(GREEN)Dotbot updated successfully!$(NC)"; \
else \
echo -e "$(GREEN)Dotbot is already up to date$(NC)"; \
fi
check-updates: ## Check for available updates
@echo -e "$(BLUE)Checking for updates...$(NC)\n"
@echo -e "$(YELLOW)Dotbot Status:$(NC)"
@cd $(DOTFILES_DIR)/$(DOTBOT_DIR) && \
CURRENT_COMMIT=$$(git rev-parse HEAD) && \
git fetch origin --quiet && \
LATEST_COMMIT=$$(git rev-parse origin/master) && \
if [ "$$CURRENT_COMMIT" != "$$LATEST_COMMIT" ]; then \
echo -e " $(RED)Update available$(NC)"; \
echo " Current: $$(git log --oneline -1 $$CURRENT_COMMIT)"; \
echo " Latest: $$(git log --oneline -1 $$LATEST_COMMIT)"; \
else \
echo -e " $(GREEN)Up to date$(NC)"; \
fi
@echo -e "\n$(YELLOW)Repository Status:$(NC)"
@cd $(DOTFILES_DIR) && \
if git status --porcelain | grep -q .; then \
echo -e " $(YELLOW)Uncommitted changes detected$(NC)"; \
git status --short; \
else \
echo -e " $(GREEN)Clean working directory$(NC)"; \
fi
# =============================================================================
# Backup & Restore
# =============================================================================
archive: ## Create backup archive of entire dotfiles directory
@echo -e "$(BLUE)Creating archive...$(NC)"
@mkdir -p $(DOTFILES_DIR)/$(BACKUP_DIR)
@TIMESTAMP=$$(date +%Y%m%d_%H%M%S) && \
if command -v zip >/dev/null 2>&1; then \
BACKUP_FILE="dotfiles_backup_$$TIMESTAMP.zip" && \
BACKUP_PATH="$(DOTFILES_DIR)/$(BACKUP_DIR)/$$BACKUP_FILE" && \
echo -e "Creating ZIP archive: $$BACKUP_PATH" && \
zip -r "$$BACKUP_PATH" . \
-x "$(BACKUP_DIR)/*" \
-x ".git/*" \
-x "dotbot/.git/*" \
-x "*.DS_Store" \
-x "*.log" \
--quiet; \
else \
BACKUP_FILE="dotfiles_backup_$$TIMESTAMP.tar.gz" && \
BACKUP_PATH="$(DOTFILES_DIR)/$(BACKUP_DIR)/$$BACKUP_FILE" && \
echo -e "Creating TAR.GZ archive: $$BACKUP_PATH" && \
tar -czf "$$BACKUP_PATH" \
--exclude="$(BACKUP_DIR)" \
--exclude=".git" \
--exclude="dotbot/.git" \
--exclude="*.DS_Store" \
--exclude="*.log" \
.; \
fi && \
echo -e "$(GREEN)Archive created: $$BACKUP_FILE ($$$(du -h "$$BACKUP_PATH" | cut -f1))$(NC)"
##@ Backup & Restore
mackup-backup: ## Backup application settings with Mackup
@echo -e "$(BLUE)Backing up application settings...$(NC)"
@if command -v mackup >/dev/null 2>&1; then \
mackup backup && \
echo -e "$(GREEN)Application settings backed up successfully!$(NC)"; \
else \
echo -e "$(RED)Mackup not installed. Install with: brew install mackup$(NC)"; \
fi
mackup-restore: ## Restore application settings with Mackup
@echo -e "$(BLUE)Restoring application settings...$(NC)"
@if command -v mackup >/dev/null 2>&1; then \
mackup restore && \
echo -e "$(GREEN)Application settings restored successfully!$(NC)"; \
else \
echo -e "$(RED)Mackup not installed. Install with: brew install mackup$(NC)"; \
fi
mackup-status: ## Show Mackup configuration status
@echo -e "$(BLUE)Mackup Configuration Status$(NC)"
@if command -v mackup >/dev/null 2>&1; then \
echo -e "$(GREEN)✓$(NC) Mackup installed"; \
mackup_status; \
else \
echo -e "$(RED)✗$(NC) Mackup not installed"; \
fi
restore: ## Restore from latest backup (interactive)
@echo -e "$(BLUE)Available backups:$(NC)"
@ls -la $(DOTFILES_DIR)/$(BACKUP_DIR)/ 2>/dev/null || echo "No backups found"
@echo ""
@read -p "Enter backup directory name to restore from: " backup_name && \
if [ -d "$(DOTFILES_DIR)/$(BACKUP_DIR)/$$backup_name" ]; then \
echo -e "$(YELLOW)Restoring from $$backup_name...$(NC)" && \
cp -r $(DOTFILES_DIR)/$(BACKUP_DIR)/$$backup_name/* ~/ && \
echo -e "$(GREEN)Restore completed!$(NC)"; \
else \
echo -e "$(RED)Backup not found!$(NC)"; \
fi
# =============================================================================
# Development & Testing
# =============================================================================
test: ## Run basic configuration tests
@echo -e "$(BLUE)Running dotfiles tests...$(NC)"
@cd $(DOTFILES_DIR) && \
python3 -c "import yaml; yaml.safe_load(open('install.conf.yaml'))" && \
echo -e " $(GREEN)✓$(NC) install.conf.yaml syntax valid" || \
echo -e " $(RED)✗$(NC) install.conf.yaml syntax error"
@cd $(DOTFILES_DIR) && \
for package_file in packages/common.yaml packages/node.yaml packages/linux/apt.yaml packages/linux/snap.yaml packages/macos/mas.yaml; do \
if [ -f "$$package_file" ]; then \
python3 -c "import yaml; yaml.safe_load(open('$$package_file'))" && \
echo -e " $(GREEN)✓$(NC) $$package_file syntax valid" || \
echo -e " $(RED)✗$(NC) $$package_file syntax error"; \
else \
echo -e " $(YELLOW)!$(NC) $$package_file not found"; \
fi; \
done
@cd $(DOTFILES_DIR) && \
for script in scripts/*/*.sh scripts/common/*.sh; do \
if [ -f "$$script" ]; then \
if [ -x "$$script" ]; then \
echo -e " $(GREEN)✓$(NC) $$script is executable"; \
else \
echo -e " $(YELLOW)!$(NC) $$script is not executable"; \
fi; \
fi; \
done
@for cmd in git python3; do \
if command -v $$cmd >/dev/null 2>&1; then \
echo -e " $(GREEN)✓$(NC) $$cmd available"; \
else \
echo -e " $(RED)✗$(NC) $$cmd not found"; \
fi; \
done
validate: ## Run comprehensive validation using validate_installer.sh
@echo -e "$(BLUE)Running comprehensive validation...$(NC)"
@cd $(DOTFILES_DIR) && \
if [ -f "scripts/common/validate_installer.sh" ]; then \
scripts/common/validate_installer.sh; \
else \
echo -e "$(RED)validate_installer.sh not found$(NC)"; \
exit 1; \
fi
lint: ## Lint shell scripts and YAML files
@echo -e "$(BLUE)Linting files...$(NC)"
@if command -v shellcheck >/dev/null 2>&1; then \
cd $(DOTFILES_DIR) && find scripts/ -name "*.sh" -exec shellcheck {} \;; \
else \
echo -e "$(YELLOW)shellcheck not installed, skipping$(NC)"; \
fi
@if command -v yamllint >/dev/null 2>&1; then \
cd $(DOTFILES_DIR) && find . -name "*.yaml" -o -name "*.yml" | grep -v $(DOTBOT_DIR) | xargs yamllint; \
else \
echo -e "$(YELLOW)yamllint not installed, skipping$(NC)"; \
fi
dry-run: ## Show what would be linked (dry run)
@echo -e "$(BLUE)Dry run for profile: $(PROFILE)$(NC)"
@cd $(DOTFILES_DIR) && \
python3 -c "import yaml; config = yaml.safe_load(open('install.conf.yaml')); [print(f' {target} -> {source.get(\"path\", source) if isinstance(source, dict) else source}') for item in config if isinstance(item, dict) and 'link' in item for target, source in item['link'].items()]"
# =============================================================================
# Logging & Cleanup
# =============================================================================
logs: ## Show recent installation logs
@ls -la $(DOTFILES_DIR)/$(LOG_DIR)/*.log 2>/dev/null | tail -10 || echo "No logs found"
logs-tail: ## Tail most recent log
@LATEST_LOG=$$(ls -t $(DOTFILES_DIR)/$(LOG_DIR)/install_*.log 2>/dev/null | head -1) && \
if [ -n "$$LATEST_LOG" ]; then tail -f "$$LATEST_LOG"; else echo "No logs found"; fi
clean: ## Clean up logs & temp files
@echo -e "$(BLUE)Cleaning up...$(NC)"
@find $(DOTFILES_DIR)/$(LOG_DIR) -name "*.log" -mtime +30 -delete 2>/dev/null || true
@cd $(DOTFILES_DIR) && find . -type d -empty -delete 2>/dev/null || true
@rm -f /tmp/dotfiles_env
@echo -e "$(GREEN)Cleanup completed!$(NC)"
clean-all: ## Clean all logs & backups
@echo -e "$(RED)WARNING: This will remove ALL logs and backups!$(NC)"
@read -p "Are you sure? (y/N): " confirm && \
if [[ "$$confirm" =~ ^[Yy]$$ ]]; then \
rm -rf $(DOTFILES_DIR)/$(LOG_DIR)/*.log $(DOTFILES_DIR)/$(BACKUP_DIR)/* && \
rm -f /tmp/dotfiles_env && \
echo -e "$(GREEN)All logs and backups removed$(NC)"; \
else \
echo -e "$(YELLOW)Operation cancelled$(NC)"; \
fi
# =============================================================================
# System Information
# =============================================================================
info: ## Show system information
@echo -e "$(BLUE)System Information$(NC)\n"
@echo -e "$(YELLOW)Operating System:$(NC)"
@echo " uname -s: $$(uname -s)"
@echo " uname -m: $$(uname -m)"
@if [ -f "$(DOTFILES_DIR)/scripts/common/detect_os.sh" ]; then \
echo " OS detection script: available"; \
else \
echo " OS detection script: not found"; \
fi
@echo -e "\n$(YELLOW)Available Profiles:$(NC)"
@echo " workstation (development environment)"
@echo " home (personal setup)"
@echo " server (minimal headless setup)"
@echo -e "\n$(YELLOW)Package Managers:$(NC)"
@for pm in brew apt-get snap; do \
if command -v $$pm >/dev/null 2>&1; then \
echo -e " $(GREEN)✓$(NC) $$pm"; \
else \
echo -e " $(RED)✗$(NC) $$pm"; \
fi; \
done
@echo -e "\n$(YELLOW)Package Files:$(NC)"
@for pkg_file in packages/common.yaml packages/node.yaml packages/linux/apt.yaml packages/macos/Brewfile.shared; do \
if [ -f "$(DOTFILES_DIR)/$$pkg_file" ]; then \
echo -e " $(GREEN)✓$(NC) $$pkg_file"; \
else \
echo -e " $(RED)✗$(NC) $$pkg_file"; \
fi; \
done
@echo -e "\n$(YELLOW)Environment Variables (potentially problematic):$(NC)"
@env | grep -E "^(OS|DETECTED_OS|OS_TYPE)" || echo " None found"
# =============================================================================
# Advanced Commands
# =============================================================================
bootstrap: ## Bootstrap a new system (install dependencies)
@echo -e "$(BLUE)Bootstrapping system...$(NC)"
@if ! command -v brew >/dev/null 2>&1 && [[ "$$(uname)" == "Darwin" ]]; then \
echo -e "$(YELLOW)Installing Homebrew...$(NC)" && \
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
else \
echo -e "$(GREEN)Homebrew already installed or not needed$(NC)"; \
fi
@if ! command -v git >/dev/null 2>&1; then \
echo -e "$(YELLOW)Installing Git...$(NC)"; \
if command -v brew >/dev/null 2>&1; then brew install git; \
elif command -v apt-get >/dev/null 2>&1; then sudo apt-get update && sudo apt-get install -y git; \
fi; \
else echo -e "$(GREEN)Git already installed$(NC)"; \
fi
@echo -e "$(GREEN)Bootstrap completed! Run 'make install' to continue.$(NC)"
doctor: ## Run comprehensive health check
@echo -e "$(BLUE)Running dotfiles health check...$(NC)\n"
@$(MAKE) check-updates
@$(MAKE) validate
@$(MAKE) info
@echo -e "$(GREEN)Health check completed!$(NC)"
init-submodules: ## Initialize git submodules
@echo -e "$(BLUE)Initializing git submodules...$(NC)"
@if [ ! -d "$(DOTFILES_DIR)/.git" ]; then \
echo -e "$(RED)Not a git repository. Run from ~/.dotfiles$(NC)"; exit 1; \
fi
@cd $(DOTFILES_DIR) && \
if [ ! -f ".gitmodules" ]; then git submodule add https://github.com/anishathalye/dotbot.git $(DOTBOT_DIR); fi
@cd $(DOTFILES_DIR) && git submodule update --init --recursive
@echo -e "$(GREEN)Submodules initialized successfully!$(NC)"
init-repo: ## Initialize new dotfiles repository
@echo -e "$(BLUE)Initializing new dotfiles repository...$(NC)"
@if [ ! -d "$(DOTFILES_DIR)/.git" ]; then \
cd $(DOTFILES_DIR) && git init && echo -e "$(GREEN)Git repository initialized$(NC)"; \
else echo -e "$(YELLOW)Git repository already exists$(NC)"; \
fi
@cd $(DOTFILES_DIR) && \
if [ ! -d "dotbot" ]; then \
git submodule add https://github.com/anishathalye/dotbot && \
git submodule update --init --recursive && \
echo -e "$(GREEN)Dotbot submodule added$(NC)"; \
else echo -e "$(YELLOW)Dotbot submodule already exists$(NC)"; \
fi
@cd $(DOTFILES_DIR) && chmod +x install
@echo -e "$(GREEN)Repository initialization completed!$(NC)"
validate-structure: ## Validate dotfiles directory structure
@echo -e "$(BLUE)Validating directory structure...$(NC)"
@cd $(DOTFILES_DIR) && \
for dir in configs packages scripts logs; do \
if [ -d "$$dir" ]; then echo -e " $(GREEN)✓$(NC) $$dir/ exists"; \
else echo -e " $(RED)✗$(NC) $$dir/ missing"; fi; \
done
@cd $(DOTFILES_DIR) && \
for file in install install.conf.yaml Makefile; do \
if [ -f "$$file" ]; then echo -e " $(GREEN)✓$(NC) $$file exists"; \
else echo -e " $(RED)✗$(NC) $$file missing"; fi; \
done
# Debug command to check environment
debug-env: ## Debug environment variables
@echo -e "$(BLUE)Environment Debug Information$(NC)"
@echo -e "$(YELLOW)Makefile Variables:$(NC)"
@echo " PROFILE: $(PROFILE)"
@echo " DOTFILES_DIR: $(DOTFILES_DIR)"
@echo " DOTBOT_DIR: $(DOTBOT_DIR)"
@echo -e "\n$(YELLOW)Shell Environment Variables:$(NC)"
@env | grep -E "^(OS|DETECTED_OS|OS_TYPE|LINUX_DISTRO)" || echo " No problematic OS variables found"
@echo -e "\n$(YELLOW)System Information:$(NC)"
@echo " uname -s: $$(uname -s)"
@echo " uname -m: $$(uname -m)"