#!/bin/bash # 1. 檢查並安裝必要工具 echo "正在檢查環境並安裝必要工具..." if [ -f /etc/debian_version ]; then apt-get update && apt-get install -y curl openssl qrencode elif [ -f /etc/redhat-release ]; then yum install -y curl openssl qrencode fi # 2. 執行官方 Xray 安裝腳本 echo "正在安裝 Xray..." bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install # 3. 收集用戶自定義參數 read -p "請輸入服務監聽端口 (預設 28679): " PORT PORT=${PORT:-28679} read -p "請輸入目標域名 (dest, 預設 login.pondus.de): " DEST_DOMAIN DEST_DOMAIN=${DEST_DOMAIN:-login.pondus.de} # 4. 生成 X25519 密鑰與 UUID echo "正在生成 X25519 密鑰與配置資訊..." KEYS=$(/usr/local/bin/xray x25519) PRIVATE_KEY=$(echo "$KEYS" | grep "Private key:" | cut -d ' ' -f 3) PUBLIC_KEY=$(echo "$KEYS" | grep "Public key:" | cut -d ' ' -f 3) UUID=$(cat /proc/sys/kernel/random/uuid) SHORT_ID=$(openssl rand -hex 4) # 5. 寫入設定檔 cat << JSON > /usr/local/etc/xray/config.json { "log": { "loglevel": "warning" }, "inbounds": [ { "tag": "dokodemo-in", "port": $PORT, "protocol": "dokodemo-door", "settings": { "address": "127.0.0.1", "port": 4431, "network": "tcp" }, "sniffing": { "enabled": true, "destOverride": ["tls"], "routeOnly": true } }, { "listen": "127.0.0.1", "port": 4431, "protocol": "vless", "settings": { "clients": [{ "id": "$UUID", "flow": "xtls-rprx-vision" }], "decryption": "none" }, "streamSettings": { "network": "tcp", "security": "reality", "realitySettings": { "show": false, "dest": "$DEST_DOMAIN:443", "xver": 0, "serverNames": ["$DEST_DOMAIN"], "privateKey": "$PRIVATE_KEY", "shortIds": ["$SHORT_ID"] } }, "sniffing": { "enabled": true, "destOverride": ["http", "tls", "quic"], "routeOnly": true } } ], "outbounds": [ { "protocol": "freedom", "tag": "direct" }, { "protocol": "blackhole", "tag": "block" } ], "routing": { "rules": [ { "type": "field", "inboundTag": ["dokodemo-in"], "domain": ["$DEST_DOMAIN"], "outboundTag": "direct" }, { "type": "field", "inboundTag": ["dokodemo-in"], "outboundTag": "block" } ] } } JSON # 6. 重啟服務 systemctl restart xray systemctl enable xray # 7. 導出資訊與 QR Code IP=$(curl -4 -s ifconfig.me) VLESS_LINK="vless://$UUID@$IP:$PORT?encryption=none&flow=xtls-rprx-vision&security=reality&sni=$DEST_DOMAIN&fp=chrome&pbk=$PUBLIC_KEY&sid=$SHORT_ID#Xray_Reality" echo "" echo "-------------------------------------------" echo "✅ 安裝與設定完成!" echo "-------------------------------------------" echo "🔗 您的客戶端連結:" echo "$VLESS_LINK" echo "-------------------------------------------" echo "📱 掃描下方 QR Code 匯入:" echo "" qrencode -t ANSIUTF8 "$VLESS_LINK" echo "-------------------------------------------"