Skip to content

Commit da0e9bc

Browse files
committed
fix(tutorial): fix bash install script for regional compatibility
- Add npm fallback when official Claude Code install script is blocked - Replace hardcoded ~/.zshrc with auto-detected shell config file - Separate interactive coding-helper step from automated script - Add clear instructions to manually source config file - Fix set -e issue with source command in wrong shell - Add helpful error messages for missing API key placeholder
1 parent 1daaf1a commit da0e9bc

1 file changed

Lines changed: 70 additions & 30 deletions

File tree

playground/apps/desktop/public/skills/install-claude-code-glm5-deepseek-v4.md

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -160,47 +160,72 @@ claude
160160

161161
## 一次性安装脚本(macOS / Linux)
162162

163-
以下脚本可一次性完成 Claude Code 安装 + GLM 5.1 / DeepSeek V4 配置
163+
以下脚本可自动完成 Claude Code 安装与 DeepSeek V4 配置(GLM 5.1 需单独运行交互式配置)
164164

165165
```bash
166166
#!/bin/bash
167167
set -e
168168

169-
echo "🚀 开始安装 Claude Code + GLM 5.1 + DeepSeek V4..."
169+
echo "🚀 开始安装 Claude Code + DeepSeek V4..."
170170

171-
# 1. 安装 Claude Code
171+
# ─── 1. 安装 Claude Code ─────────────────────────────────
172172
if ! command -v claude &> /dev/null; then
173-
echo "📦 安装 Claude Code..."
174-
curl -fsSL https://claude.ai/install.sh | bash
173+
echo "📦 尝试安装 Claude Code..."
174+
175+
# 方式一:官方安装脚本(部分地区可能无法访问)
176+
if curl -fsSL https://claude.ai/install.sh -o /tmp/claude-install.sh 2>/dev/null && \
177+
grep -q "npm install" /tmp/claude-install.sh 2>/dev/null; then
178+
bash /tmp/claude-install.sh
179+
else
180+
# 方式二:直接通过 npm 安装(备用方案)
181+
echo " 官方脚本不可用,使用 npm 安装..."
182+
npm install -g @anthropic-ai/claude-code
183+
fi
184+
185+
if ! command -v claude &> /dev/null; then
186+
echo "❌ Claude Code 安装失败"
187+
echo " 请手动运行: npm install -g @anthropic-ai/claude-code"
188+
exit 1
189+
fi
190+
echo "✅ Claude Code 安装完成"
175191
else
176-
echo "✅ Claude Code 已安装"
192+
echo "✅ Claude Code 已安装: $(claude --version 2>/dev/null || echo 'unknown')"
177193
fi
178194

179-
# 2. 配置 GLM 5.1(交互式,需手动输入 API Key)
180-
echo ""
181-
echo "🧠 启动 Coding Tool Helper 配置 GLM 5.1..."
182-
echo " 请按提示选择语言、Plan 套餐、输入 API Key 并勾选 Claude Code"
183-
npx @z_ai/coding-helper
184-
185-
# 3. 配置 DeepSeek V4(需替换 <YOUR_DEEPSEEK_API_KEY>)
195+
# ─── 2. 配置 DeepSeek V4 ─────────────────────────────────
186196
echo ""
187197
echo "⚙️ 配置 DeepSeek V4 环境变量..."
188198

199+
# 请替换为你的真实 DeepSeek API Key
189200
deepseek_key="<YOUR_DEEPSEEK_API_KEY>"
190201

191202
if [ "$deepseek_key" = "<YOUR_DEEPSEEK_API_KEY>" ]; then
192-
echo "⚠️ 请编辑脚本,将 <YOUR_DEEPSEEK_API_KEY> 替换为你的真实 DeepSeek API Key"
203+
echo "❌ 错误: 请将脚本中的 <YOUR_DEEPSEEK_API_KEY> 替换为你的真实 DeepSeek API Key"
204+
echo " 获取地址: https://platform.deepseek.com/"
193205
exit 1
194206
fi
195207

196-
# 写入 ~/.zshrc(如使用 bash 请改为 ~/.bashrc)
197-
shell_rc="$HOME/.zshrc"
208+
# 自动检测 Shell 配置文件
209+
if [ -n "$ZSH_VERSION" ] || [ "$(basename "$SHELL")" = "zsh" ]; then
210+
shell_rc="$HOME/.zshrc"
211+
elif [ -n "$BASH_VERSION" ] || [ "$(basename "$SHELL")" = "bash" ]; then
212+
shell_rc="$HOME/.bashrc"
213+
[ ! -f "$shell_rc" ] && shell_rc="$HOME/.bash_profile"
214+
else
215+
shell_rc="$HOME/.profile"
216+
fi
217+
218+
# 确保配置文件存在
219+
[ ! -f "$shell_rc" ] && touch "$shell_rc"
198220

199221
append_env() {
200222
local key="$1"
201223
local val="$2"
202-
if ! grep -q "^export $key=" "$shell_rc" 2>/dev/null; then
224+
if ! grep -qF "export $key=" "$shell_rc" 2>/dev/null; then
203225
echo "export $key=\"$val\"" >> "$shell_rc"
226+
echo " ✓ 已添加: $key"
227+
else
228+
echo " ⏭ 已存在: $key (跳过)"
204229
fi
205230
}
206231

@@ -213,32 +238,47 @@ append_env "ANTHROPIC_DEFAULT_HAIKU_MODEL" "deepseek-v4-flash"
213238
append_env "CLAUDE_CODE_SUBAGENT_MODEL" "deepseek-v4-flash"
214239
append_env "CLAUDE_CODE_EFFORT_LEVEL" "max"
215240

216-
source "$shell_rc"
217-
241+
# ─── 3. 输出结果 ─────────────────────────────────────────
218242
echo ""
219-
echo "安装完成!"
243+
echo "DeepSeek V4 配置已写入: $shell_rc"
220244
echo ""
221-
echo "📋 验证命令:"
245+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
246+
echo "⚠️ 重要: 请执行以下命令使环境变量生效:"
247+
echo ""
248+
echo " source $shell_rc"
249+
echo ""
250+
echo " 或重新打开终端窗口"
251+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
252+
echo ""
253+
echo "📋 验证命令:"
222254
echo " claude --version"
223255
echo " cd /path/to/project && claude"
224256
echo ""
225-
echo "💡 模型切换提示:"
226-
echo " - GLM 5.1:通过 coding-helper 重新加载套餐"
227-
echo " - DeepSeek V4:确保环境变量已设置,直接启动 claude"
257+
258+
# ─── 4. GLM 5.1 配置提示 ─────────────────────────────────
259+
echo "🧠 GLM 5.1 配置(可选):"
260+
echo " 如需使用 GLM 5.1,请单独运行交互式配置工具:"
261+
echo ""
262+
echo " npx @z_ai/coding-helper"
263+
echo ""
264+
echo " 按提示选择语言 → Plan 套餐 → 输入 API Key → 勾选 Claude Code"
228265
echo ""
229-
```
266+
230267

231268
**使用方法**
232269

233-
1. 复制脚本保存为 `install-cc-glm-ds.sh`
234-
2. `<YOUR_DEEPSEEK_API_KEY>` 替换为你的真实 Key
235-
3. 执行
270+
1. 复制上方脚本内容,保存为 `install-cc-ds.sh`
271+
2. 将脚本中的 `<YOUR_DEEPSEEK_API_KEY>` 替换为你的真实 Key
272+
3. 赋予执行权限并运行
236273

237274
```bash
238-
chmod +x install-cc-glm-ds.sh
239-
./install-cc-glm-ds.sh
275+
chmod +x install-cc-ds.sh
276+
./install-cc-ds.sh
240277
```
241278

279+
4. 根据脚本提示,运行 `source ~/.zshrc`(或对应的配置文件)使环境变量生效
280+
5. 如需配置 GLM 5.1,单独运行 `npx @z_ai/coding-helper`
281+
242282
---
243283

244284
## 模型切换速查表

0 commit comments

Comments
 (0)