117 lines
3.8 KiB
Bash
117 lines
3.8 KiB
Bash
#!/bin/bash
|
|
# Convert CRLF to LF if present (handles Windows line endings)
|
|
if command -v dos2unix >/dev/null 2>&1; then
|
|
dos2unix "$0" 2>/dev/null || true
|
|
fi
|
|
|
|
set -e
|
|
echo "🤖 Installing Claude Code CLI..."
|
|
|
|
# Check if already installed
|
|
if command -v claude >/dev/null 2>&1; then
|
|
echo "✅ Claude Code already installed"
|
|
claude --version || echo "Claude Code version check failed"
|
|
exit 0
|
|
fi
|
|
|
|
# Cross-platform home directory detection
|
|
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
|
|
HOME_DIR="${USERPROFILE:-$HOME}"
|
|
BIN_DIR="$HOME_DIR/bin"
|
|
# Windows/WSL/Git Bash compatibility
|
|
export NVM_DIR="$HOME_DIR/.nvm"
|
|
else
|
|
HOME_DIR="$HOME"
|
|
BIN_DIR="/home/coder/bin"
|
|
export NVM_DIR="$HOME/.nvm"
|
|
fi
|
|
|
|
# Ensure npm is available
|
|
# First, try to find npm in common locations
|
|
NPM_PATHS=(
|
|
"/usr/bin/npm"
|
|
"/usr/local/bin/npm"
|
|
"$HOME/.nvm/versions/node/*/bin/npm"
|
|
"/home/coder/.nvm/versions/node/*/bin/npm"
|
|
"/opt/nodejs/bin/npm"
|
|
)
|
|
|
|
NPM_CMD=""
|
|
for npm_path in "${NPM_PATHS[@]}"; do
|
|
if [[ -f "$npm_path" ]] || [[ -x "$npm_path" ]]; then
|
|
NPM_CMD="$npm_path"
|
|
break
|
|
fi
|
|
done
|
|
|
|
# Try sourcing nvm if npm not found yet
|
|
if [[ -z "$NPM_CMD" ]] && [[ -s "$NVM_DIR/nvm.sh" ]]; then
|
|
# Use POSIX-compatible sourcing
|
|
. "$NVM_DIR/nvm.sh"
|
|
NPM_CMD=$(command -v npm 2>/dev/null || true)
|
|
fi
|
|
|
|
# Final check for npm in PATH
|
|
if [[ -z "$NPM_CMD" ]]; then
|
|
NPM_CMD=$(command -v npm 2>/dev/null || true)
|
|
fi
|
|
|
|
if [[ -z "$NPM_CMD" ]] || [[ ! -x "$NPM_CMD" ]]; then
|
|
echo "❌ npm not found - Node.js installation required"
|
|
echo "Searched in: ${NPM_PATHS[*]}"
|
|
echo "PATH: $PATH"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ Found npm at: $NPM_CMD"
|
|
|
|
echo "📥 Installing Claude Code CLI..."
|
|
$NPM_CMD install -g @anthropic-ai/claude-code
|
|
|
|
# Verify installation
|
|
if command -v claude >/dev/null 2>&1; then
|
|
echo "✅ Claude Code installed successfully!"
|
|
echo "🔧 Run 'claude auth login' to authenticate"
|
|
echo "💡 Use 'claude chat' for interactive assistance"
|
|
echo "💡 Use 'claude edit <file>' to edit files with AI"
|
|
|
|
# Create helper script with proper line endings
|
|
mkdir -p "$BIN_DIR"
|
|
|
|
# Use printf instead of cat with heredoc to ensure consistent line endings
|
|
{
|
|
printf '#!/bin/bash\n'
|
|
printf 'echo "🤖 Claude Code AI Assistant"\n'
|
|
printf 'echo "=========================="\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "Authentication:"\n'
|
|
printf 'echo " claude auth login # Authenticate with Anthropic"\n'
|
|
printf 'echo " claude auth logout # Sign out"\n'
|
|
printf 'echo " claude auth whoami # Check current user"\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "Interactive Chat:"\n'
|
|
printf 'echo " claude chat # Start interactive session"\n'
|
|
printf 'echo " claude chat '\''question'\'' # Single question"\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "File Editing:"\n'
|
|
printf 'echo " claude edit file.py # AI-powered file editing"\n'
|
|
printf 'echo " claude edit --help # Edit command options"\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "Code Analysis:"\n'
|
|
printf 'echo " claude analyze . # Analyze current directory"\n'
|
|
printf 'echo " claude review file.py # Code review"\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "Project Operations:"\n'
|
|
printf 'echo " claude init # Initialize Claude in project"\n'
|
|
printf 'echo " claude status # Show project status"\n'
|
|
printf 'echo ""\n'
|
|
printf 'echo "💡 For full documentation: https://docs.anthropic.com/claude/docs"\n'
|
|
} > "$BIN_DIR/claude-help"
|
|
|
|
chmod +x "$BIN_DIR/claude-help"
|
|
|
|
echo "💡 Run 'claude-help' for quick reference"
|
|
else
|
|
echo "❌ Claude Code installation failed"
|
|
exit 1
|
|
fi |