Files
web-capture-api/install.sh
2026-07-07 13:23:36 +08:00

116 lines
2.8 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
# 一键安装脚本
set -e
echo "🚀 Web Capture API 安装脚本"
echo "================================"
echo ""
# 检测系统
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
else
echo "❌ 不支持的操作系统: $OSTYPE"
exit 1
fi
echo "📋 系统检测: $OS"
# 检查 Python
echo ""
echo "📦 检查 Python..."
if command -v python3.12 &> /dev/null; then
PYTHON=python3.12
elif command -v python3 &> /dev/null; then
PYTHON=python3
else
echo "❌ 未找到 Python 3请先安装 Python 3.10+"
exit 1
fi
echo "✅ 找到 Python: $($PYTHON --version)"
# 检查 pip
if ! $PYTHON -m pip --version &> /dev/null; then
echo "❌ 未找到 pip请先安装 pip"
exit 1
fi
# 检查 Node.js (用于 agent-browser)
echo ""
echo "📦 检查 Node.js..."
if command -v node &> /dev/null; then
NODE_VERSION=$(node --version)
echo "✅ 找到 Node.js: $NODE_VERSION"
HAS_NODE=true
else
echo "⚠️ 未找到 Node.js将跳过 agent-browser 安装"
HAS_NODE=false
fi
# 安装 Python 依赖
echo ""
echo "📥 安装 Python 依赖..."
$PYTHON -m pip install --user playwright flask flask-cors gunicorn
# 询问使用哪个后端
echo ""
echo "🔧 选择浏览器后端:"
echo " 1) Playwright (推荐,自动安装浏览器)"
echo " 2) agent-browser (高性能,需要手动安装浏览器依赖)"
read -p "请选择 [1/2]: " choice
case $choice in
1)
echo ""
echo "🌐 安装 Playwright 浏览器..."
$PYTHON -m playwright install chromium
if [ "$OS" == "linux" ]; then
echo ""
echo "⚠️ 如果浏览器启动失败,可能需要安装系统依赖:"
echo " $PYTHON -m playwright install-deps chromium"
fi
;;
2)
if [ "$HAS_NODE" = false ]; then
echo "❌ 安装 agent-browser 需要 Node.js"
exit 1
fi
echo ""
echo "🌐 安装 agent-browser..."
npm install -g agent-browser
if [ "$OS" == "linux" ]; then
echo ""
echo "⚠️ agent-browser 需要浏览器依赖,请运行:"
echo " agent-browser install --with-deps"
echo ""
echo "如果需要 sudo 权限,请运行:"
echo " sudo agent-browser install --with-deps"
else
agent-browser install
fi
;;
*)
echo "❌ 无效选择"
exit 1
;;
esac
# 完成
echo ""
echo "✅ 安装完成!"
echo ""
echo "🚀 启动服务:"
echo " cd $(pwd)"
echo " $PYTHON app.py"
echo ""
echo "📖 访问地址:"
echo " http://localhost:16025"
echo ""
echo "📚 API 文档:"
echo " http://localhost:16025/api"