#!/bin/bash
# 部署 server_ip DNS 自动配置逻辑（需 root）
set -e
BASE="$(cd "$(dirname "$0")" && pwd)"
PATCH="$BASE/patches"

cp -f "$PATCH/application/extra/cloudflare.php" "$BASE/application/extra/cloudflare.php"
cp -f "$PATCH/application/common/service/CloudflareService.php" "$BASE/application/common/service/CloudflareService.php"
cp -f "$PATCH/application/admin/lang/zh-cn/domain.php" "$BASE/application/admin/lang/zh-cn/domain.php"
chown www:www "$BASE/application/extra/cloudflare.php" "$BASE/application/common/service/CloudflareService.php" "$BASE/application/admin/lang/zh-cn/domain.php"
php -l "$BASE/application/common/service/CloudflareService.php"
echo "部署完成。请确认 .env 中 cloudflare.server_ip 已填写。"
echo "Cloudflare API Token 需包含权限：Zone DNS Edit、Zone Settings Edit（用于 SSL Flexible 与 Always Use HTTPS）。"
