-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·334 lines (285 loc) · 10.8 KB
/
install.sh
File metadata and controls
executable file
·334 lines (285 loc) · 10.8 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
#!/usr/bin/env bash
# Claude Code Merged Installer
# Usage: curl -fsSL https://your-repo.com/merged_install.sh | bash
# or: wget -qO- https://your-repo.com/merged_install.sh | bash
set -euo pipefail
# Configuration
REPO_URL="https://github.com/plusplusoneplusplus/ccc.git"
REPO_NAME="ccc"
CLAUDE_SOURCE_DIR="${HOME}/.claude-source-git"
CLAUDE_DIR="${HOME}/.claude"
BACKUP_DIR="${HOME}/.claude.backup.$(date +%Y%m%d_%H%M%S)"
# Default options
FORCE=0
DRY_RUN=0
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
NC='\033[0m'
usage() {
cat <<EOF
${BLUE}Claude Code Merged Installer${NC}
${PURPLE}Usage:${NC} $(basename "$0") [options]
${PURPLE}Options:${NC}
-f, --force Replace existing configuration and source
-n, --dry-run Show what would be done without making changes
-r, --repo-url Repository URL to clone from (default: $REPO_URL)
-s, --source-dir Source directory for persistent storage (default: $CLAUDE_SOURCE_DIR)
-h, --help Show this help message
${PURPLE}Examples:${NC}
$(basename "$0") # Standard installation
$(basename "$0") --force # Force overwrite existing setup
$(basename "$0") --dry-run # Preview installation steps
${BLUE}This script will:${NC}
• Clone the Claude configuration repository to a persistent location
• Create backup of existing ~/.claude if present
• Set up symbolic link from ~/.claude to the source directory
• Configure necessary permissions and directories
EOF
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-f|--force)
FORCE=1
shift
;;
-n|--dry-run)
DRY_RUN=1
shift
;;
-r|--repo-url)
REPO_URL="$2"
shift 2
;;
-s|--source-dir)
CLAUDE_SOURCE_DIR="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}" >&2
usage
exit 1
;;
esac
done
# Utility functions
log() {
echo -e "${GREEN}[INFO]${NC} $*"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}
error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
}
run_command() {
if [[ $DRY_RUN -eq 1 ]]; then
echo -e "${BLUE}[DRY-RUN]${NC} $*"
else
eval "$*"
fi
}
print_header() {
echo
echo -e "${PURPLE}╔══════════════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${PURPLE}║ Claude Code Configuration Installer ║${NC}"
echo -e "${PURPLE}║ ║${NC}"
echo -e "${PURPLE}║ This script will download and set up your Claude Code configuration ║${NC}"
echo -e "${PURPLE}║ with persistent storage and symbolic linking. ║${NC}"
echo -e "${PURPLE}╚══════════════════════════════════════════════════════════════════════════════╝${NC}"
echo
}
check_dependencies() {
log "Checking system dependencies..."
local missing_deps=()
if ! command -v git &> /dev/null; then
missing_deps+=("git")
fi
if ! command -v curl &> /dev/null && ! command -v wget &> /dev/null; then
missing_deps+=("curl or wget")
fi
if [[ ${#missing_deps[@]} -gt 0 ]]; then
error "Missing required dependencies: ${missing_deps[*]}"
error "Please install the missing dependencies and try again."
exit 1
fi
log "✓ All dependencies satisfied"
}
backup_existing_claude() {
if [[ -e "$CLAUDE_DIR" ]]; then
if [[ $FORCE -eq 0 && $DRY_RUN -eq 0 ]]; then
warn "Existing Claude configuration found at $CLAUDE_DIR"
if [[ -t 0 ]]; then
# TTY is available, can prompt user
echo -n "Do you want to backup and replace it? [Y/n] "
read -r response
if [[ "$response" =~ ^[Nn]$ ]]; then
log "Setup cancelled by user"
exit 0
fi
else
# No TTY, default to yes
log "No TTY detected, defaulting to backup and replace (use --force to skip this check)"
fi
elif [[ $DRY_RUN -eq 1 ]]; then
warn "Existing Claude configuration found at $CLAUDE_DIR"
log "In dry-run mode: would prompt to backup and replace"
fi
log "Creating backup at $BACKUP_DIR"
run_command "cp -r \"$CLAUDE_DIR\" \"$BACKUP_DIR\""
log "✓ Backup created at $BACKUP_DIR"
log "Removing existing configuration"
run_command "rm -rf \"$CLAUDE_DIR\""
fi
}
download_or_update_source() {
log "Setting up Claude source repository..."
if [[ -d "$CLAUDE_SOURCE_DIR" ]]; then
if [[ $FORCE -eq 1 ]]; then
log "Removing existing source directory"
run_command "rm -rf \"$CLAUDE_SOURCE_DIR\""
else
log "Updating existing repository at $CLAUDE_SOURCE_DIR"
if [[ $DRY_RUN -eq 0 ]]; then
cd "$CLAUDE_SOURCE_DIR"
if git rev-parse --git-dir > /dev/null 2>&1; then
run_command "git fetch origin"
run_command "git reset --hard origin/main"
log "✓ Repository updated successfully"
return
else
warn "Source directory exists but is not a git repository"
log "Removing and re-cloning"
run_command "rm -rf \"$CLAUDE_SOURCE_DIR\""
fi
else
echo -e "${BLUE}[DRY-RUN]${NC} cd \"$CLAUDE_SOURCE_DIR\" && git fetch origin && git reset --hard origin/main"
return
fi
fi
fi
log "Cloning repository from $REPO_URL"
run_command "git clone \"$REPO_URL\" \"$CLAUDE_SOURCE_DIR\""
log "✓ Repository downloaded successfully"
}
setup_permissions() {
log "Setting up file permissions..."
# Make shell scripts executable
run_command "find \"$CLAUDE_SOURCE_DIR\" -name '*.sh' -type f -exec chmod +x {} +"
log "✓ Permissions configured"
}
create_symlink() {
log "Setting up symbolic link..."
if [[ -e "$CLAUDE_DIR" || -L "$CLAUDE_DIR" ]]; then
if [[ -L "$CLAUDE_DIR" ]]; then
local current_target
current_target="$(readlink "$CLAUDE_DIR")"
if [[ "$current_target" == "$CLAUDE_SOURCE_DIR" ]]; then
log "✓ Symbolic link already exists and points to correct location"
return
fi
fi
warn "Removing existing ~/.claude to create symbolic link"
run_command "rm -rf \"$CLAUDE_DIR\""
fi
log "Creating symbolic link: $CLAUDE_DIR -> $CLAUDE_SOURCE_DIR"
run_command "ln -s \"$CLAUDE_SOURCE_DIR\" \"$CLAUDE_DIR\""
log "✓ Symbolic link created successfully"
}
verify_installation() {
log "Verifying installation..."
local files_to_check=(
"$CLAUDE_DIR/settings.json"
"$CLAUDE_DIR/statusline-enhanced.sh"
)
local all_good=1
for file in "${files_to_check[@]}"; do
if [[ -f "$file" ]]; then
log "✓ Found: $(basename "$file")"
else
error "✗ Missing: $file"
all_good=0
fi
done
# Check if symlink is correct
if [[ -L "$CLAUDE_DIR" ]]; then
local link_target
link_target="$(readlink "$CLAUDE_DIR")"
if [[ "$link_target" == "$CLAUDE_SOURCE_DIR" ]]; then
log "✓ Symbolic link is correctly configured"
else
error "✗ Symbolic link points to wrong location: $link_target"
all_good=0
fi
else
error "✗ ~/.claude is not a symbolic link"
all_good=0
fi
if [[ $all_good -eq 1 ]]; then
log "✓ Installation verification passed"
else
error "Installation verification failed"
exit 1
fi
}
print_completion_message() {
echo
echo -e "${GREEN}╔══════════════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Installation Complete! 🎉 ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════════════════════╝${NC}"
echo
echo -e "${BLUE}Your Claude Code configuration has been successfully installed!${NC}"
echo
echo -e "${PURPLE}Source repository:${NC} $CLAUDE_SOURCE_DIR"
echo -e "${PURPLE}Configuration symlink:${NC} $CLAUDE_DIR -> $CLAUDE_SOURCE_DIR"
if [[ -d "$BACKUP_DIR" ]]; then
echo -e "${PURPLE}Previous config backed up to:${NC} $BACKUP_DIR"
fi
echo
echo -e "${BLUE}Key features:${NC}"
echo -e " • Persistent source repository for easy updates"
echo -e " • Custom statusline with enhanced information"
echo -e " • GitHub submission workflow commands"
echo -e " • Project-specific configurations"
echo -e " • Command history and shell snapshots"
echo
echo -e "${BLUE}Next steps:${NC}"
echo -e " 1. Restart Claude Code or reload your configuration"
echo -e " 2. Check ~/.claude/settings.json for customization options"
echo -e " 3. Explore ~/.claude/commands/ for available commands"
echo
echo -e "${BLUE}To update in the future:${NC}"
echo -e " • Run this script again to pull the latest changes"
echo -e " • Or manually: cd $CLAUDE_SOURCE_DIR && git pull"
echo
echo -e "${GREEN}Happy coding with Claude! 🚀${NC}"
}
# Main execution
main() {
print_header
if [[ $DRY_RUN -eq 1 ]]; then
warn "DRY RUN MODE - No actual changes will be made"
echo
fi
log "Welcome to the Claude Code configuration installer!"
echo
check_dependencies
backup_existing_claude
download_or_update_source
setup_permissions
create_symlink
if [[ $DRY_RUN -eq 0 ]]; then
verify_installation
fi
print_completion_message
}
# Run main function
main "$@"