From 3239b907713e4a9338533bd488ffef168d78e3b3 Mon Sep 17 00:00:00 2001 From: joywayer Date: Sat, 2 May 2026 10:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E7=BD=B2=20claude?= =?UTF-8?q?=20+=20deepseek=20sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- claude/setup-claude-deepseek.sh | 111 ++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100755 claude/setup-claude-deepseek.sh diff --git a/claude/setup-claude-deepseek.sh b/claude/setup-claude-deepseek.sh new file mode 100755 index 0000000..55906be --- /dev/null +++ b/claude/setup-claude-deepseek.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash +# ============================================================= +# Claude Code + DeepSeek 一键配置脚本 (macOS) +# 用法:在终端中执行此脚本 (bash setup-claude-deepseek.sh) +# ============================================================= + +# 颜色定义 +CYAN='\033[0;36m' +YELLOW='\033[1;33m' +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +DEEPSEEK_API_KEY="sk-a7e8782b1d5547a692ef2efec55b44f2" +DEEPSEEK_BASE_URL="https://api.deepseek.com/anthropic" +DEEPSEEK_MODEL="deepseek-v4-pro" + +echo -e "${CYAN}=== Claude Code + DeepSeek 配置开始 (macOS) ===${NC}" + +# ── 1. 检查 Node.js ────────────────────────────────────────── +echo -e "\n${YELLOW}[1/4] 检查 Node.js...${NC}" +if ! command -v node &> /dev/null; then + echo -e "${YELLOW}未找到 Node.js,准备自动安装...${NC}" + if ! command -v brew &> /dev/null; then + echo -e "${YELLOW}未找到 Homebrew,正在为您安装 Homebrew...${NC}" + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + # 初始化 brew 环境变量以防当前终端 session 暂未更新 + if [ -x "/opt/homebrew/bin/brew" ]; then + eval "$(/opt/homebrew/bin/brew shellenv)" + elif [ -x "/usr/local/bin/brew" ]; then + eval "$(/usr/local/bin/brew shellenv)" + fi + fi + echo -e "${YELLOW}正在通过 Homebrew 安装 Node.js...${NC}" + export HOMEBREW_NO_AUTO_UPDATE=1 + brew install node + if [ $? -ne 0 ]; then + echo -e "${RED}Node.js 自动安装失败,请手动安装后重试。${NC}" + exit 1 + fi +fi +echo -e "${GREEN}Node.js $(node --version) 已安装${NC}" + +# ── 2. 安装 Claude Code ─────────────────────────────────────── +echo -e "\n${YELLOW}[2/4] 安装 Claude Code...${NC}" +if command -v claude &> /dev/null; then + echo -e "${GREEN}Claude Code 已安装:$(claude --version 2>&1)${NC}" +else + npm install -g @anthropic-ai/claude-code + if [ $? -ne 0 ]; then + echo -e "${RED}安装失败,请检查 npm 网络和权限${NC}" + exit 1 + fi + echo -e "${GREEN}Claude Code 安装成功${NC}" +fi + +# ── 3. 写入 ~/.claude/settings.json(仅保留 model) ────────── +echo -e "\n${YELLOW}[3/4] 配置 ~/.claude/settings.json...${NC}" +CLAUDE_DIR="$HOME/.claude" +mkdir -p "$CLAUDE_DIR" +cat < "$CLAUDE_DIR/settings.json" +{ + "model": "$DEEPSEEK_MODEL" +} +EOF +echo -e "${GREEN}已写入 $CLAUDE_DIR/settings.json${NC}" + +# ── 4. 设置环境变量 profile (支持 bash 和 zsh) ──────────────── +echo -e "\n${YELLOW}[4/4] 设置环境变量...${NC}" + +PROFILE_CONTENT=$(cat </dev/null; then + echo -e "${GREEN}环境变量已存在于 $PROFILE_FILE,建议手动检查以防重复${NC}" +else + echo -e "\n$PROFILE_CONTENT" >> "$PROFILE_FILE" + echo -e "${GREEN}已追加环境变量到:$PROFILE_FILE${NC}" +fi + +# ── 验证连接 ────────────────────────────────────────────────── +echo -e "\n${CYAN}=== 验证连接 ===${NC}" +export ANTHROPIC_BASE_URL="$DEEPSEEK_BASE_URL" +export ANTHROPIC_AUTH_TOKEN="$DEEPSEEK_API_KEY" +export ANTHROPIC_MODEL="$DEEPSEEK_MODEL" + +# 运行 claude 进行简短测试 +echo -e "${YELLOW}正在尝试连接 api...${NC}" +result=$(claude -p "say hi" 2>&1) +if [ $? -eq 0 ]; then + echo -e "${GREEN}连接成功:$result${NC}" +else + echo -e "${RED}连接失败:$result${NC}" +fi + +echo -e "\n${CYAN}=== 配置完成!请执行 'source $PROFILE_FILE' 或新开终端后直接运行 claude ===${NC}" \ No newline at end of file