#!/bin/bash
# Docker 和服务部署脚本

echo "[1/4] 安装 Docker..."
curl -fsSL https://get.docker.com | sh
systemctl enable docker
systemctl start docker

echo "[2/4] 验证 Docker..."
docker --version

echo "[3/4] 部署 Gitea..."
mkdir -p /opt/gitea
cd /opt/gitea
cat > docker-compose.yml << 'EOF'
version: "3.8"
services:
  gitea:
    image: gitea/gitea:latest
    container_name: gitea
    restart: unless-stopped
    ports:
      - "127.0.0.1:3000:3000"
      - "127.0.0.1:2222:22"
    volumes:
      - gitea-data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=sqlite3
      - GITEA__server__DOMAIN=tksea.top
      - GITEA__server__ROOT_URL=https://tksea.top/
volumes:
  gitea-data:
EOF
docker compose up -d

echo "[4/4] 部署 Sub2API..."
mkdir -p /opt/sub2api/deploy
cd /opt/sub2api/deploy
curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/docker-deploy.sh | bash

echo ""
echo "========================================"
echo "部署完成!"
echo "========================================"
echo "检查状态: docker ps"
echo "访问: https://tksea.top (Gitea)"
echo "访问: https://api.tksea.top (Sub2API)"
echo "========================================"