Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
124 lines
3.8 KiB
Bash
124 lines
3.8 KiB
Bash
#!/usr/bin/env bash
|
||
# Edge VPS helper for physical deploy: write Caddy site → WG upstream, reload Caddy.
|
||
# Does NOT touch other Caddy sites, sing-box, or Docker stacks.
|
||
#
|
||
# Usage on overseas VPS (root):
|
||
# bash scripts/bootstrap_physical_edge.sh
|
||
# DOMAIN=dy.example.com WG_UPSTREAM_IP=10.8.0.2 bash scripts/bootstrap_physical_edge.sh
|
||
set -euo pipefail
|
||
|
||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||
# shellcheck disable=SC1091
|
||
source "$ROOT/scripts/lib/install_common.sh"
|
||
require_root
|
||
load_install_env_files
|
||
|
||
log() { printf '\n[%s] %s\n' "$(date '+%F %T')" "$*"; }
|
||
die() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
|
||
|
||
if [[ -z "${DOMAIN:-}" || -z "${WG_UPSTREAM_IP:-}" ]]; then
|
||
echo "=== 物理机边缘(Caddy → WireGuard)向导 ==="
|
||
ask DOMAIN "站点域名(DNS 已指向本 VPS)"
|
||
ask WG_UPSTREAM_IP "物理机 WG IP" "10.8.0.2"
|
||
ask WEB_PORT "上游 Next 端口" "4015"
|
||
ask API_PORT "上游 API 端口" "8014"
|
||
ask PB_PORT "上游 PB 端口" "8092"
|
||
ask S3_PORT "上游 S3 端口" "8333"
|
||
ask S3_BUCKET "S3 bucket 路径前缀" "douyin-covers"
|
||
ask CADDY_SITES_DIR "Caddy sites 目录" "/etc/caddy/sites"
|
||
ask_yn CADDY_RELOAD "写完后 reload Caddy?" "y"
|
||
fi
|
||
|
||
DOMAIN="${DOMAIN:?}"
|
||
WG_UPSTREAM_IP="${WG_UPSTREAM_IP:?}"
|
||
WEB_PORT="${WEB_PORT:-4015}"
|
||
API_PORT="${API_PORT:-8014}"
|
||
PB_PORT="${PB_PORT:-8092}"
|
||
S3_PORT="${S3_PORT:-8333}"
|
||
S3_BUCKET="${S3_BUCKET:-douyin-covers}"
|
||
CADDY_SITES_DIR="${CADDY_SITES_DIR:-/etc/caddy/sites}"
|
||
CADDY_RELOAD="${CADDY_RELOAD:-1}"
|
||
SITE_FILE="${CADDY_SITES_DIR}/${DOMAIN}.caddy"
|
||
|
||
command -v caddy >/dev/null || die "caddy not found"
|
||
[[ -d "$CADDY_SITES_DIR" ]] || die "missing $CADDY_SITES_DIR — create it and import from main Caddyfile first"
|
||
|
||
mkdir -p "$CADDY_SITES_DIR"
|
||
if [[ -f "$SITE_FILE" ]]; then
|
||
cp -a "$SITE_FILE" "${SITE_FILE}.bak.$(date +%s)"
|
||
log "backed up existing $SITE_FILE"
|
||
fi
|
||
|
||
cat >"$SITE_FILE" <<EOF
|
||
# douyinWEB physical edge — generated $(date -u '+%F %T') UTC
|
||
# Upstream guest: ${WG_UPSTREAM_IP}
|
||
${DOMAIN} {
|
||
encode gzip
|
||
request_body { max_size 200MB }
|
||
|
||
handle /api/* {
|
||
reverse_proxy ${WG_UPSTREAM_IP}:${API_PORT} {
|
||
header_up Host {host}
|
||
}
|
||
}
|
||
handle /covers/* {
|
||
reverse_proxy ${WG_UPSTREAM_IP}:${API_PORT} {
|
||
header_up Host {host}
|
||
}
|
||
}
|
||
handle /_/* {
|
||
reverse_proxy ${WG_UPSTREAM_IP}:${PB_PORT} {
|
||
header_up Host {host}
|
||
}
|
||
}
|
||
handle /${S3_BUCKET}/* {
|
||
reverse_proxy ${WG_UPSTREAM_IP}:${S3_PORT} {
|
||
header_up Host {host}
|
||
}
|
||
}
|
||
handle /shellcrash-ui {
|
||
redir /shellcrash-ui/ 308
|
||
}
|
||
handle_path /shellcrash-ui/* {
|
||
reverse_proxy ${WG_UPSTREAM_IP}:9999 {
|
||
header_up Host {host}
|
||
header_up X-Forwarded-Proto {scheme}
|
||
}
|
||
}
|
||
# Zashboard: /ui without slash must redirect (browsers often open /ui#/… → blank)
|
||
@ui_noslash {
|
||
path /ui
|
||
not path /ui/
|
||
not path /ui/*
|
||
}
|
||
redir @ui_noslash /ui/ 308
|
||
@clash path /ui/ /ui/* /version /proxies /proxies/* /configs /configs/* /rules /rules/* /connections /connections/* /providers /providers/* /cache /cache/* /dns /dns/* /debug /debug/* /traffic /logs /memory /restart /upgrade /upgrade/* /group /group/* /script /script/* /fakeip /fakeip/* /endpoint /endpoint/* /runtime /runtime/* /meta /meta/* /schema /schema/* /flushfakeip /externaloverride /externaloverride/* /storage /storage/*
|
||
handle @clash {
|
||
reverse_proxy ${WG_UPSTREAM_IP}:9999 {
|
||
header_up Host {host}
|
||
}
|
||
}
|
||
handle {
|
||
reverse_proxy ${WG_UPSTREAM_IP}:${WEB_PORT} {
|
||
header_up Host {host}
|
||
}
|
||
}
|
||
}
|
||
EOF
|
||
|
||
log "wrote $SITE_FILE"
|
||
caddy validate --config /etc/caddy/Caddyfile
|
||
|
||
if [[ "$CADDY_RELOAD" == "1" ]]; then
|
||
systemctl reload caddy
|
||
log "caddy reloaded (not restarted)"
|
||
else
|
||
log "skipped reload — run: systemctl reload caddy"
|
||
fi
|
||
|
||
echo
|
||
echo "Check new site: curl -sS -o /dev/null -w '%{http_code}\\n' https://${DOMAIN}/api/health"
|
||
echo "Check old sites still healthy before leaving."
|
||
echo "WireGuard: ensure AllowedIPs is overlay-only (e.g. 10.8.0.0/24), never 0.0.0.0/0."
|
||
log "DONE"
|