AIClient-2-API/install-and-run.sh
hex2077 3a54404e0e fix(oauth): 优化自动关联凭证逻辑以支持单个凭证关联
- 修改 autoLinkProviderConfigs 函数,增加 onlyCurrentCred 选项
- 当 onlyCurrentCred 为 true 时,仅关联当前生成的凭证文件
- 避免批量导入凭证时重复扫描所有配置文件
- 在 OAuth 回调中传递 credPath 参数,确保正确关联新凭证
- 统一 install-and-run 脚本中的包管理器检测逻辑
- 优化 Claude 提供商的 token 计数方法,提高准确性
2026-02-03 12:15:35 +08:00

106 lines
No EOL
2.6 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 设置中文环境
export LC_ALL=zh_CN.UTF-8
export LANG=zh_CN.UTF-8
echo "========================================"
echo " AI Client 2 API 快速安装启动脚本"
echo "========================================"
echo
# 处理参数
FORCE_PULL=0
for arg in "$@"; do
if [ "$arg" == "--pull" ]; then
FORCE_PULL=1
fi
done
# 检查Git并尝试pull
if [ $FORCE_PULL -eq 1 ]; then
echo "[更新] 正在从远程仓库拉取最新代码..."
if command -v git > /dev/null 2>&1; then
git pull
if [ $? -ne 0 ]; then
echo "[警告] Git pull 失败,请检查网络或手动处理冲突。"
else
echo "[成功] 代码已更新。"
fi
else
echo "[警告] 未检测到 Git跳过代码拉取。"
fi
fi
# 检查Node.js是否已安装
echo "[检查] 正在检查Node.js是否已安装..."
node --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "[错误] 未检测到Node.js请先安装Node.js"
echo "下载地址https://nodejs.org/"
echo "提示推荐安装LTS版本"
exit 1
fi
# 获取Node.js版本
NODE_VERSION=$(node --version 2>/dev/null)
echo "[成功] Node.js已安装版本: $NODE_VERSION"
# 检查npm是否可用
echo "[检查] 正在检查npm是否可用..."
npm --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "[错误] npm不可用请重新安装Node.js"
exit 1
fi
# 检查package.json是否存在
if [ ! -f "package.json" ]; then
echo "[错误] 未找到package.json文件"
echo "请确保在项目根目录下运行此脚本"
exit 1
fi
echo "[成功] 找到package.json文件"
# 检查 pnpm 是否安装
if command -v pnpm > /dev/null 2>&1; then
PKG_MANAGER=pnpm
else
PKG_MANAGER=npm
fi
echo "[安装] 正在使用 $PKG_MANAGER 安装/更新依赖..."
echo "这可能需要几分钟时间,请耐心等待..."
echo "正在执行: $PKG_MANAGER install..."
$PKG_MANAGER install
if [ $? -ne 0 ]; then
echo "[错误] 依赖安装失败"
echo "请检查网络连接或手动运行 '$PKG_MANAGER install'"
exit 1
fi
echo "[成功] 依赖安装/更新完成"
# 检查src目录和master.js是否存在
if [ ! -f "src/core/master.js" ]; then
echo "[错误] 未找到src/core/master.js文件"
exit 1
fi
echo "[成功] 项目文件检查完成"
# 启动应用程序
echo
echo "========================================"
echo " 启动AIClient2API服务器..."
echo "========================================"
echo
echo "服务器将在 http://localhost:3000 启动"
echo "访问 http://localhost:3000 查看管理界面"
echo "按 Ctrl+C 停止服务器"
echo
# 启动服务器
node src/core/master.js