-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·172 lines (156 loc) · 6.58 KB
/
setup.sh
File metadata and controls
executable file
·172 lines (156 loc) · 6.58 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
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (c) 2026 Marcus Krueger
# Master setup script for CodeForge devcontainer
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEVCONTAINER_DIR="$(dirname "$SCRIPT_DIR")"
ENV_FILE="$DEVCONTAINER_DIR/.env"
# Load configuration
if [ -f "$ENV_FILE" ]; then
set -a
source "$ENV_FILE"
set +a
fi
# Deprecation guard: .env may still set CLAUDE_CONFIG_DIR=/workspaces/.claude
# (pre-v2.0 default). Since .env is gitignored, PR updates can't fix it.
# Override with warning so all child scripts use the correct home location.
if [ "$CLAUDE_CONFIG_DIR" = "/workspaces/.claude" ]; then
echo "[setup] WARNING: CLAUDE_CONFIG_DIR=/workspaces/.claude is deprecated (moved to home dir in v2.0)"
echo "[setup] Updating .devcontainer/.env automatically."
CLAUDE_CONFIG_DIR="$HOME/.claude"
# Fix the file on disk so subsequent restarts don't trigger this guard
if [ -f "$ENV_FILE" ]; then
sed -i 's|^CLAUDE_CONFIG_DIR=.*/workspaces/\.claude.*|# CLAUDE_CONFIG_DIR removed (v2.0: now uses $HOME/.claude)|' "$ENV_FILE"
echo "[setup] .env updated — CLAUDE_CONFIG_DIR line commented out."
fi
fi
# Deprecation guard: CONFIG_SOURCE_DIR may still point to /workspaces/.claude
# (pre-v2.0 default was to keep config source in workspace .claude dir).
# Override with correct path.
if [ "$CONFIG_SOURCE_DIR" = "/workspaces/.claude" ]; then
echo "[setup] WARNING: CONFIG_SOURCE_DIR=/workspaces/.claude is deprecated (moved to .devcontainer/config in v2.0)"
echo "[setup] Updating .devcontainer/.env automatically."
CONFIG_SOURCE_DIR="$DEVCONTAINER_DIR/config"
if [ -f "$ENV_FILE" ]; then
sed -i 's|^CONFIG_SOURCE_DIR=.*/workspaces/\.claude.*|# CONFIG_SOURCE_DIR removed (v2.0: now uses .devcontainer/config)|' "$ENV_FILE"
echo "[setup] .env updated — CONFIG_SOURCE_DIR line commented out."
fi
fi
# Apply defaults for any unset variables
: "${CLAUDE_CONFIG_DIR:=$HOME/.claude}"
: "${CONFIG_SOURCE_DIR:=$DEVCONTAINER_DIR/config}"
: "${SETUP_CONFIG:=true}"
: "${SETUP_ALIASES:=true}"
: "${SETUP_AUTH:=true}"
: "${SETUP_PLUGINS:=true}"
: "${SETUP_UPDATE_CLAUDE:=true}"
: "${SETUP_PROJECTS:=true}"
: "${SETUP_TERMINAL:=true}"
: "${SETUP_POSTSTART:=true}"
export CLAUDE_CONFIG_DIR CONFIG_SOURCE_DIR SETUP_CONFIG SETUP_ALIASES SETUP_AUTH SETUP_PLUGINS SETUP_UPDATE_CLAUDE SETUP_PROJECTS SETUP_TERMINAL SETUP_POSTSTART
# Fix named volume ownership — Docker creates named volumes as root:root
# regardless of remoteUser. This is the only setup script requiring sudo.
if ! sudo chown "$(id -un):$(id -gn)" "$HOME/.claude" 2>/dev/null; then
echo "[setup] WARNING: Could not fix volume ownership on $HOME/.claude — subsequent scripts may fail"
fi
SETUP_START=$(date +%s)
SETUP_RESULTS=()
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " CodeForge Setup"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
run_script() {
local script="$1"
local enabled="$2"
local name
name="$(basename "$script" .sh)"
if [ "$enabled" = "true" ]; then
if [ -f "$script" ]; then
printf " %-30s" "$name..."
local output
if output=$(bash "$script" 2>&1); then
echo "done"
SETUP_RESULTS+=("$name:ok")
else
local exit_code=$?
echo "FAILED (exit $exit_code)"
SETUP_RESULTS+=("$name:failed")
# Show output on failure for diagnostics
echo "$output" | sed 's/^/ /'
fi
else
echo " $name... not found, skipping"
SETUP_RESULTS+=("$name:missing")
fi
else
echo " $name... skipped (disabled)"
SETUP_RESULTS+=("$name:disabled")
fi
}
run_poststart_hooks() {
local hook_dir="/usr/local/devcontainer-poststart.d"
if [ ! -d "$hook_dir" ]; then
return 0
fi
local count=0
for hook in "$hook_dir"/*.sh; do
[ -f "$hook" ] || continue
[ -x "$hook" ] || continue
local name
name="$(basename "$hook")"
printf " %-30s" "$name..."
if bash "$hook" 2>&1; then
echo "done"
count=$((count + 1))
else
echo "FAILED (exit $?)"
fi
done
if [ $count -gt 0 ]; then
SETUP_RESULTS+=("poststart-hooks:ok ($count)")
fi
}
run_script "$SCRIPT_DIR/setup-migrate-claude.sh" "true"
run_script "$SCRIPT_DIR/setup-auth.sh" "$SETUP_AUTH"
run_script "$SCRIPT_DIR/setup-config.sh" "$SETUP_CONFIG"
run_script "$SCRIPT_DIR/setup-aliases.sh" "$SETUP_ALIASES"
run_script "$SCRIPT_DIR/setup-plugins.sh" "$SETUP_PLUGINS"
run_script "$SCRIPT_DIR/setup-projects.sh" "$SETUP_PROJECTS"
run_script "$SCRIPT_DIR/setup-terminal.sh" "$SETUP_TERMINAL"
# Background the update to avoid blocking container start
if [ "$SETUP_UPDATE_CLAUDE" = "true" ] && [ -f "$SCRIPT_DIR/setup-update-claude.sh" ]; then
CLAUDE_UPDATE_LOG="${CLAUDE_UPDATE_LOG:-/workspaces/.tmp/claude-update.log}"
mkdir -p "$(dirname "$CLAUDE_UPDATE_LOG")"
bash "$SCRIPT_DIR/setup-update-claude.sh" >>"$CLAUDE_UPDATE_LOG" 2>&1 &
disown
SETUP_RESULTS+=("setup-update-claude:background")
else
SETUP_RESULTS+=("setup-update-claude:disabled")
fi
# Run post-start hooks
if [ "$SETUP_POSTSTART" = "true" ]; then
run_poststart_hooks
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Setup Summary"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
FAILURES=0
for result in "${SETUP_RESULTS[@]}"; do
name="${result%%:*}"
status="${result##*:}"
case "$status" in
ok*) printf " ✓ %s\n" "$name" ;;
failed) printf " ✗ %s (FAILED)\n" "$name"; FAILURES=$((FAILURES + 1)) ;;
disabled) printf " - %s (disabled)\n" "$name" ;;
missing) printf " ? %s (not found)\n" "$name" ;;
background) printf " ⇢ %s (background)\n" "$name" ;;
esac
done
ELAPSED=$(( $(date +%s) - SETUP_START ))
echo ""
if [ $FAILURES -gt 0 ]; then
echo " $FAILURES step(s) failed. Check output above for details."
fi
echo " Completed in ${ELAPSED}s"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"