-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·782 lines (673 loc) · 22.9 KB
/
setup.sh
File metadata and controls
executable file
·782 lines (673 loc) · 22.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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
#!/bin/bash
# Finance Guru Setup Script
# Checks dependencies, creates directories, scaffolds config files.
# Run this after cloning the repository to set up your environment.
set -e
# ============================================================
# Path Setup
# ============================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR"
# ============================================================
# Terminal Color Detection
# ============================================================
# Detect whether stdout is an interactive terminal that supports
# color output. Fall back to plain text for pipes, CI, and cron.
# Use ${TERM:-dumb} to handle unset TERM (not just empty).
if [ -t 1 ] && [ "${TERM:-dumb}" != "dumb" ]; then
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m'
else
GREEN=''
RED=''
YELLOW=''
BOLD=''
NC=''
fi
# ============================================================
# Output Helper Functions
# ============================================================
info() {
printf " %s\n" "$1"
}
success() {
printf " ${GREEN}[OK]${NC} %s\n" "$1"
}
warn() {
printf " ${YELLOW}[WARN]${NC} %s\n" "$1"
}
error() {
printf " ${RED}[FAIL]${NC} %s\n" "$1"
}
header() {
printf "\n${BOLD}%s${NC}\n" "$1"
}
# ============================================================
# OS Detection
# ============================================================
# Sets two globals: DETECTED_OS (macos/linux/wsl)
# and PKG_MANAGER (brew/apt/none)
DETECTED_OS=""
PKG_MANAGER=""
detect_os() {
local kernel
kernel=$(uname -s)
case "$kernel" in
Darwin)
DETECTED_OS="macos"
if command -v brew &>/dev/null; then
PKG_MANAGER="brew"
else
PKG_MANAGER="none"
fi
;;
Linux)
if grep -qi microsoft /proc/version 2>/dev/null; then
DETECTED_OS="wsl"
else
DETECTED_OS="linux"
fi
if command -v apt &>/dev/null; then
PKG_MANAGER="apt"
else
PKG_MANAGER="none"
fi
;;
*)
DETECTED_OS="linux"
PKG_MANAGER="none"
;;
esac
}
# ============================================================
# Version Comparison
# ============================================================
# Returns 0 if $1 >= $2, 1 otherwise.
# Uses sort -V (verified on macOS Apple sort and GNU coreutils).
version_gte() {
[ "$(printf '%s\n' "$1" "$2" | sort -V | head -1)" = "$2" ]
}
# ============================================================
# Install Command Lookup
# ============================================================
# Returns the OS-specific install command for a dependency.
get_install_command() {
local dep_name="$1"
case "$dep_name" in
python3)
case "$DETECTED_OS" in
macos)
if [ "$PKG_MANAGER" = "brew" ]; then
printf "brew install python@3.12"
else
printf 'Install Homebrew first:\n /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"\nThen:\n brew install python@3.12'
fi
;;
linux|wsl)
if [ "$PKG_MANAGER" = "apt" ]; then
printf "sudo apt update && sudo apt install python3.12"
else
printf "Visit https://www.python.org/downloads/"
fi
;;
esac
;;
uv)
printf "curl -LsSf https://astral.sh/uv/install.sh | sh"
;;
bun)
printf "curl -fsSL https://bun.sh/install | bash"
;;
esac
}
# ============================================================
# Auto-Install Prompt
# ============================================================
# Prompts user to install a missing dependency. Only works in
# interactive mode (stdin is a tty). Skips in CI/pipes.
prompt_install() {
local dep_name="$1"
local install_cmd="$2"
# Check if stdin is a tty before prompting
if [ ! -t 0 ]; then
warn "Skipped: $dep_name (non-interactive)"
return 1
fi
# Skip auto-install for non-executable strings (multiline instructions,
# manual URLs, or instructional text that would fail under eval)
if [[ "$install_cmd" == *$'\n'* ]] || [[ "$install_cmd" =~ ^(Visit|Install|See|Go\ to) ]]; then
info "$dep_name requires manual installation:"
printf "%s\n" "$install_cmd" | while IFS= read -r line; do
printf " %s\n" "$line"
done
return 1
fi
printf " %s not found. Install now? [y/N] " "$dep_name"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
info "Installing $dep_name..."
if ! eval "$install_cmd"; then
error "Install command failed for $dep_name"
return 1
fi
# Re-check if install succeeded
case "$dep_name" in
Python) command -v python3 &>/dev/null && success "Installed: $dep_name" && return 0 ;;
uv) command -v uv &>/dev/null && success "Installed: $dep_name" && return 0 ;;
Bun) command -v bun &>/dev/null && success "Installed: $dep_name" && return 0 ;;
esac
error "Installation may have failed for $dep_name"
return 1
else
printf " ${YELLOW}Skipped:${NC} %s (user declined)\n" "$dep_name"
return 1
fi
}
# ============================================================
# Single Dependency Check
# ============================================================
# Checks if a command exists and optionally verifies minimum version.
# Returns 0 on success, 1 on failure.
check_dependency() {
local cmd="$1"
local name="$2"
local min_version="$3"
# Check if command exists
if ! command -v "$cmd" &>/dev/null; then
local install_cmd
install_cmd=$(get_install_command "$cmd")
printf " ${RED}[MISSING]${NC} %s (not found)\n" "$name"
info "Install with: $install_cmd"
return 1
fi
# Extract version (sentinel "0.0" ensures predictable behavior under set -e)
local found_version="0.0"
case "$cmd" in
python3) found_version=$(python3 --version 2>&1 | grep -oE '[0-9]+\.[0-9]+' | head -1) || found_version="0.0" ;;
uv) found_version=$(uv --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) || found_version="0.0" ;;
bun) found_version=$(bun --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) || found_version="0.0" ;;
esac
# Ensure fallback if extraction returned empty
[ -z "$found_version" ] && found_version="0.0"
# Check minimum version if specified
if [ -n "$min_version" ] && [ -n "$found_version" ]; then
if ! version_gte "$found_version" "$min_version"; then
local install_cmd
install_cmd=$(get_install_command "$cmd")
printf " ${RED}[MISSING]${NC} %s %s (>= %s required)\n" "$name" "$found_version" "$min_version"
info "Install with: $install_cmd"
return 1
fi
fi
# Success
if [ -n "$min_version" ]; then
printf " ${GREEN}[OK]${NC} %s %s (>= %s required)\n" "$name" "$found_version" "$min_version"
else
printf " ${GREEN}[OK]${NC} %s %s\n" "$name" "$found_version"
fi
return 0
}
# ============================================================
# Check All Dependencies
# ============================================================
# Checks all dependencies in a single pass, accumulating failures
# without triggering set -e. Reports all results before failing.
# Arrays to track failed deps for auto-install
FAILED_DEPS=()
FAILED_NAMES=()
FAILED_CMDS=()
check_all_deps() {
local missing=0
FAILED_DEPS=()
FAILED_NAMES=()
FAILED_CMDS=()
check_dependency "python3" "Python" "3.12" || { missing=$((missing + 1)); FAILED_DEPS+=("python3"); FAILED_NAMES+=("Python"); FAILED_CMDS+=("$(get_install_command python3)"); }
check_dependency "uv" "uv" "" || { missing=$((missing + 1)); FAILED_DEPS+=("uv"); FAILED_NAMES+=("uv"); FAILED_CMDS+=("$(get_install_command uv)"); }
check_dependency "bun" "Bun" "" || { missing=$((missing + 1)); FAILED_DEPS+=("bun"); FAILED_NAMES+=("Bun"); FAILED_CMDS+=("$(get_install_command bun)"); }
if [ "$missing" -gt 0 ]; then
printf "\n ${RED}%d dependency(ies) missing${NC}\n" "$missing"
return 1
fi
printf "\n ${GREEN}All dependencies satisfied${NC}\n"
return 0
}
# ============================================================
# Summary Tracking
# ============================================================
# Track items for the final summary report.
CREATED_ITEMS=()
SKIPPED_ITEMS=()
# ============================================================
# Progress Tracking
# ============================================================
# Tracks completed setup steps in .setup-progress for resumable re-runs.
# Step names: deps_checked, dirs_created, dirs_verified, config_scaffolded,
# python_deps_installed
PROGRESS_FILE="$PROJECT_ROOT/.setup-progress"
TOTAL_STEPS=6
is_step_complete() {
[ -f "$PROGRESS_FILE" ] && grep -q "^$1$" "$PROGRESS_FILE"
}
mark_step_complete() {
if ! is_step_complete "$1"; then
echo "$1" >> "$PROGRESS_FILE"
fi
}
show_progress() {
if [ -f "$PROGRESS_FILE" ]; then
local completed
completed=$(wc -l < "$PROGRESS_FILE" | tr -d ' ')
printf "\n ${YELLOW}Resuming setup...${NC} (%s/%s steps completed)\n" "$completed" "$TOTAL_STEPS"
while IFS= read -r step; do
printf " ${GREEN}[done]${NC} %s\n" "$step"
done < "$PROGRESS_FILE"
printf "\n"
fi
}
# ============================================================
# Directory Functions
# ============================================================
create_dir() {
if [ ! -d "$1" ]; then
mkdir -p "$1"
printf " ${GREEN}Created:${NC} %s\n" "$1"
CREATED_ITEMS+=("dir: $1")
else
printf " ${YELLOW}Already exists:${NC} %s\n" "$1"
SKIPPED_ITEMS+=("dir: $1")
fi
}
create_directory_structure() {
# fin-guru-private tree
create_dir "$PROJECT_ROOT/fin-guru-private"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/strategies"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/strategies/active"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/strategies/archive"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/strategies/risk-management"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/tickets"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/analysis"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/analysis/reports"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/reports"
create_dir "$PROJECT_ROOT/fin-guru-private/fin-guru/archive"
create_dir "$PROJECT_ROOT/fin-guru-private/guides"
create_dir "$PROJECT_ROOT/fin-guru-private/hedging"
# Portfolio data directories
create_dir "$PROJECT_ROOT/notebooks"
create_dir "$PROJECT_ROOT/notebooks/updates"
create_dir "$PROJECT_ROOT/notebooks/retirement-accounts"
create_dir "$PROJECT_ROOT/notebooks/transactions"
create_dir "$PROJECT_ROOT/notebooks/tools-needed"
create_dir "$PROJECT_ROOT/notebooks/tools-needed/done"
# Finance Guru data directory
create_dir "$PROJECT_ROOT/fin-guru/data"
}
verify_directory_structure() {
local missing=0
local dirs=(
"$PROJECT_ROOT/fin-guru-private"
"$PROJECT_ROOT/fin-guru-private/fin-guru"
"$PROJECT_ROOT/fin-guru-private/fin-guru/strategies"
"$PROJECT_ROOT/fin-guru-private/fin-guru/strategies/active"
"$PROJECT_ROOT/fin-guru-private/fin-guru/strategies/archive"
"$PROJECT_ROOT/fin-guru-private/fin-guru/strategies/risk-management"
"$PROJECT_ROOT/fin-guru-private/fin-guru/tickets"
"$PROJECT_ROOT/fin-guru-private/fin-guru/analysis"
"$PROJECT_ROOT/fin-guru-private/fin-guru/analysis/reports"
"$PROJECT_ROOT/fin-guru-private/fin-guru/reports"
"$PROJECT_ROOT/fin-guru-private/fin-guru/archive"
"$PROJECT_ROOT/fin-guru-private/guides"
"$PROJECT_ROOT/fin-guru-private/hedging"
"$PROJECT_ROOT/notebooks"
"$PROJECT_ROOT/notebooks/updates"
"$PROJECT_ROOT/notebooks/retirement-accounts"
"$PROJECT_ROOT/notebooks/transactions"
"$PROJECT_ROOT/notebooks/tools-needed"
"$PROJECT_ROOT/notebooks/tools-needed/done"
"$PROJECT_ROOT/fin-guru/data"
)
for dir in "${dirs[@]}"; do
if [ ! -d "$dir" ]; then
mkdir -p "$dir"
printf " ${GREEN}Recreated:${NC} %s\n" "$dir"
CREATED_ITEMS+=("dir (recreated): $dir")
missing=$((missing + 1))
fi
done
if [ "$missing" -eq 0 ]; then
printf " ${GREEN}[OK]${NC} All directories verified\n"
else
printf " ${YELLOW}Recreated %d missing directory(ies)${NC}\n" "$missing"
fi
}
# ============================================================
# Config Scaffolding
# ============================================================
scaffold_file() {
local target="$1"
local description="$2"
local basename_target
basename_target=$(basename "$target")
if [ -f "$target" ]; then
if [ -t 0 ]; then
printf " %s (%s) already exists. Overwrite? [y/N] " "$basename_target" "$description"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
return 0 # Caller writes content
else
printf " ${YELLOW}Kept existing:${NC} %s\n" "$target"
SKIPPED_ITEMS+=("file: $target")
return 1
fi
else
printf " ${YELLOW}Kept existing:${NC} %s (non-interactive)\n" "$target"
SKIPPED_ITEMS+=("file: $target")
return 1
fi
fi
# File doesn't exist -- caller will write it
return 0
}
scaffold_config_files() {
# 1. user-profile.yaml
local user_profile="$PROJECT_ROOT/fin-guru/data/user-profile.yaml"
if scaffold_file "$user_profile" "user profile template"; then
cat > "$user_profile" << 'PROFILE_EOF'
# Finance Guru User Profile Configuration
# Complete this profile during onboarding with the Onboarding Specialist
system_ownership:
type: "private_family_office"
owner: "sole_client"
mode: "exclusive_service"
data_location: "local_only"
orientation_status:
completed: false
assessment_path: ""
last_updated: ""
onboarding_phase: "pending" # pending | assessment | profiled | active
user_profile:
# Will be populated during onboarding
liquid_assets:
total: 0
accounts_count: 0
average_yield: 0.0
investment_portfolio:
total_value: 0
retirement_accounts: 0
allocation: ""
risk_profile: ""
cash_flow:
monthly_income: 0
fixed_expenses: 0
variable_expenses: 0
investment_capacity: 0
debt_profile:
mortgage_balance: 0
mortgage_payment: 0
weighted_interest_rate: 0.0
preferences:
risk_tolerance: ""
investment_philosophy: ""
time_horizon: ""
# Google Sheets Integration (optional)
google_sheets:
portfolio_tracker:
spreadsheet_id: ""
url: ""
purpose: "Finance Guru portfolio tracking"
PROFILE_EOF
printf " ${GREEN}Created:${NC} %s\n" "$user_profile"
CREATED_ITEMS+=("file: $user_profile")
fi
# 2. .env from .env.example
local env_file="$PROJECT_ROOT/.env"
if [ -f "$PROJECT_ROOT/.env.example" ]; then
if scaffold_file "$env_file" "environment config"; then
cp "$PROJECT_ROOT/.env.example" "$env_file"
printf " ${GREEN}Created:${NC} %s (from .env.example)\n" "$env_file"
CREATED_ITEMS+=("file: $env_file")
fi
else
warn ".env.example not found -- skipping .env creation"
fi
# 3. fin-guru-private/README.md
local private_readme="$PROJECT_ROOT/fin-guru-private/README.md"
if scaffold_file "$private_readme" "private directory README"; then
cat > "$private_readme" << 'README_EOF'
# Finance Guru Private Documentation
This directory contains your personal Finance Guru documentation:
- **fin-guru/strategies/** - Your portfolio strategies
- **fin-guru/tickets/** - Buy/sell execution tickets
- **fin-guru/analysis/** - Deep research and modeling
- **fin-guru/reports/** - Monthly market reviews
- **guides/** - Tool usage guides
## Important
This directory is gitignored and will not be committed to version control.
Your financial data stays private on your local machine.
## Getting Started
After running the setup script, activate the Onboarding Specialist:
```
/fin-guru:agents:onboarding-specialist
```
The specialist will guide you through:
1. Financial assessment
2. Portfolio profile creation
3. Strategy recommendations
Once onboarding is complete, you can use the Finance Orchestrator:
```
/finance-orchestrator
```
README_EOF
printf " ${GREEN}Created:${NC} %s\n" "$private_readme"
CREATED_ITEMS+=("file: $private_readme")
fi
}
# ============================================================
# Python Dependencies
# ============================================================
install_python_deps() {
if [ ! -f "$PROJECT_ROOT/pyproject.toml" ]; then
warn "pyproject.toml not found -- skipping Python dependency install"
return 0
fi
if (cd "$PROJECT_ROOT" && uv sync); then
success "Python dependencies installed via uv sync"
CREATED_ITEMS+=("Python dependencies (uv sync)")
else
error "uv sync failed -- you can retry with: cd $PROJECT_ROOT && uv sync"
return 1
fi
}
# ============================================================
# Pre-commit Hooks
# ============================================================
install_pre_commit_hooks() {
# Skip if no pre-commit config exists
if [ ! -f "$PROJECT_ROOT/.pre-commit-config.yaml" ]; then
info "No .pre-commit-config.yaml found -- skipping pre-commit setup"
return 0
fi
# Check if pre-commit is available; install via uv tool if not
if ! command -v pre-commit &>/dev/null; then
info "Installing pre-commit via uv tool..."
if ! uv tool install pre-commit; then
warn "Failed to install pre-commit -- you can install manually: uv tool install pre-commit"
return 0
fi
fi
# Install hooks (default migration mode preserves existing hooks as .legacy)
if (cd "$PROJECT_ROOT" && pre-commit install); then
success "Pre-commit hooks installed"
CREATED_ITEMS+=("Pre-commit hooks (pre-commit install)")
else
warn "pre-commit install failed -- you can retry with: cd $PROJECT_ROOT && pre-commit install"
fi
}
# ============================================================
# Summary
# ============================================================
print_summary() {
printf "\n"
printf "==========================================\n"
printf " ${GREEN}${BOLD}Setup Complete!${NC}\n"
printf "==========================================\n"
printf "\n"
# Created section
if [ ${#CREATED_ITEMS[@]} -gt 0 ]; then
printf " ${BOLD}Created:${NC}\n"
for item in "${CREATED_ITEMS[@]}"; do
printf " - %s\n" "$item"
done
printf "\n"
fi
# Skipped section
if [ ${#SKIPPED_ITEMS[@]} -gt 0 ]; then
printf " ${BOLD}Skipped (already existed):${NC}\n"
for item in "${SKIPPED_ITEMS[@]}"; do
printf " - %s\n" "$item"
done
printf "\n"
fi
# Next steps
printf " ${BOLD}Next steps:${NC}\n"
printf "\n"
printf " 1. Edit .env to add your API keys (optional)\n"
printf " yfinance works without API keys for basic market data.\n"
printf "\n"
printf " 2. Run the onboarding wizard:\n"
printf " uv run python scripts/onboarding/main.py\n"
printf "\n"
printf " 3. After onboarding: /finance-orchestrator\n"
printf "\n"
}
# ============================================================
# CLI Argument Parsing
# ============================================================
CHECK_DEPS_ONLY=false
show_usage() {
printf "Usage: ./setup.sh [OPTIONS]\n"
printf "\n"
printf "Options:\n"
printf " --check-deps-only Check dependencies without modifying anything\n"
printf " --help, -h Show this help message\n"
printf "\n"
printf "Setup creates fin-guru-private/ directory structure, scaffolds config\n"
printf "files, and installs Python dependencies. Run after cloning the repo.\n"
}
while [ $# -gt 0 ]; do
case "$1" in
--check-deps-only)
CHECK_DEPS_ONLY=true
shift
;;
--help|-h)
show_usage
exit 0
;;
*)
printf "Unknown option: %s\n" "$1"
printf "Run './setup.sh --help' for usage information.\n"
exit 1
;;
esac
done
# ============================================================
# Main Flow
# ============================================================
# Banner
printf "\n"
printf "==========================================\n"
printf " ${BOLD}Finance Guru Setup${NC}\n"
printf "==========================================\n"
printf "\n"
# Show resume status if re-running
show_progress
# Detect OS
detect_os
info "Detected OS: $DETECTED_OS (package manager: $PKG_MANAGER)"
# Check dependencies
header "Checking dependencies..."
if check_all_deps; then
# All deps present
if [ "$CHECK_DEPS_ONLY" = true ]; then
printf "\n"
header "Dependency check complete"
info "All dependencies are installed and meet version requirements."
exit 0
fi
else
# Some deps missing
if [ "$CHECK_DEPS_ONLY" = true ]; then
printf "\n"
header "Dependency check complete"
error "Some dependencies are missing. Install them and re-run."
exit 1
fi
# Offer auto-install for each missing dep
printf "\n"
header "Auto-install missing dependencies"
for i in "${!FAILED_NAMES[@]}"; do
prompt_install "${FAILED_NAMES[$i]}" "${FAILED_CMDS[$i]}" || true
done
# Re-check all deps after install attempts
printf "\n"
header "Re-checking dependencies..."
if ! check_all_deps; then
printf "\n"
error "Please install missing dependencies and re-run setup.sh"
exit 1
fi
fi
mark_step_complete "deps_checked"
# Step 2: Create directory structure + ALWAYS validate
# NOTE: verify_directory_structure runs on EVERY path (first run AND re-run).
# On first run with pre-existing dirs, mkdir -p is idempotent but we must still
# validate expected structure. On re-run, we skip creation but still validate.
# This satisfies CONTEXT.md decision: "Verify state of skipped items -- not just
# existence but expected structure."
if is_step_complete "dirs_created"; then
header "Verifying directory structure..."
verify_directory_structure
mark_step_complete "dirs_verified"
else
header "Creating directory structure..."
create_directory_structure
# Always validate after creation -- catches pre-existing dirs with missing subdirs
header "Validating directory structure..."
verify_directory_structure
mark_step_complete "dirs_created"
mark_step_complete "dirs_verified"
fi
# Step 3: Scaffold config files
if is_step_complete "config_scaffolded"; then
header "Verifying config files..."
# Still run scaffold_config_files -- it handles overwrite prompts internally
scaffold_config_files
else
header "Scaffolding config files..."
scaffold_config_files
mark_step_complete "config_scaffolded"
fi
# Step 4: Install Python dependencies
if is_step_complete "python_deps_installed"; then
header "Python dependencies..."
printf " ${GREEN}[done]${NC} Python dependencies already installed\n"
else
header "Installing Python dependencies..."
install_python_deps
mark_step_complete "python_deps_installed"
fi
# Step 5: Install pre-commit hooks
if is_step_complete "precommit_installed"; then
header "Pre-commit hooks..."
printf " ${GREEN}[done]${NC} Pre-commit hooks already installed\n"
else
header "Installing pre-commit hooks..."
install_pre_commit_hooks
mark_step_complete "precommit_installed"
fi
# Step 6: Summary
print_summary