-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
407 lines (347 loc) · 11.5 KB
/
install.sh
File metadata and controls
407 lines (347 loc) · 11.5 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
#!/bin/bash
# Claude Code Toolkit Installer
# Safely installs Claude hooks, agents, and MCP configuration to any directory
# Usage: curl https://raw.githubusercontent.com/Mandalorian007/claude-code-toolkit/main/install.sh | bash
set -e
# Configuration
REPO_URL="https://github.com/Mandalorian007/claude-code-toolkit"
TEMP_DIR=$(mktemp -d)
CURRENT_DIR=$(pwd)
BACKUP_DIR=".claude-toolkit-backup-$(date +%s)"
NEEDS_BACKUP=false
# Required environment variables
REQUIRED_ENV_VARS=(
"ENGINEER_NAME=your-name-here # TODO: Your name for TTS personalization"
"ELEVENLABS_API_KEY=your-elevenlabs-key # TODO: Get from https://elevenlabs.io"
"ELEVENLABS_VOICE_ID=aUNOP2y8xEvi4nZebjIw # TODO: Choose voice ID from ElevenLabs"
"PERPLEXITY_API_KEY=your-perplexity-key # TODO: Get from https://docs.perplexity.ai"
"FIRECRAWL_API_KEY=your-firecrawl-key # TODO: Get from https://firecrawl.dev"
"YOUTUBE_API_KEY=your-youtube-key # TODO: Get from Google Cloud Console"
"YOUTUBE_TRANSCRIPT_LANG=en # Language for YouTube transcripts"
)
# Essential .gitignore entries
GITIGNORE_ENTRIES=(
".env"
)
# Colors and symbols for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 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_skip() {
echo -e "${YELLOW}⏭️ $1${NC}"
}
log_install() {
echo -e "${BLUE}📦 $1${NC}"
}
# Cleanup function
cleanup() {
if [[ -d "$TEMP_DIR" ]]; then
rm -rf "$TEMP_DIR"
fi
}
trap cleanup EXIT
# OS Detection
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [[ -f /etc/os-release ]]; then
. /etc/os-release
case $ID in
ubuntu|debian) echo "debian" ;;
centos|rhel|fedora) echo "redhat" ;;
arch) echo "arch" ;;
*) echo "linux" ;;
esac
else
echo "linux"
fi
else
echo "unknown"
fi
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Install with package manager (advisory only - no sudo)
install_package_advisory() {
local package=$1
local os=$2
log_warning "$package not found. Please install it manually:"
case $os in
macos)
echo " brew install $package"
;;
debian)
echo " sudo apt-get update && sudo apt-get install -y $package"
;;
redhat)
echo " sudo dnf install -y $package"
echo " # or: sudo yum install -y $package"
;;
arch)
echo " sudo pacman -S $package"
;;
*)
echo " (Please install $package using your system's package manager)"
;;
esac
echo ""
}
# Check dependencies (no automatic installation)
check_dependencies() {
local os=$(detect_os)
local missing_deps=()
log_info "Detected OS: $os"
log_info "Checking system dependencies..."
# Check Claude Code CLI
if command_exists claude; then
local claude_version=$(claude --version 2>/dev/null || echo "unknown")
log_success "Claude Code is already installed ($claude_version)"
else
missing_deps+=("claude")
log_warning "Claude Code not found. Please install it manually:"
echo " Visit: https://docs.anthropic.com/en/docs/claude-code/overview"
echo " Or download from: https://claude.ai/download"
echo ""
fi
# Check ffmpeg
if command_exists ffmpeg; then
log_success "ffmpeg is already installed"
else
missing_deps+=("ffmpeg")
install_package_advisory ffmpeg "$os"
fi
# Check node/npm
if command_exists node && command_exists npm; then
local node_version=$(node --version)
log_success "Node.js is already installed ($node_version)"
else
missing_deps+=("node/npm")
case $os in
macos)
log_warning "Node.js/npm not found. Please install:"
echo " brew install node"
;;
debian)
log_warning "Node.js/npm not found. Please install:"
echo " curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -"
echo " sudo apt-get install -y nodejs"
;;
*)
log_warning "Node.js/npm not found. Please install nodejs using your package manager."
;;
esac
echo ""
fi
# Check npx (should come with npm)
if command_exists npx; then
log_success "npx is available"
elif command_exists node; then
log_warning "npx not available (but Node.js is installed - this is unusual)"
fi
# Return status based on whether we have missing dependencies
if [[ ${#missing_deps[@]} -gt 0 ]]; then
log_warning "Missing dependencies detected. The toolkit will still install, but you'll need these for full functionality:"
for dep in "${missing_deps[@]}"; do
echo " - $dep"
done
echo ""
log_info "You can install these dependencies later and the toolkit will work fine."
return 1
fi
return 0
}
# Setup environment variables
setup_env_file() {
local added_count=0
local missing_vars=()
log_info "Setting up .env file..."
# Create .env if it doesn't exist
if [[ ! -f ".env" ]]; then
log_install "Creating new .env file"
touch ".env"
fi
# Check and add missing environment variables
for env_line in "${REQUIRED_ENV_VARS[@]}"; do
local var_name=$(echo "$env_line" | cut -d'=' -f1)
local var_line=$(echo "$env_line" | cut -d'#' -f1 | xargs) # Remove comment for checking
# Check if variable already exists in .env
if ! grep -q "^${var_name}=" ".env" 2>/dev/null; then
echo "$env_line" >> ".env"
((added_count++))
# Check if it's a TODO item (placeholder value)
if [[ "$env_line" =~ your-.*-key|your-name-here ]]; then
missing_vars+=("$var_name")
fi
fi
done
if [[ $added_count -gt 0 ]]; then
log_success "Added $added_count environment variables to .env"
else
log_skip "All environment variables already present in .env"
fi
# Report missing variables that need user attention
if [[ ${#missing_vars[@]} -gt 0 ]]; then
log_warning "User needs to configure these environment variables:"
for var in "${missing_vars[@]}"; do
echo " - $var"
done
fi
}
# Smart merge for .gitignore
merge_gitignore() {
local target_file=".gitignore"
if [[ ! -f "$target_file" ]]; then
log_install "Creating new .gitignore"
printf "%s\n" "${GITIGNORE_ENTRIES[@]}" > "$target_file"
return
fi
log_info "Merging .gitignore entries..."
# Add missing entries
local added_count=0
for entry in "${GITIGNORE_ENTRIES[@]}"; do
if ! grep -Fxq "$entry" "$target_file" 2>/dev/null; then
echo "$entry" >> "$target_file"
((added_count++))
fi
done
if [[ $added_count -gt 0 ]]; then
log_success "Added $added_count new entries to .gitignore"
else
log_skip "All .gitignore entries already present"
fi
}
# Backup existing file if it exists
backup_file() {
local file=$1
if [[ -e "$file" ]]; then
if [[ "$NEEDS_BACKUP" == false ]]; then
log_info "Creating backup directory: $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
NEEDS_BACKUP=true
fi
log_info "Backing up existing $file"
cp -r "$file" "$BACKUP_DIR/"
return 0
fi
return 1
}
# Install files with smart merging
install_files() {
log_info "Installing Claude toolkit files..."
# Handle .claude directory
if backup_file ".claude"; then
log_warning "Existing .claude directory found, backed up"
fi
log_install "Installing .claude directory..."
cp -r "$TEMP_DIR/.claude" .
log_success ".claude directory installed"
# Handle .mcp.json
if backup_file ".mcp.json"; then
log_warning "Existing .mcp.json found, backed up"
fi
log_install "Installing .mcp.json..."
cp "$TEMP_DIR/.mcp.json" .
log_success ".mcp.json installed"
# Setup environment variables
setup_env_file
# Smart .gitignore merge
merge_gitignore
}
# Verify installation
verify_installation() {
log_info "Verifying installation..."
local errors=0
# Check required files
for file in ".claude/settings.json" ".claude/hooks" ".mcp.json" ".env"; do
if [[ -e "$file" ]]; then
log_success "$file installed correctly"
else
log_error "$file missing"
((errors++))
fi
done
# Check hook files
for hook in "user_prompt_submit.py" "pre_tool_use.py" "post_tool_use.py" "notification.py" "stop.py"; do
if [[ -f ".claude/hooks/$hook" ]]; then
log_success "Hook $hook installed"
else
log_error "Hook $hook missing"
((errors++))
fi
done
return $errors
}
# Main installation function
main() {
echo "🎭 Claude Code Toolkit Installer"
echo "================================="
echo ""
# Safety check
log_info "Checking current directory..."
if [[ ! -f "package.json" && ! -f "pyproject.toml" && ! -f "Cargo.toml" && ! -f ".git/config" && ! -f "README.md" ]]; then
log_warning "This doesn't look like a project directory."
echo "Continue anyway? (y/N): "
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
log_error "Installation cancelled"
exit 1
fi
fi
# Check dependencies (advisory only)
log_info "Checking system dependencies..."
check_dependencies # Don't exit on missing deps
# Download toolkit
log_info "Downloading Claude toolkit..."
if curl -L "${REPO_URL}/archive/main.tar.gz" | tar -xz -C "$TEMP_DIR" --strip-components=1; then
log_success "Toolkit downloaded successfully"
else
log_error "Failed to download toolkit"
exit 1
fi
# Install files
install_files
# Verify installation
if verify_installation; then
echo ""
log_success "Installation completed successfully!"
echo ""
echo "📋 Next steps:"
echo " 1. Configure your API keys in .env (see TODO comments)"
echo " 2. Install any missing dependencies shown above"
echo " 3. Launch Claude Code: export \$(cat .env | xargs) && claude"
echo " 4. Try the @prime command to load project context"
echo ""
echo "📚 Documentation: https://github.com/Mandalorian007/claude-code-toolkit"
if [[ "$NEEDS_BACKUP" == true ]]; then
echo ""
log_info "Previous files backed up to: $BACKUP_DIR"
fi
else
log_error "Installation verification failed"
if [[ "$NEEDS_BACKUP" == true ]]; then
echo ""
log_info "Your original files are backed up in: $BACKUP_DIR"
fi
exit 1
fi
}
# Run main function
main "$@"