#!/bin/bash # AntiCaptcha 安装脚本 set -e echo "=========================================" echo " AntiCaptcha 安装脚本" echo "=========================================" # 检查系统 if [ ! -f /etc/os-release ]; then echo "无法检测操作系统" exit 1 fi . /etc/os-release # 安装依赖 install_deps() { echo "正在安装依赖..." case "$ID" in ubuntu|debian) apt update apt install -y libopencv-dev libonnxruntime-dev ;; centos|rhel|fedora) yum install -y opencv-devel onnxruntime ;; alpine) apk add --no-cache opencv onnxruntime ;; *) echo "不支持的系统: $ID" exit 1 ;; esac } # 安装 Go install_go() { if command -v go &> /dev/null; then echo "Go 已安装: $(go version)" return fi echo "正在安装 Go..." wget -q https://go.dev/dl/go1.22.5.linux-amd64.tar.gz tar -C /usr/local -xzf go1.22.5.linux-amd64.tar.gz rm go1.22.5.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc } # 构建项目 build() { echo "正在构建项目..." go mod download CGO_ENABLED=1 go build -o anticaptcha ./cmd/server } # 创建 systemd 服务 create_service() { echo "正在创建 systemd 服务..." cat > /etc/systemd/system/anticaptcha.service << EOF [Unit] Description=AntiCaptcha Service After=network.target [Service] Type=simple ExecStart=/opt/anticaptcha/anticaptcha WorkingDirectory=/opt/anticaptcha Restart=always RestartSec=5 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable anticaptcha } # 主流程 main() { install_deps install_go build echo "" echo "=========================================" echo " 安装完成!" echo "=========================================" echo "" echo "运行方式:" echo " ./anticaptcha" echo "" echo "或创建 systemd 服务后:" echo " systemctl start anticaptcha" echo "" } main "$@"