c9895133cb
sing-box Hy2 stays on 8443+; port 443 VLESS uses Xray which pairs reliably with v2rayN/Xray-core clients. Co-authored-by: Cursor <cursoragent@cursor.com>
72 lines
2.6 KiB
Bash
72 lines
2.6 KiB
Bash
#!/usr/bin/env bash
|
||
# 核对 Reality 密钥是否一致,并验证 Xray 配置
|
||
set -euo pipefail
|
||
|
||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||
ENV_FILE="${ROOT}/.env"
|
||
XRAY_CFG="/usr/local/etc/xray/config.json"
|
||
SB_CFG="/etc/sing-box/config.json"
|
||
|
||
[[ -f "$ENV_FILE" ]] || { echo "缺少 $ENV_FILE"; exit 1; }
|
||
# shellcheck disable=SC1090
|
||
source "$ENV_FILE"
|
||
|
||
echo "========== .env =========="
|
||
grep ^REALITY_ "$ENV_FILE" | grep -v PRIVATE || true
|
||
echo "REALITY_PRIVATE_KEY=***(已隐藏)"
|
||
|
||
if command -v xray &>/dev/null && [[ -f "$XRAY_CFG" ]]; then
|
||
echo ""
|
||
echo "========== Xray config.json =========="
|
||
ENV_FILE="$ENV_FILE" XRAY_CFG="$XRAY_CFG" python3 - <<'PY'
|
||
import json, os
|
||
from pathlib import Path
|
||
env = {}
|
||
for line in Path(os.environ["ENV_FILE"]).read_text().splitlines():
|
||
line = line.strip()
|
||
if not line or line.startswith("#") or "=" not in line:
|
||
continue
|
||
k, _, v = line.partition("=")
|
||
env[k.strip()] = v.strip()
|
||
cfg = json.load(open(os.environ["XRAY_CFG"]))
|
||
rs = cfg["inbounds"][0]["streamSettings"]["realitySettings"]
|
||
pk = rs["privateKey"]
|
||
print("privateKey:", pk[:8] + "..." if pk else "(empty)")
|
||
print("shortIds:", rs.get("shortIds"))
|
||
print("serverNames:", rs.get("serverNames"))
|
||
print("clients:", len(cfg["inbounds"][0]["settings"]["clients"]))
|
||
match = pk == env.get("REALITY_PRIVATE_KEY", "")
|
||
print("privateKey 与 .env 一致:", "是" if match else "否 ← 需运行 render-xray.py")
|
||
PY
|
||
echo ""
|
||
echo "========== xray -test =========="
|
||
xray run -test -c "$XRAY_CFG"
|
||
else
|
||
echo ""
|
||
echo "Xray 未安装或配置不存在。VLESS Reality 需 Xray:"
|
||
echo " bash -c \"\$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"
|
||
echo " python3 ${ROOT}/scripts/render-xray.py"
|
||
fi
|
||
|
||
if [[ -f "$SB_CFG" ]] && grep -q vless-reality "$SB_CFG" 2>/dev/null; then
|
||
echo ""
|
||
echo "[!] sing-box 仍含 vless-reality inbound,会与 Xray 争抢 443。"
|
||
echo " 请运行: python3 ${ROOT}/scripts/render-server.py && systemctl restart sing-box"
|
||
fi
|
||
|
||
if command -v xray &>/dev/null && [[ -n "${REALITY_PRIVATE_KEY:-}" ]]; then
|
||
echo ""
|
||
echo "========== 公钥配对 =========="
|
||
DERIVED="$(xray x25519 -i "$REALITY_PRIVATE_KEY" 2>/dev/null | awk '/Public key/ {print $3}')"
|
||
if [[ -n "$DERIVED" ]]; then
|
||
if [[ "$DERIVED" == "${REALITY_PUBLIC_KEY:-}" ]]; then
|
||
echo "公钥与私钥配对: 是"
|
||
else
|
||
echo "公钥与私钥配对: 否"
|
||
echo " .env PUBLIC: ${REALITY_PUBLIC_KEY:-}"
|
||
echo " 推导 PUBLIC: $DERIVED"
|
||
echo " 请重新运行 generate-keys.sh 并 render-xray.py"
|
||
fi
|
||
fi
|
||
fi
|