refactor: Claude Code 安装方式从官方原生脚本改为 npm install
Some checks failed
Deploy to Cloudflare Pages / deploy (push) Failing after 11s
Some checks failed
Deploy to Cloudflare Pages / deploy (push) Failing after 11s
国内用户无法访问 claude.ai/install.sh,统一三个工具的安装路径: - 移除 setup.sh/ps1 中 Claude Code 的特殊安装分支 - ClaudeCode 独立脚本添加 Node.js/fnm 检测安装函数链 - 三个工具均使用 npm install -g 安装 (需要 Node.js >= 20) - 更新 CLAUDE.md 和文档中的安装说明
This commit is contained in:
@@ -44,7 +44,7 @@ xcodecli-shells/
|
||||
|
||||
| 工具 | 安装方式 | 依赖 |
|
||||
| ---- | ---- | ---- |
|
||||
| Claude Code | 官方原生脚本 `curl -fsSL https://claude.ai/install.sh \| bash` | 无需 Node.js,自动更新 |
|
||||
| Claude Code | `npm install -g @anthropic-ai/claude-code` | **需要 Node.js >= 20** |
|
||||
| Gemini CLI | `npm install -g @google/gemini-cli@latest` | **需要 Node.js >= 20** |
|
||||
| Codex | `npm install -g @openai/codex` | **需要 Node.js >= 20** |
|
||||
|
||||
@@ -52,10 +52,9 @@ xcodecli-shells/
|
||||
|
||||
跨平台一站式安装配置工具:
|
||||
|
||||
- 检测 Node.js 环境,缺失时使用 fnm 安装 (Gemini CLI / Codex 需要)
|
||||
- 检测 Node.js 环境,缺失时使用 fnm 安装 (三个工具均需要)
|
||||
- 显示三个工具的安装状态
|
||||
- Claude Code 使用官方原生安装脚本 (`curl -fsSL https://claude.ai/install.sh | bash`)
|
||||
- Gemini CLI / Codex 使用 `npm install -g` 安装 (需要 Node.js >= 20)
|
||||
- 三个工具均使用 `npm install -g` 安装 (需要 Node.js >= 20)
|
||||
- 下载并执行对应工具的配置脚本
|
||||
|
||||
```powershell
|
||||
|
||||
@@ -31,6 +31,7 @@ $ClaudeConfigDir = "$env:USERPROFILE\.claude"
|
||||
$ClaudeSettingsFile = "$ClaudeConfigDir\settings.json"
|
||||
$ToolCommand = "claude"
|
||||
$ToolName = "Claude Code"
|
||||
$ToolPackage = "@anthropic-ai/claude-code"
|
||||
|
||||
# ========== 工具函数 ==========
|
||||
function Test-Command {
|
||||
@@ -80,14 +81,138 @@ function Write-Error {
|
||||
Write-Host " $Message"
|
||||
}
|
||||
|
||||
function Install-Tool {
|
||||
Write-Info "使用官方安装脚本安装 $ToolName..."
|
||||
Write-Host " 执行: irm https://claude.ai/install.ps1 | iex" -ForegroundColor Gray
|
||||
# ========== Node.js 环境检测 ==========
|
||||
function Get-NodeVersion {
|
||||
if (Test-Command "node") {
|
||||
try {
|
||||
$versionStr = (& node --version 2>$null) -replace 'v', ''
|
||||
$major = [int]($versionStr -split '\.')[0]
|
||||
return @{ Version = $versionStr; Major = $major }
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Install-Fnm {
|
||||
Write-Host ""
|
||||
Write-Info "正在安装 fnm (Fast Node Manager)..."
|
||||
|
||||
try {
|
||||
Invoke-Expression "& { $(Invoke-RestMethod https://claude.ai/install.ps1) }"
|
||||
if (Test-Command "winget") {
|
||||
Write-Info "使用 winget 安装 fnm..."
|
||||
& winget install Schniz.fnm -e --accept-source-agreements --accept-package-agreements
|
||||
}
|
||||
else {
|
||||
Write-Info "使用 PowerShell 脚本安装 fnm..."
|
||||
Invoke-Expression "& { $(Invoke-RestMethod https://fnm.vercel.app/install.ps1) }"
|
||||
}
|
||||
|
||||
Refresh-Path
|
||||
|
||||
if (Test-Command "fnm") {
|
||||
Write-Success "fnm 安装成功!"
|
||||
$fnmEnv = & fnm env --use-on-cd 2>$null
|
||||
if ($fnmEnv) {
|
||||
$fnmEnv | Out-String | Invoke-Expression
|
||||
}
|
||||
return $true
|
||||
}
|
||||
else {
|
||||
Write-Warning "fnm 可能已安装,但需要重新打开终端才能生效"
|
||||
Write-Info "请重新打开 PowerShell 后再运行此脚本"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "fnm 安装失败: $($_.Exception.Message)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function Install-NodeWithFnm {
|
||||
Write-Info "使用 fnm 安装 Node.js 24.x..."
|
||||
|
||||
try {
|
||||
& fnm install 24
|
||||
& fnm use 24
|
||||
& fnm default 24
|
||||
Refresh-Path
|
||||
|
||||
if (Test-Command "node") {
|
||||
$nodeInfo = Get-NodeVersion
|
||||
Write-Success "Node.js v$($nodeInfo.Version) 安装成功!"
|
||||
return $true
|
||||
}
|
||||
else {
|
||||
Write-Warning "Node.js 可能已安装,但需要重新打开终端才能生效"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Node.js 安装失败: $($_.Exception.Message)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function Ensure-NodeEnvironment {
|
||||
$nodeInfo = Get-NodeVersion
|
||||
|
||||
if ($nodeInfo) {
|
||||
Write-Info "检测到 Node.js v$($nodeInfo.Version)"
|
||||
|
||||
if ($nodeInfo.Major -lt 20) {
|
||||
Write-Warning "Node.js 版本过低 (需要 >= 20.x)"
|
||||
|
||||
$upgrade = Read-Host "是否使用 fnm 安装 Node.js 24.x? (Y/n)"
|
||||
if ($upgrade -eq "n" -or $upgrade -eq "N") {
|
||||
Write-Error "Node.js 版本不满足要求,请手动升级后重试"
|
||||
return $false
|
||||
}
|
||||
|
||||
if (-not (Test-Command "fnm")) {
|
||||
if (-not (Install-Fnm)) { return $false }
|
||||
}
|
||||
|
||||
return Install-NodeWithFnm
|
||||
}
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
Write-Warning "未检测到 Node.js"
|
||||
Write-Info "将使用 fnm 安装 Node.js 24.x"
|
||||
|
||||
$install = Read-Host "是否继续? (Y/n)"
|
||||
if ($install -eq "n" -or $install -eq "N") {
|
||||
return $false
|
||||
}
|
||||
|
||||
if (-not (Test-Command "fnm")) {
|
||||
if (-not (Install-Fnm)) { return $false }
|
||||
}
|
||||
|
||||
return Install-NodeWithFnm
|
||||
}
|
||||
|
||||
function Install-Tool {
|
||||
if (-not (Ensure-NodeEnvironment)) {
|
||||
return $false
|
||||
}
|
||||
|
||||
Write-Info "使用 npm 安装 $ToolName..."
|
||||
Write-Host " 执行: npm install -g $ToolPackage" -ForegroundColor Gray
|
||||
|
||||
try {
|
||||
Invoke-Expression "npm install -g $ToolPackage"
|
||||
$exitCode = $LASTEXITCODE
|
||||
Refresh-Path
|
||||
|
||||
if ($exitCode -ne 0) {
|
||||
Write-Error "安装命令返回错误码: $exitCode"
|
||||
return $false
|
||||
}
|
||||
|
||||
if (Test-Command $ToolCommand) {
|
||||
Write-Success "$ToolName 安装成功!"
|
||||
return $true
|
||||
|
||||
@@ -19,6 +19,7 @@ CLAUDE_CONFIG_DIR="$HOME/.claude"
|
||||
CLAUDE_SETTINGS_FILE="$CLAUDE_CONFIG_DIR/settings.json"
|
||||
TOOL_COMMAND="claude"
|
||||
TOOL_NAME="Claude Code"
|
||||
TOOL_PACKAGE="@anthropic-ai/claude-code"
|
||||
|
||||
# ========== Shell 环境变量配置 ==========
|
||||
get_shell_rc() {
|
||||
@@ -82,14 +83,115 @@ print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# ========== Node.js 环境检测 ==========
|
||||
get_node_version() {
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
node --version 2>/dev/null | sed 's/v//'
|
||||
fi
|
||||
}
|
||||
|
||||
get_node_major_version() {
|
||||
local version
|
||||
version=$(get_node_version)
|
||||
if [ -n "$version" ]; then
|
||||
echo "$version" | cut -d. -f1
|
||||
fi
|
||||
}
|
||||
|
||||
install_fnm() {
|
||||
echo ""
|
||||
print_info "正在安装 fnm (Fast Node Manager)..."
|
||||
|
||||
if curl -fsSL https://fnm.vercel.app/install | bash; then
|
||||
export PATH="$HOME/.local/share/fnm:$PATH"
|
||||
if [ -f "$HOME/.local/share/fnm/fnm" ]; then
|
||||
eval "$(~/.local/share/fnm/fnm env)"
|
||||
fi
|
||||
|
||||
if command -v fnm >/dev/null 2>&1; then
|
||||
print_success "fnm 安装成功!"
|
||||
return 0
|
||||
else
|
||||
print_warning "fnm 可能已安装,但需要重新打开终端才能生效"
|
||||
print_info "请重新打开终端后再运行此脚本"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "fnm 安装失败"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
install_node_with_fnm() {
|
||||
print_info "使用 fnm 安装 Node.js 24.x..."
|
||||
|
||||
if fnm install 24 && fnm use 24 && fnm default 24; then
|
||||
eval "$(fnm env)"
|
||||
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
local version
|
||||
version=$(get_node_version)
|
||||
print_success "Node.js v$version 安装成功!"
|
||||
return 0
|
||||
else
|
||||
print_warning "Node.js 可能已安装,但需要重新打开终端才能生效"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "Node.js 安装失败"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_node_environment() {
|
||||
local version major
|
||||
|
||||
version=$(get_node_version)
|
||||
if [ -n "$version" ]; then
|
||||
major=$(get_node_major_version)
|
||||
print_info "检测到 Node.js v$version"
|
||||
|
||||
if [ "$major" -lt 20 ]; then
|
||||
print_warning "Node.js 版本过低 (需要 >= 20.x)"
|
||||
|
||||
read -p "是否使用 fnm 安装 Node.js 24.x? (Y/n): " -r
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
print_error "Node.js 版本不满足要求,请手动升级后重试"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! command -v fnm >/dev/null 2>&1; then
|
||||
install_fnm || return 1
|
||||
fi
|
||||
|
||||
install_node_with_fnm || return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_warning "未检测到 Node.js"
|
||||
print_info "将使用 fnm 安装 Node.js 24.x"
|
||||
|
||||
read -p "是否继续? (Y/n): " -r
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! command -v fnm >/dev/null 2>&1; then
|
||||
install_fnm || return 1
|
||||
fi
|
||||
|
||||
install_node_with_fnm || return 1
|
||||
}
|
||||
|
||||
install_tool() {
|
||||
print_info "使用官方安装脚本安装 $TOOL_NAME..."
|
||||
echo " 执行: curl -fsSL https://claude.ai/install.sh | bash"
|
||||
ensure_node_environment || return 1
|
||||
|
||||
if bash -c 'set -o pipefail; curl -fsSL https://claude.ai/install.sh | bash'; then
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
hash -r 2>/dev/null || true
|
||||
print_info "使用 npm 安装 $TOOL_NAME..."
|
||||
echo " 执行: npm install -g $TOOL_PACKAGE"
|
||||
|
||||
if npm install -g "$TOOL_PACKAGE"; then
|
||||
if command -v "$TOOL_COMMAND" >/dev/null 2>&1; then
|
||||
print_success "$TOOL_NAME 安装成功!"
|
||||
return 0
|
||||
|
||||
@@ -47,6 +47,6 @@ $key='你的密钥'; $f="$env:TEMP\xc.ps1";iwr -useb https://gitea.sususu.cf/sus
|
||||
## 常见问题
|
||||
|
||||
- **Q: 安装后无法使用?**
|
||||
- A: 请确保已重新打开终端。Claude Code 使用原生安装器,无需 Node.js。如果问题仍存在,检查 `~/.local/bin` 是否在 PATH 中。
|
||||
- A: 请确保已重新打开终端。Claude Code 通过 npm 安装,需要 Node.js >= 20。如果问题仍存在,检查 Node.js 和 npm 全局目录是否在 PATH 中。
|
||||
- **Q: 权限错误?**
|
||||
- A: Claude Code 原生安装器会安装到用户目录 (`~/.local/bin`),通常不需要 `sudo`。
|
||||
- A: 使用 npm 安装时,建议通过 fnm 管理 Node.js,避免全局安装需要 `sudo`。
|
||||
|
||||
@@ -31,6 +31,7 @@ $ClaudeConfigDir = "$env:USERPROFILE\.claude"
|
||||
$ClaudeSettingsFile = "$ClaudeConfigDir\settings.json"
|
||||
$ToolCommand = "claude"
|
||||
$ToolName = "Claude Code"
|
||||
$ToolPackage = "@anthropic-ai/claude-code"
|
||||
|
||||
# ========== 工具函数 ==========
|
||||
function Test-Command {
|
||||
@@ -80,14 +81,138 @@ function Write-Error {
|
||||
Write-Host " $Message"
|
||||
}
|
||||
|
||||
function Install-Tool {
|
||||
Write-Info "使用官方安装脚本安装 $ToolName..."
|
||||
Write-Host " 执行: irm https://claude.ai/install.ps1 | iex" -ForegroundColor Gray
|
||||
# ========== Node.js 环境检测 ==========
|
||||
function Get-NodeVersion {
|
||||
if (Test-Command "node") {
|
||||
try {
|
||||
$versionStr = (& node --version 2>$null) -replace 'v', ''
|
||||
$major = [int]($versionStr -split '\.')[0]
|
||||
return @{ Version = $versionStr; Major = $major }
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Install-Fnm {
|
||||
Write-Host ""
|
||||
Write-Info "正在安装 fnm (Fast Node Manager)..."
|
||||
|
||||
try {
|
||||
Invoke-Expression "& { $(Invoke-RestMethod https://claude.ai/install.ps1) }"
|
||||
if (Test-Command "winget") {
|
||||
Write-Info "使用 winget 安装 fnm..."
|
||||
& winget install Schniz.fnm -e --accept-source-agreements --accept-package-agreements
|
||||
}
|
||||
else {
|
||||
Write-Info "使用 PowerShell 脚本安装 fnm..."
|
||||
Invoke-Expression "& { $(Invoke-RestMethod https://fnm.vercel.app/install.ps1) }"
|
||||
}
|
||||
|
||||
Refresh-Path
|
||||
|
||||
if (Test-Command "fnm") {
|
||||
Write-Success "fnm 安装成功!"
|
||||
$fnmEnv = & fnm env --use-on-cd 2>$null
|
||||
if ($fnmEnv) {
|
||||
$fnmEnv | Out-String | Invoke-Expression
|
||||
}
|
||||
return $true
|
||||
}
|
||||
else {
|
||||
Write-Warning "fnm 可能已安装,但需要重新打开终端才能生效"
|
||||
Write-Info "请重新打开 PowerShell 后再运行此脚本"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "fnm 安装失败: $($_.Exception.Message)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function Install-NodeWithFnm {
|
||||
Write-Info "使用 fnm 安装 Node.js 24.x..."
|
||||
|
||||
try {
|
||||
& fnm install 24
|
||||
& fnm use 24
|
||||
& fnm default 24
|
||||
Refresh-Path
|
||||
|
||||
if (Test-Command "node") {
|
||||
$nodeInfo = Get-NodeVersion
|
||||
Write-Success "Node.js v$($nodeInfo.Version) 安装成功!"
|
||||
return $true
|
||||
}
|
||||
else {
|
||||
Write-Warning "Node.js 可能已安装,但需要重新打开终端才能生效"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Node.js 安装失败: $($_.Exception.Message)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function Ensure-NodeEnvironment {
|
||||
$nodeInfo = Get-NodeVersion
|
||||
|
||||
if ($nodeInfo) {
|
||||
Write-Info "检测到 Node.js v$($nodeInfo.Version)"
|
||||
|
||||
if ($nodeInfo.Major -lt 20) {
|
||||
Write-Warning "Node.js 版本过低 (需要 >= 20.x)"
|
||||
|
||||
$upgrade = Read-Host "是否使用 fnm 安装 Node.js 24.x? (Y/n)"
|
||||
if ($upgrade -eq "n" -or $upgrade -eq "N") {
|
||||
Write-Error "Node.js 版本不满足要求,请手动升级后重试"
|
||||
return $false
|
||||
}
|
||||
|
||||
if (-not (Test-Command "fnm")) {
|
||||
if (-not (Install-Fnm)) { return $false }
|
||||
}
|
||||
|
||||
return Install-NodeWithFnm
|
||||
}
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
Write-Warning "未检测到 Node.js"
|
||||
Write-Info "将使用 fnm 安装 Node.js 24.x"
|
||||
|
||||
$install = Read-Host "是否继续? (Y/n)"
|
||||
if ($install -eq "n" -or $install -eq "N") {
|
||||
return $false
|
||||
}
|
||||
|
||||
if (-not (Test-Command "fnm")) {
|
||||
if (-not (Install-Fnm)) { return $false }
|
||||
}
|
||||
|
||||
return Install-NodeWithFnm
|
||||
}
|
||||
|
||||
function Install-Tool {
|
||||
if (-not (Ensure-NodeEnvironment)) {
|
||||
return $false
|
||||
}
|
||||
|
||||
Write-Info "使用 npm 安装 $ToolName..."
|
||||
Write-Host " 执行: npm install -g $ToolPackage" -ForegroundColor Gray
|
||||
|
||||
try {
|
||||
Invoke-Expression "npm install -g $ToolPackage"
|
||||
$exitCode = $LASTEXITCODE
|
||||
Refresh-Path
|
||||
|
||||
if ($exitCode -ne 0) {
|
||||
Write-Error "安装命令返回错误码: $exitCode"
|
||||
return $false
|
||||
}
|
||||
|
||||
if (Test-Command $ToolCommand) {
|
||||
Write-Success "$ToolName 安装成功!"
|
||||
return $true
|
||||
|
||||
@@ -19,6 +19,7 @@ CLAUDE_CONFIG_DIR="$HOME/.claude"
|
||||
CLAUDE_SETTINGS_FILE="$CLAUDE_CONFIG_DIR/settings.json"
|
||||
TOOL_COMMAND="claude"
|
||||
TOOL_NAME="Claude Code"
|
||||
TOOL_PACKAGE="@anthropic-ai/claude-code"
|
||||
|
||||
# ========== Shell 环境变量配置 ==========
|
||||
get_shell_rc() {
|
||||
@@ -82,14 +83,115 @@ print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# ========== Node.js 环境检测 ==========
|
||||
get_node_version() {
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
node --version 2>/dev/null | sed 's/v//'
|
||||
fi
|
||||
}
|
||||
|
||||
get_node_major_version() {
|
||||
local version
|
||||
version=$(get_node_version)
|
||||
if [ -n "$version" ]; then
|
||||
echo "$version" | cut -d. -f1
|
||||
fi
|
||||
}
|
||||
|
||||
install_fnm() {
|
||||
echo ""
|
||||
print_info "正在安装 fnm (Fast Node Manager)..."
|
||||
|
||||
if curl -fsSL https://fnm.vercel.app/install | bash; then
|
||||
export PATH="$HOME/.local/share/fnm:$PATH"
|
||||
if [ -f "$HOME/.local/share/fnm/fnm" ]; then
|
||||
eval "$(~/.local/share/fnm/fnm env)"
|
||||
fi
|
||||
|
||||
if command -v fnm >/dev/null 2>&1; then
|
||||
print_success "fnm 安装成功!"
|
||||
return 0
|
||||
else
|
||||
print_warning "fnm 可能已安装,但需要重新打开终端才能生效"
|
||||
print_info "请重新打开终端后再运行此脚本"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "fnm 安装失败"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
install_node_with_fnm() {
|
||||
print_info "使用 fnm 安装 Node.js 24.x..."
|
||||
|
||||
if fnm install 24 && fnm use 24 && fnm default 24; then
|
||||
eval "$(fnm env)"
|
||||
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
local version
|
||||
version=$(get_node_version)
|
||||
print_success "Node.js v$version 安装成功!"
|
||||
return 0
|
||||
else
|
||||
print_warning "Node.js 可能已安装,但需要重新打开终端才能生效"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "Node.js 安装失败"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_node_environment() {
|
||||
local version major
|
||||
|
||||
version=$(get_node_version)
|
||||
if [ -n "$version" ]; then
|
||||
major=$(get_node_major_version)
|
||||
print_info "检测到 Node.js v$version"
|
||||
|
||||
if [ "$major" -lt 20 ]; then
|
||||
print_warning "Node.js 版本过低 (需要 >= 20.x)"
|
||||
|
||||
read -p "是否使用 fnm 安装 Node.js 24.x? (Y/n): " -r
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
print_error "Node.js 版本不满足要求,请手动升级后重试"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! command -v fnm >/dev/null 2>&1; then
|
||||
install_fnm || return 1
|
||||
fi
|
||||
|
||||
install_node_with_fnm || return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_warning "未检测到 Node.js"
|
||||
print_info "将使用 fnm 安装 Node.js 24.x"
|
||||
|
||||
read -p "是否继续? (Y/n): " -r
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! command -v fnm >/dev/null 2>&1; then
|
||||
install_fnm || return 1
|
||||
fi
|
||||
|
||||
install_node_with_fnm || return 1
|
||||
}
|
||||
|
||||
install_tool() {
|
||||
print_info "使用官方安装脚本安装 $TOOL_NAME..."
|
||||
echo " 执行: curl -fsSL https://claude.ai/install.sh | bash"
|
||||
ensure_node_environment || return 1
|
||||
|
||||
if bash -c 'set -o pipefail; curl -fsSL https://claude.ai/install.sh | bash'; then
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
hash -r 2>/dev/null || true
|
||||
print_info "使用 npm 安装 $TOOL_NAME..."
|
||||
echo " 执行: npm install -g $TOOL_PACKAGE"
|
||||
|
||||
if npm install -g "$TOOL_PACKAGE"; then
|
||||
if command -v "$TOOL_COMMAND" >/dev/null 2>&1; then
|
||||
print_success "$TOOL_NAME 安装成功!"
|
||||
return 0
|
||||
|
||||
28
setup.ps1
28
setup.ps1
@@ -216,32 +216,7 @@ function Install-Tool {
|
||||
[hashtable]$Tool
|
||||
)
|
||||
|
||||
if ($Tool.Command -eq "claude") {
|
||||
# Claude Code: 使用官方原生安装脚本
|
||||
Write-Info "使用官方安装脚本安装 $($Tool.Name)..."
|
||||
Write-Host " 执行: irm https://claude.ai/install.ps1 | iex" -ForegroundColor Gray
|
||||
|
||||
try {
|
||||
Invoke-Expression "& { $(Invoke-RestMethod https://claude.ai/install.ps1) }"
|
||||
Refresh-Path
|
||||
|
||||
if (Test-Command $Tool.Command) {
|
||||
Write-Success "$($Tool.Name) 安装成功!"
|
||||
return $true
|
||||
}
|
||||
else {
|
||||
Write-Warning "$($Tool.Name) 可能已安装,但需要重新打开终端才能生效"
|
||||
$continue = Read-Host "是否继续进行配置? (Y/n)"
|
||||
return ($continue -ne "n" -and $continue -ne "N")
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "安装失败: $($_.Exception.Message)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Gemini CLI / Codex: 使用 npm 安装 (需要 Node.js)
|
||||
# 所有工具统一使用 npm 安装 (需要 Node.js)
|
||||
if (-not (Ensure-NodeEnvironment)) {
|
||||
return $false
|
||||
}
|
||||
@@ -274,7 +249,6 @@ function Install-Tool {
|
||||
Write-Error "安装失败: $($_.Exception.Message)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# ========== 远程配置脚本调用 ==========
|
||||
|
||||
25
setup.sh
25
setup.sh
@@ -365,27 +365,7 @@ install_tool() {
|
||||
|
||||
info "安装 $tool_name..."
|
||||
|
||||
if [ "$tool_num" = "1" ]; then
|
||||
# Claude Code: 使用官方原生安装脚本
|
||||
local install_cmd="curl -fsSL https://claude.ai/install.sh | bash"
|
||||
echo -e " 执行: ${CYAN}$install_cmd${NC}"
|
||||
if bash -c 'set -o pipefail; curl -fsSL https://claude.ai/install.sh | bash'; then
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
hash -r 2>/dev/null || true
|
||||
local tool_cmd=$(get_tool_cmd "$tool_num")
|
||||
if command -v "$tool_cmd" >/dev/null 2>&1; then
|
||||
success "$tool_name 安装成功!"
|
||||
return 0
|
||||
else
|
||||
warning "$tool_name 可能已安装,但需要重新打开终端才能生效"
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
error "$tool_name 安装失败 (请检查 https://claude.ai 是否可达)"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
# Gemini CLI / Codex: 使用 npm 安装 (需要 Node.js)
|
||||
# 所有工具统一使用 npm 安装 (需要 Node.js)
|
||||
if ! ensure_node_environment; then
|
||||
return 1
|
||||
fi
|
||||
@@ -405,7 +385,6 @@ install_tool() {
|
||||
error "$tool_name 安装失败"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# ========== 配置工具 ==========
|
||||
@@ -559,7 +538,7 @@ main() {
|
||||
info "API 密钥: ${api_key:0:8}..."
|
||||
echo ""
|
||||
|
||||
# Node.js 环境检查已移至 install_tool 内部 (仅 Gemini CLI / Codex 需要)
|
||||
# Node.js 环境检查已移至 install_tool 内部 (三个工具均需要)
|
||||
|
||||
echo ""
|
||||
echo -e "${CYAN}========================================${NC}"
|
||||
|
||||
Reference in New Issue
Block a user