├── LICENSE ├── README.md └── xray_2go.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 eooce 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xray-argo无交互一键四协议安装脚本 2 | 最好用的一键xray-argo脚本,一键四协议无交互安装脚本! 3 | * vless-grpc-reality | vless-xhttp-reality | vless-ws-tls(argo) | vmess-ws-tls(argo) 4 | 5 | ### 支持系统列表: 6 | >Debian 7 | >Ubuntu 8 | >CentOS 9 | >Alpine 10 | >Fedora 11 | >Alma-linux 12 | >Rocky-linux 13 | >Amazom-linux 14 | 15 | *** 16 | * xhttp目前支持的客户端较少,v2rayN或小火箭更新到新版内核才支持 17 | * 可选环境变量:UUID PORT CFIP CFPORT 自定义变量放脚本前面运行即可 18 | * NAT小鸡需带PORT变量运行并确保PORT之后的1个端口可用,或运行完后更改订阅端口和reality端口 19 | 20 | ``` 21 | bash <(curl -Ls https://github.com/eooce/xray-2go/raw/main/xray_2go.sh) 22 | ``` 23 | 24 | 带变量运行示例,修改为自己需要定义的参数 25 | ``` 26 | PORT=8888 CFIP=www.visa.com.tw CFPORT=8443 bash <(curl -Ls https://github.com/eooce/xray-2go/raw/main/xray_2go.sh) 27 | ``` 28 | 29 | # 免责声明 30 | * 本程序仅供学习了解, 非盈利目的,请于下载后 24 小时内删除, 不得用作任何商业用途, 文字、数据及图片均有所属版权, 如转载须注明来源。 31 | * 使用本程序必循遵守部署免责声明,使用本程序必循遵守部署服务器所在地、所在国家和用户所在国家的法律法规, 程序作者不对使用者任何不当行为负责。 32 | -------------------------------------------------------------------------------- /xray_2go.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 定义颜色 4 | re="\033[0m" 5 | red="\033[1;91m" 6 | green="\e[1;32m" 7 | yellow="\e[1;33m" 8 | purple="\e[1;35m" 9 | skyblue="\e[1;36m" 10 | red() { echo -e "\e[1;91m$1\033[0m"; } 11 | green() { echo -e "\e[1;32m$1\033[0m"; } 12 | yellow() { echo -e "\e[1;33m$1\033[0m"; } 13 | purple() { echo -e "\e[1;35m$1\033[0m"; } 14 | skyblue() { echo -e "\e[1;36m$1\033[0m"; } 15 | reading() { read -p "$(red "$1")" "$2"; } 16 | 17 | # 定义常量 18 | server_name="xray" 19 | work_dir="/etc/xray" 20 | config_dir="${work_dir}/config.json" 21 | client_dir="${work_dir}/url.txt" 22 | # 定义环境变量 23 | export UUID=${UUID:-$(cat /proc/sys/kernel/random/uuid)} 24 | export PORT=${PORT:-$(shuf -i 1000-60000 -n 1)} 25 | export ARGO_PORT=${ARGO_PORT:-'8080'} 26 | export CFIP=${CFIP:-'www.visa.com.tw'} 27 | export CFPORT=${CFPORT:-'443'} 28 | 29 | # 检查是否为root下运行 30 | [[ $EUID -ne 0 ]] && red "请在root用户下运行脚本" && exit 1 31 | 32 | # 检查 xray 是否已安装 33 | check_xray() { 34 | if [ -f "${work_dir}/${server_name}" ]; then 35 | if [ -f /etc/alpine-release ]; then 36 | rc-service xray status | grep -q "started" && green "running" && return 0 || yellow "not running" && return 1 37 | else 38 | [ "$(systemctl is-active xray)" = "active" ] && green "running" && return 0 || yellow "not running" && return 1 39 | fi 40 | else 41 | red "not installed" 42 | return 2 43 | fi 44 | } 45 | 46 | # 检查 argo 是否已安装 47 | check_argo() { 48 | if [ -f "${work_dir}/argo" ]; then 49 | if [ -f /etc/alpine-release ]; then 50 | rc-service tunnel status | grep -q "started" && green "running" && return 0 || yellow "not running" && return 1 51 | else 52 | [ "$(systemctl is-active tunnel)" = "active" ] && green "running" && return 0 || yellow "not running" && return 1 53 | fi 54 | else 55 | red "not installed" 56 | return 2 57 | fi 58 | } 59 | 60 | # 检查 caddy 是否已安装 61 | check_caddy() { 62 | if command -v caddy &>/dev/null; then 63 | if [ -f /etc/alpine-release ]; then 64 | rc-service caddy status | grep -q "started" && green "running" && return 0 || yellow "not running" && return 1 65 | else 66 | [ "$(systemctl is-active caddy)" = "active" ] && green "running" && return 0 || yellow "not running" && return 1 67 | fi 68 | else 69 | red "not installed" 70 | return 2 71 | fi 72 | } 73 | 74 | #根据系统类型安装、卸载依赖 75 | manage_packages() { 76 | if [ $# -lt 2 ]; then 77 | red "Unspecified package name or action" 78 | return 1 79 | fi 80 | 81 | action=$1 82 | shift 83 | 84 | for package in "$@"; do 85 | if [ "$action" == "install" ]; then 86 | if command -v "$package" &>/dev/null; then 87 | green "${package} already installed" 88 | continue 89 | fi 90 | yellow "正在安装 ${package}..." 91 | if command -v apt &>/dev/null; then 92 | DEBIAN_FRONTEND=noninteractive apt install -y "$package" 93 | elif command -v dnf &>/dev/null; then 94 | dnf install -y "$package" 95 | elif command -v yum &>/dev/null; then 96 | yum install -y "$package" 97 | elif command -v apk &>/dev/null; then 98 | apk update 99 | apk add "$package" 100 | else 101 | red "Unknown system!" 102 | return 1 103 | fi 104 | elif [ "$action" == "uninstall" ]; then 105 | if ! command -v "$package" &>/dev/null; then 106 | yellow "${package} is not installed" 107 | continue 108 | fi 109 | yellow "正在卸载 ${package}..." 110 | if command -v apt &>/dev/null; then 111 | apt remove -y "$package" && apt autoremove -y 112 | elif command -v dnf &>/dev/null; then 113 | dnf remove -y "$package" && dnf autoremove -y 114 | elif command -v yum &>/dev/null; then 115 | yum remove -y "$package" && yum autoremove -y 116 | elif command -v apk &>/dev/null; then 117 | apk del "$package" 118 | else 119 | red "Unknown system!" 120 | return 1 121 | fi 122 | else 123 | red "Unknown action: $action" 124 | return 1 125 | fi 126 | done 127 | 128 | return 0 129 | } 130 | 131 | # 获取ip 132 | get_realip() { 133 | ip=$(curl -s --max-time 2 ipv4.ip.sb) 134 | if [ -z "$ip" ]; then 135 | ipv6=$(curl -s --max-time 2 ipv6.ip.sb) 136 | echo "[$ipv6]" 137 | else 138 | if echo "$(curl -s http://ipinfo.io/org)" | grep -qE 'Cloudflare|UnReal|AEZA|Andrei'; then 139 | ipv6=$(curl -s --max-time 2 ipv6.ip.sb) 140 | echo "[$ipv6]" 141 | else 142 | echo "$ip" 143 | fi 144 | fi 145 | } 146 | 147 | # 下载并安装 xray,cloudflared 148 | install_xray() { 149 | clear 150 | purple "正在安装Xray-2go中,请稍等..." 151 | ARCH_RAW=$(uname -m) 152 | case "${ARCH_RAW}" in 153 | 'x86_64') ARCH='amd64'; ARCH_ARG='64' ;; 154 | 'x86' | 'i686' | 'i386') ARCH='386'; ARCH_ARG='32' ;; 155 | 'aarch64' | 'arm64') ARCH='arm64'; ARCH_ARG='arm64-v8a' ;; 156 | 'armv7l') ARCH='armv7'; ARCH_ARG='arm32-v7a' ;; 157 | 's390x') ARCH='s390x' ;; 158 | *) red "不支持的架构: ${ARCH_RAW}"; exit 1 ;; 159 | esac 160 | 161 | # 下载xray,cloudflared 162 | [ ! -d "${work_dir}" ] && mkdir -p "${work_dir}" && chmod 777 "${work_dir}" 163 | curl -sLo "${work_dir}/${server_name}.zip" "https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-${ARCH_ARG}.zip" 164 | curl -sLo "${work_dir}/qrencode" "https://github.com/eooce/test/releases/download/${ARCH}/qrencode-linux-${ARCH}" 165 | curl -sLo "${work_dir}/argo" "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${ARCH}" 166 | unzip "${work_dir}/${server_name}.zip" -d "${work_dir}/" > /dev/null 2>&1 && chmod +x ${work_dir}/${server_name} ${work_dir}/argo ${work_dir}/qrencode 167 | rm -rf "${work_dir}/${server_name}.zip" "${work_dir}/geosite.dat" "${work_dir}/geoip.dat" "${work_dir}/README.md" "${work_dir}/LICENSE" 168 | 169 | # 生成随机UUID和密码 170 | password=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c 24) 171 | GRPC_PORT=$(($PORT + 1)) 172 | XHTTP_PORT=$(($PORT + 2)) 173 | 174 | # 关闭防火墙 175 | iptables -F > /dev/null 2>&1 && iptables -P INPUT ACCEPT > /dev/null 2>&1 && iptables -P FORWARD ACCEPT > /dev/null 2>&1 && iptables -P OUTPUT ACCEPT > /dev/null 2>&1 176 | command -v ip6tables &> /dev/null && ip6tables -F > /dev/null 2>&1 && ip6tables -P INPUT ACCEPT > /dev/null 2>&1 && ip6tables -P FORWARD ACCEPT > /dev/null 2>&1 && ip6tables -P OUTPUT ACCEPT > /dev/null 2>&1 177 | 178 | output=$(/etc/xray/xray x25519) 179 | private_key=$(echo "${output}" | grep "PrivateKey:" | awk '{print $2}') 180 | public_key=$(echo "${output}" | grep "Password:" | awk '{print $2}') 181 | 182 | # 生成配置文件 183 | cat > "${config_dir}" << EOF 184 | { 185 | "log": { "access": "/dev/null", "error": "/dev/null", "loglevel": "none" }, 186 | "inbounds": [ 187 | { 188 | "port": $ARGO_PORT, 189 | "protocol": "vless", 190 | "settings": { 191 | "clients": [{ "id": "$UUID", "flow": "xtls-rprx-vision" }], 192 | "decryption": "none", 193 | "fallbacks": [ 194 | { "dest": 3001 }, { "path": "/vless-argo", "dest": 3002 }, 195 | { "path": "/vmess-argo", "dest": 3003 } 196 | ] 197 | }, 198 | "streamSettings": { "network": "tcp" } 199 | }, 200 | { 201 | "port": 3001, "listen": "127.0.0.1", "protocol": "vless", 202 | "settings": { "clients": [{ "id": "$UUID" }], "decryption": "none" }, 203 | "streamSettings": { "network": "tcp", "security": "none" } 204 | }, 205 | { 206 | "port": 3002, "listen": "127.0.0.1", "protocol": "vless", 207 | "settings": { "clients": [{ "id": "$UUID", "level": 0 }], "decryption": "none" }, 208 | "streamSettings": { "network": "ws", "security": "none", "wsSettings": { "path": "/vless-argo" } }, 209 | "sniffing": { "enabled": true, "destOverride": ["http", "tls", "quic"], "metadataOnly": false } 210 | }, 211 | { 212 | "port": 3003, "listen": "127.0.0.1", "protocol": "vmess", 213 | "settings": { "clients": [{ "id": "$UUID", "alterId": 0 }] }, 214 | "streamSettings": { "network": "ws", "wsSettings": { "path": "/vmess-argo" } }, 215 | "sniffing": { "enabled": true, "destOverride": ["http", "tls", "quic"], "metadataOnly": false } 216 | }, 217 | { 218 | "listen":"::","port": $XHTTP_PORT, "protocol": "vless","settings": {"clients": [{"id": "$UUID"}],"decryption": "none"}, 219 | "streamSettings": {"network": "xhttp","security": "reality","realitySettings": {"target": "www.nazhumi.com:443","xver": 0,"serverNames": 220 | ["www.nazhumi.com"],"privateKey": "$private_key","shortIds": [""]}},"sniffing": {"enabled": true,"destOverride": ["http","tls","quic"]} 221 | }, 222 | { 223 | "listen":"::","port":$GRPC_PORT,"protocol":"vless","settings":{"clients":[{"id":"$UUID"}],"decryption":"none"}, 224 | "streamSettings":{"network":"grpc","security":"reality","realitySettings":{"dest":"www.iij.ad.jp:443","serverNames":["www.iij.ad.jp"], 225 | "privateKey":"$private_key","shortIds":[""]},"grpcSettings":{"serviceName":"grpc"}},"sniffing":{"enabled":true,"destOverride":["http","tls","quic"]} 226 | } 227 | ], 228 | "dns": { "servers": ["https+local://8.8.8.8/dns-query"] }, 229 | "outbounds": [ 230 | { 231 | "protocol": "freedom", 232 | "tag": "direct" 233 | }, 234 | { 235 | "protocol": "blackhole", 236 | "tag": "block" 237 | } 238 | ] 239 | } 240 | EOF 241 | } 242 | # debian/ubuntu/centos 守护进程 243 | main_systemd_services() { 244 | cat > /etc/systemd/system/xray.service << EOF 245 | [Unit] 246 | Description=Xray Service 247 | Documentation=https://github.com/XTLS/Xray-core 248 | After=network.target nss-lookup.target 249 | Wants=network-online.target 250 | 251 | [Service] 252 | Type=simple 253 | NoNewPrivileges=yes 254 | ExecStart=$work_dir/xray run -c $config_dir 255 | Restart=on-failure 256 | RestartPreventExitStatus=23 257 | 258 | [Install] 259 | WantedBy=multi-user.target 260 | EOF 261 | 262 | cat > /etc/systemd/system/tunnel.service << EOF 263 | [Unit] 264 | Description=Cloudflare Tunnel 265 | After=network.target 266 | 267 | [Service] 268 | Type=simple 269 | NoNewPrivileges=yes 270 | TimeoutStartSec=0 271 | ExecStart=/etc/xray/argo tunnel --url http://localhost:$ARGO_PORT --no-autoupdate --edge-ip-version auto --protocol http2 272 | StandardOutput=append:/etc/xray/argo.log 273 | Restart=on-failure 274 | RestartSec=5s 275 | 276 | [Install] 277 | WantedBy=multi-user.target 278 | 279 | EOF 280 | if [ -f /etc/centos-release ]; then 281 | yum install -y chrony 282 | systemctl start chronyd 283 | systemctl enable chronyd 284 | chronyc -a makestep 285 | yum update -y ca-certificates 286 | bash -c 'echo "0 0" > /proc/sys/net/ipv4/ping_group_range' 287 | fi 288 | bash -c 'echo "0 0" > /proc/sys/net/ipv4/ping_group_range' 289 | systemctl daemon-reload 290 | systemctl enable xray 291 | systemctl is-active --quiet xray || systemctl start xray 292 | systemctl enable tunnel 293 | systemctl start tunnel 294 | systemctl is-active --quiet tunnel || systemctl start xray 295 | } 296 | # 适配alpine 守护进程 297 | alpine_openrc_services() { 298 | cat > /etc/init.d/xray << 'EOF' 299 | #!/sbin/openrc-run 300 | 301 | description="Xray service" 302 | command="/etc/xray/xray" 303 | command_args="run -c /etc/xray/config.json" 304 | command_background=true 305 | pidfile="/var/run/xray.pid" 306 | EOF 307 | 308 | cat > /etc/init.d/tunnel << 'EOF' 309 | #!/sbin/openrc-run 310 | 311 | description="Cloudflare Tunnel" 312 | command="/bin/sh" 313 | command_args="-c '/etc/xray/argo tunnel --url http://localhost:8080 --no-autoupdate --edge-ip-version auto --protocol http2 > /etc/xray/argo.log 2>&1'" 314 | command_background=true 315 | pidfile="/var/run/tunnel.pid" 316 | EOF 317 | 318 | chmod +x /etc/init.d/xray 319 | chmod +x /etc/init.d/tunnel 320 | 321 | rc-update add xray default 322 | rc-update add tunnel default 323 | 324 | } 325 | 326 | 327 | get_info() { 328 | clear 329 | IP=$(get_realip) 330 | 331 | isp=$(curl -s --max-time 2 https://speed.cloudflare.com/meta | awk -F\" '{print $26"-"$18}' | sed -e 's/ /_/g' || echo "vps") 332 | 333 | if [ -f "${work_dir}/argo.log" ]; then 334 | for i in {1..5}; do 335 | purple "第 $i 次尝试获取ArgoDoamin中..." 336 | argodomain=$(sed -n 's|.*https://\([^/]*trycloudflare\.com\).*|\1|p' "${work_dir}/argo.log") 337 | [ -n "$argodomain" ] && break 338 | sleep 2 339 | done 340 | else 341 | restart_argo 342 | sleep 6 343 | argodomain=$(sed -n 's|.*https://\([^/]*trycloudflare\.com\).*|\1|p' "${work_dir}/argo.log") 344 | fi 345 | 346 | green "\nArgoDomain:${purple}$argodomain${re}\n" 347 | 348 | cat > ${work_dir}/url.txt < ${work_dir}/sub.txt 361 | yellow "\n温馨提醒:如果是NAT机,reality端口和订阅端口需使用可用端口范围内的端口,否则reality协议不通,无法订阅\n" 362 | green "节点订阅链接:http://$IP:$PORT/$password\n\n订阅链接适用于V2rayN,Nekbox,karing,Sterisand,Loon,小火箭,圈X等\n" 363 | green "订阅二维码" 364 | $work_dir/qrencode "http://$IP:$PORT/$password" 365 | echo "" 366 | } 367 | 368 | # 处理ubuntu系统中没有caddy源的问题 369 | install_caddy () { 370 | if [ -f /etc/os-release ] && (grep -q "Ubuntu" /etc/os-release || grep -q "Debian GNU/Linux 11" /etc/os-release); then 371 | purple "安装依赖中...\n" 372 | apt install -y debian-keyring debian-archive-keyring apt-transport-https 373 | curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | tee /etc/apt/trusted.gpg.d/caddy-stable.asc 374 | curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list 375 | rm /etc/apt/trusted.gpg.d/caddy-stable.asc /usr/share/keyrings/caddy-archive-keyring.gpg 2>/dev/null 376 | curl -fsSL https://dl.cloudsmith.io/public/caddy/stable/gpg.key | gpg --dearmor -o /usr/share/keyrings/caddy-archive-keyring.gpg 377 | echo "deb [signed-by=/usr/share/keyrings/caddy-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main" | tee /etc/apt/sources.list.d/caddy-stable.list 378 | DEBIAN_FRONTEND=noninteractive apt update -y && manage_packages install caddy 379 | else 380 | manage_packages install caddy 381 | fi 382 | } 383 | 384 | # caddy订阅配置 385 | add_caddy_conf() { 386 | [ -f /etc/caddy/Caddyfile ] && cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak > /dev/null 2>&1 387 | rm -rf /etc/caddy/Caddyfile 388 | cat > /etc/caddy/Caddyfile << EOF 389 | { 390 | auto_https off 391 | log { 392 | output file /var/log/caddy/caddy.log { 393 | roll_size 10MB 394 | roll_keep 10 395 | roll_keep_for 720h 396 | } 397 | } 398 | } 399 | 400 | :$PORT { 401 | handle /$password { 402 | root * /etc/xray 403 | try_files /sub.txt 404 | file_server browse 405 | header Content-Type "text/plain; charset=utf-8" 406 | } 407 | 408 | handle { 409 | respond "404 Not Found" 404 410 | } 411 | } 412 | EOF 413 | 414 | /usr/bin/caddy validate --config /etc/caddy/Caddyfile > /dev/null 2>&1 415 | chown caddy:caddy /var/log/caddy/caddy.log > /dev/null 2>&1 416 | chmod 644 /var/log/caddy/caddy.log > /dev/null 2>&1 417 | 418 | if [ $? -eq 0 ]; then 419 | if [ -f /etc/alpine-release ]; then 420 | rc-service caddy restart 421 | else 422 | systemctl daemon-reload 423 | systemctl restart caddy 424 | fi 425 | else 426 | [ -f /etc/alpine-release ] && rc-service caddy restart > /dev/null 2>&1 || red "Caddy 配置文件验证失败,订阅功能可能无法使用,但不影响节点使用\nissues 反馈:https://github.com/eooce/xray-argo/issues\n" 427 | fi 428 | } 429 | 430 | 431 | # 启动 xray 432 | start_xray() { 433 | if [ ${check_xray} -eq 1 ]; then 434 | yellow "\n正在启动 ${server_name} 服务\n" 435 | if [ -f /etc/alpine-release ]; then 436 | rc-service xray start 437 | else 438 | systemctl daemon-reload 439 | systemctl start "${server_name}" 440 | fi 441 | if [ $? -eq 0 ]; then 442 | green "${server_name} 服务已成功启动\n" 443 | else 444 | red "${server_name} 服务启动失败\n" 445 | fi 446 | elif [ ${check_xray} -eq 0 ]; then 447 | yellow "xray 正在运行\n" 448 | sleep 1 449 | menu 450 | else 451 | yellow "xray 尚未安装!\n" 452 | sleep 1 453 | menu 454 | fi 455 | } 456 | 457 | # 停止 xray 458 | stop_xray() { 459 | if [ ${check_xray} -eq 0 ]; then 460 | yellow "\n正在停止 ${server_name} 服务\n" 461 | if [ -f /etc/alpine-release ]; then 462 | rc-service xray stop 463 | else 464 | systemctl stop "${server_name}" 465 | fi 466 | if [ $? -eq 0 ]; then 467 | green "${server_name} 服务已成功停止\n" 468 | else 469 | red "${server_name} 服务停止失败\n" 470 | fi 471 | 472 | elif [ ${check_xray} -eq 1 ]; then 473 | yellow "xray 未运行\n" 474 | sleep 1 475 | menu 476 | else 477 | yellow "xray 尚未安装!\n" 478 | sleep 1 479 | menu 480 | fi 481 | } 482 | 483 | # 重启 xray 484 | restart_xray() { 485 | if [ ${check_xray} -eq 0 ]; then 486 | yellow "\n正在重启 ${server_name} 服务\n" 487 | if [ -f /etc/alpine-release ]; then 488 | rc-service ${server_name} restart 489 | else 490 | systemctl daemon-reload 491 | systemctl restart "${server_name}" 492 | fi 493 | if [ $? -eq 0 ]; then 494 | green "${server_name} 服务已成功重启\n" 495 | else 496 | red "${server_name} 服务重启失败\n" 497 | fi 498 | elif [ ${check_xray} -eq 1 ]; then 499 | yellow "xray 未运行\n" 500 | sleep 1 501 | menu 502 | else 503 | yellow "xray 尚未安装!\n" 504 | sleep 1 505 | menu 506 | fi 507 | } 508 | 509 | # 启动 argo 510 | start_argo() { 511 | if [ ${check_argo} -eq 1 ]; then 512 | yellow "\n正在启动 Argo 服务\n" 513 | if [ -f /etc/alpine-release ]; then 514 | rc-service tunnel start 515 | else 516 | systemctl daemon-reload 517 | systemctl start tunnel 518 | fi 519 | if [ $? -eq 0 ]; then 520 | green "Argo 服务已成功重启\n" 521 | else 522 | red "Argo 服务重启失败\n" 523 | fi 524 | elif [ ${check_argo} -eq 0 ]; then 525 | green "Argo 服务正在运行\n" 526 | sleep 1 527 | menu 528 | else 529 | yellow "Argo 尚未安装!\n" 530 | sleep 1 531 | menu 532 | fi 533 | } 534 | 535 | # 停止 argo 536 | stop_argo() { 537 | if [ ${check_argo} -eq 0 ]; then 538 | yellow "\n正在停止 Argo 服务\n" 539 | if [ -f /etc/alpine-release ]; then 540 | rc-service stop start 541 | else 542 | systemctl daemon-reload 543 | systemctl stop tunnel 544 | fi 545 | if [ $? -eq 0 ]; then 546 | green "Argo 服务已成功停止\n" 547 | else 548 | red "Argo 服务停止失败\n" 549 | fi 550 | elif [ ${check_argo} -eq 1 ]; then 551 | yellow "Argo 服务未运行\n" 552 | sleep 1 553 | menu 554 | else 555 | yellow "Argo 尚未安装!\n" 556 | sleep 1 557 | menu 558 | fi 559 | } 560 | 561 | # 重启 argo 562 | restart_argo() { 563 | if [ ${check_argo} -eq 0 ]; then 564 | yellow "\n正在重启 Argo 服务\n" 565 | rm /etc/xray/argo.log 2>/dev/null 566 | if [ -f /etc/alpine-release ]; then 567 | rc-service tunnel restart 568 | else 569 | systemctl daemon-reload 570 | systemctl restart tunnel 571 | fi 572 | if [ $? -eq 0 ]; then 573 | green "Argo 服务已成功重启\n" 574 | else 575 | red "Argo 服务重启失败\n" 576 | fi 577 | elif [ ${check_argo} -eq 1 ]; then 578 | yellow "Argo 服务未运行\n" 579 | sleep 1 580 | menu 581 | else 582 | yellow "Argo 尚未安装!\n" 583 | sleep 1 584 | menu 585 | fi 586 | } 587 | 588 | # 启动 caddy 589 | start_caddy() { 590 | if command -v caddy &>/dev/null; then 591 | yellow "\n正在启动 caddy 服务\n" 592 | if [ -f /etc/alpine-release ]; then 593 | rc-service caddy start 594 | else 595 | systemctl daemon-reload 596 | systemctl start caddy 597 | fi 598 | if [ $? -eq 0 ]; then 599 | green "caddy 服务已成功启动\n" 600 | else 601 | red "caddy 启动失败\n" 602 | fi 603 | else 604 | yellow "caddy 尚未安装!\n" 605 | sleep 1 606 | menu 607 | fi 608 | } 609 | 610 | # 重启 caddy 611 | restart_caddy() { 612 | if command -v caddy &>/dev/null; then 613 | yellow "\n正在重启 caddy 服务\n" 614 | if [ -f /etc/alpine-release ]; then 615 | rc-service caddy restart 616 | else 617 | systemctl restart caddy 618 | fi 619 | if [ $? -eq 0 ]; then 620 | green "caddy 服务已成功重启\n" 621 | else 622 | red "caddy 重启失败\n" 623 | fi 624 | else 625 | yellow "caddy 尚未安装!\n" 626 | sleep 1 627 | menu 628 | fi 629 | } 630 | 631 | # 卸载 xray 632 | uninstall_xray() { 633 | reading "确定要卸载 xray-2go 吗? (y/n): " choice 634 | case "${choice}" in 635 | y|Y) 636 | yellow "正在卸载 xray" 637 | if [ -f /etc/alpine-release ]; then 638 | rc-service xray stop 639 | rc-service tunnel stop 640 | rm /etc/init.d/xray /etc/init.d/tunnel 641 | rc-update del xray default 642 | rc-update del tunnel default 643 | else 644 | # 停止 xray和 argo 服务 645 | systemctl stop "${server_name}" 646 | systemctl stop tunnel 647 | # 禁用 xray 服务 648 | systemctl disable "${server_name}" 649 | systemctl disable tunnel 650 | 651 | # 重新加载 systemd 652 | systemctl daemon-reload || true 653 | fi 654 | # 删除配置文件和日志 655 | rm -rf "${work_dir}" || true 656 | rm -rf /etc/systemd/system/xray.service /etc/systemd/system/tunnel.service 2>/dev/null 657 | 658 | # 卸载caddy 659 | reading "\n是否卸载 caddy?${green}(卸载请输入 ${yellow}y${re} ${green}回车将跳过卸载caddy) (y/n): ${re}" choice 660 | case "${choice}" in 661 | y|Y) 662 | manage_packages uninstall caddy 663 | ;; 664 | *) 665 | yellow "取消卸载caddy\n" 666 | ;; 667 | esac 668 | 669 | green "\nXray_2go 卸载成功\n" 670 | ;; 671 | *) 672 | purple "已取消卸载操作\n" 673 | ;; 674 | esac 675 | } 676 | 677 | # 创建快捷指令 678 | create_shortcut() { 679 | cat > "$work_dir/2go.sh" << EOF 680 | #!/usr/bin/env bash 681 | 682 | bash <(curl -Ls https://github.com/eooce/xray-2go/raw/main/xray_2go.sh) \$1 683 | EOF 684 | chmod +x "$work_dir/2go.sh" 685 | ln -sf "$work_dir/2go.sh" /usr/bin/2go 686 | if [ -s /usr/bin/2go ]; then 687 | green "\n快捷指令 2go 创建成功\n" 688 | else 689 | red "\n快捷指令创建失败\n" 690 | fi 691 | } 692 | 693 | # 适配alpine运行argo报错用户组和dns的问题 694 | change_hosts() { 695 | sh -c 'echo "0 0" > /proc/sys/net/ipv4/ping_group_range' 696 | sed -i '1s/.*/127.0.0.1 localhost/' /etc/hosts 697 | sed -i '2s/.*/::1 localhost/' /etc/hosts 698 | } 699 | 700 | # 变更配置 701 | change_config() { 702 | clear 703 | echo "" 704 | green "1. 修改UUID" 705 | skyblue "------------" 706 | green "2. 修改grpc-reality端口" 707 | skyblue "------------" 708 | green "3. 修改xhttp-reality端口" 709 | skyblue "------------" 710 | green "4. 修改reality节点伪装域名" 711 | skyblue "------------" 712 | purple "${purple}0. 返回主菜单" 713 | skyblue "------------" 714 | reading "请输入选择: " choice 715 | case "${choice}" in 716 | 1) 717 | reading "\n请输入新的UUID: " new_uuid 718 | [ -z "$new_uuid" ] && new_uuid=$(cat /proc/sys/kernel/random/uuid) && green "\n生成的UUID为:$new_uuid" 719 | sed -i "s/[a-fA-F0-9]\{8\}-[a-fA-F0-9]\{4\}-[a-fA-F0-9]\{4\}-[a-fA-F0-9]\{4\}-[a-fA-F0-9]\{12\}/$new_uuid/g" $config_dir 720 | restart_xray 721 | sed -i "s/[a-fA-F0-9]\{8\}-[a-fA-F0-9]\{4\}-[a-fA-F0-9]\{4\}-[a-fA-F0-9]\{4\}-[a-fA-F0-9]\{12\}/$new_uuid/g" $client_dir 722 | content=$(cat "$client_dir") 723 | vmess_urls=$(grep -o 'vmess://[^ ]*' "$client_dir") 724 | vmess_prefix="vmess://" 725 | for vmess_url in $vmess_urls; do 726 | encoded_vmess="${vmess_url#"$vmess_prefix"}" 727 | decoded_vmess=$(echo "$encoded_vmess" | base64 --decode) 728 | updated_vmess=$(echo "$decoded_vmess" | jq --arg new_uuid "$new_uuid" '.id = $new_uuid') 729 | encoded_updated_vmess=$(echo "$updated_vmess" | base64 | tr -d '\n') 730 | new_vmess_url="$vmess_prefix$encoded_updated_vmess" 731 | content=$(echo "$content" | sed "s|$vmess_url|$new_vmess_url|") 732 | done 733 | echo "$content" > "$client_dir" 734 | base64 -w0 $client_dir > /etc/xray/sub.txt 735 | while IFS= read -r line; do yellow "$line"; done < $client_dir 736 | green "\nUUID已修改为:${purple}${new_uuid}${re} ${green}请更新订阅或手动更改所有节点的UUID${re}\n" 737 | ;; 738 | 2) 739 | reading "\n请输入grpc-reality端口 (回车跳过将使用随机端口): " new_port 740 | [ -z "$new_port" ] && new_port=$(shuf -i 2000-65000 -n 1) 741 | until [[ -z $(lsof -iTCP:$new_port -sTCP:LISTEN 2>/dev/null) ]]; do 742 | if [[ -n $(lsof -iTCP:$new_port -sTCP:LISTEN 2>/dev/null) ]]; then 743 | echo -e "${red}${new_port}端口已经被其他程序占用,请更换端口重试${re}" 744 | reading "请输入新的订阅端口(1-65535):" new_port 745 | [[ -z $new_port ]] && new_port=$(shuf -i 2000-65000 -n 1) 746 | fi 747 | done 748 | sed -i "41s/\"port\":\s*[0-9]\+/\"port\": $new_port/" /etc/xray/config.json 749 | restart_xray 750 | sed -i '1s/\(vless:\/\/[^@]*@[^:]*:\)[0-9]\{1,\}/\1'"$new_port"'/' $client_dir 751 | base64 -w0 $client_dir > /etc/xray/sub.txt 752 | while IFS= read -r line; do yellow "$line"; done < ${work_dir}/url.txt 753 | green "\nGRPC-reality端口已修改成:${purple}$new_port${re} ${green}请更新订阅或手动更改grpc-reality节点端口${re}\n" 754 | ;; 755 | 3) 756 | reading "\n请输入xhttp-reality端口 (回车跳过将使用随机端口): " new_port 757 | [ -z "$new_port" ] && new_port=$(shuf -i 2000-65000 -n 1) 758 | until [[ -z $(lsof -iTCP:$new_port -sTCP:LISTEN 2>/dev/null) ]]; do 759 | if [[ -n $(lsof -iTCP:$new_port -sTCP:LISTEN 2>/dev/null) ]]; then 760 | echo -e "${red}${new_port}端口已经被其他程序占用,请更换端口重试${re}" 761 | reading "请输入新的订阅端口(1-65535):" new_port 762 | [[ -z $new_port ]] && new_port=$(shuf -i 2000-65000 -n 1) 763 | fi 764 | done 765 | sed -i "35s/\"port\":\s*[0-9]\+/\"port\": $new_port/" /etc/xray/config.json 766 | restart_xray 767 | sed -i '3s/\(vless:\/\/[^@]*@[^:]*:\)[0-9]\{1,\}/\1'"$new_port"'/' $client_dir 768 | base64 -w0 $client_dir > /etc/xray/sub.txt 769 | while IFS= read -r line; do yellow "$line"; done < ${work_dir}/url.txt 770 | green "\nxhttp-reality端口已修改成:${purple}$new_port${re} ${green}请更新订阅或手动更改xhttp-reality节点端口${re}\n" 771 | ;; 772 | 4) 773 | clear 774 | green "\n1. bgk.jp\n\n2. www.joom.com\n\n3. www.stengg.com\n\n4. www.nazhumi.com\n" 775 | reading "\n请输入新的Reality伪装域名(可自定义输入,回车留空将使用默认1): " new_sni 776 | if [ -z "$new_sni" ]; then 777 | new_sni="bgk.jp" 778 | elif [[ "$new_sni" == "1" ]]; then 779 | new_sni="bgk.jp" 780 | elif [[ "$new_sni" == "2" ]]; then 781 | new_sni="www.joom.com" 782 | elif [[ "$new_sni" == "3" ]]; then 783 | new_sni="www.stengg.com" 784 | elif [[ "$new_sni" == "4" ]]; then 785 | new_sni="www.nazhumi.com" 786 | else 787 | new_sni="$new_sni" 788 | fi 789 | jq --arg new_sni "$new_sni" '.inbounds[5].streamSettings.realitySettings.dest = ($new_sni + ":443") | .inbounds[5].streamSettings.realitySettings.serverNames = [$new_sni]' /etc/xray/config.json > /etc/xray/config.json.tmp && mv /etc/xray/config.json.tmp /etc/xray/config.json 790 | restart_xray 791 | sed -i "1s/\(vless:\/\/[^\?]*\?\([^\&]*\&\)*sni=\)[^&]*/\1$new_sni/" $client_dir 792 | sed -i "1s/\(vless:\/\/[^\?]*\?\([^\&]*\&\)*authority=\)[^&]*/\1$new_sni/" $client_dir 793 | base64 -w0 $client_dir > /etc/xray/sub.txt 794 | while IFS= read -r line; do yellow "$line"; done < ${work_dir}/url.txt 795 | echo "" 796 | green "\nReality sni已修改为:${purple}${new_sni}${re} ${green}请更新订阅或手动更改reality节点的sni域名${re}\n" 797 | ;; 798 | 0) menu ;; 799 | *) read "无效的选项!" ;; 800 | esac 801 | } 802 | 803 | disable_open_sub() { 804 | if [ ${check_xray} -eq 0 ]; then 805 | clear 806 | echo "" 807 | green "1. 关闭节点订阅" 808 | skyblue "------------" 809 | green "2. 开启节点订阅" 810 | skyblue "------------" 811 | green "3. 更换订阅端口" 812 | skyblue "------------" 813 | purple "4. 返回主菜单" 814 | skyblue "------------" 815 | reading "请输入选择: " choice 816 | case "${choice}" in 817 | 1) 818 | if command -v caddy &>/dev/null; then 819 | if [ -f /etc/alpine-release ]; then 820 | rc-service caddy status | grep -q "started" && rc-service caddy stop || red "caddy not running" 821 | else 822 | [ "$(systemctl is-active caddy)" = "active" ] && systemctl stop caddy || red "ngixn not running" 823 | fi 824 | else 825 | yellow "caddy is not installed" 826 | fi 827 | 828 | green "\n已关闭节点订阅\n" 829 | ;; 830 | 2) 831 | green "\n已开启节点订阅\n" 832 | server_ip=$(get_realip) 833 | password=$(tr -dc A-Za-z < /dev/urandom | head -c 32) 834 | sed -i "s/\/[a-zA-Z0-9]\+/\/$password/g" /etc/caddy/Caddyfile 835 | sub_port=$(port=$(grep -oP ':\K[0-9]+' /etc/caddy/Caddyfile); if [ "$port" -eq 80 ]; then echo ""; else echo "$port"; fi) 836 | start_caddy 837 | (port=$(grep -oP ':\K[0-9]+' /etc/caddy/Caddyfile); if [ "$port" -eq 80 ]; then echo ""; else green "订阅端口:$port"; fi); link=$(if [ -z "$sub_port" ]; then echo "http://$server_ip/$password"; else echo "http://$server_ip:$sub_port/$password"; fi); green "\n新的节点订阅链接:$link\n" 838 | ;; 839 | 840 | 3) 841 | reading "请输入新的订阅端口(1-65535):" sub_port 842 | [ -z "$sub_port" ] && sub_port=$(shuf -i 2000-65000 -n 1) 843 | until [[ -z $(lsof -iTCP:$sub_port -sTCP:LISTEN 2>/dev/null) ]]; do 844 | if [[ -n $(lsof -iTCP:$sub_port -sTCP:LISTEN 2>/dev/null) ]]; then 845 | echo -e "${red}${new_port}端口已经被其他程序占用,请更换端口重试${re}" 846 | reading "请输入新的订阅端口(1-65535):" sub_port 847 | [[ -z $sub_port ]] && sub_port=$(shuf -i 2000-65000 -n 1) 848 | fi 849 | done 850 | sed -i "s/:[0-9]\+/:$sub_port/g" /etc/caddy/Caddyfile 851 | path=$(sed -n 's/.*handle \/\([^ ]*\).*/\1/p' /etc/caddy/Caddyfile) 852 | server_ip=$(get_realip) 853 | restart_caddy 854 | green "\n订阅端口更换成功\n" 855 | green "新的订阅链接为:http://$server_ip:$sub_port/$path\n" 856 | ;; 857 | 4) menu ;; 858 | *) red "无效的选项!" ;; 859 | esac 860 | else 861 | yellow "xray—2go 尚未安装!" 862 | sleep 1 863 | menu 864 | fi 865 | } 866 | 867 | # xray 管理 868 | manage_xray() { 869 | green "1. 启动xray服务" 870 | skyblue "-------------------" 871 | green "2. 停止xray服务" 872 | skyblue "-------------------" 873 | green "3. 重启xray服务" 874 | skyblue "-------------------" 875 | purple "4. 返回主菜单" 876 | skyblue "------------" 877 | reading "\n请输入选择: " choice 878 | case "${choice}" in 879 | 1) start_xray ;; 880 | 2) stop_xray ;; 881 | 3) restart_xray ;; 882 | 4) menu ;; 883 | *) red "无效的选项!" ;; 884 | esac 885 | } 886 | 887 | # Argo 管理 888 | manage_argo() { 889 | if [ ${check_argo} -eq 2 ]; then 890 | yellow "Argo 尚未安装!" 891 | sleep 1 892 | menu 893 | else 894 | clear 895 | echo "" 896 | green "1. 启动Argo服务" 897 | skyblue "------------" 898 | green "2. 停止Argo服务" 899 | skyblue "------------" 900 | green "3. 添加Argo固定隧道" 901 | skyblue "----------------" 902 | green "4. 切换回Argo临时隧道" 903 | skyblue "------------------" 904 | green "5. 重新获取Argo临时域名" 905 | skyblue "-------------------" 906 | purple "6. 返回主菜单" 907 | skyblue "-----------" 908 | reading "\n请输入选择: " choice 909 | case "${choice}" in 910 | 1) start_argo ;; 911 | 2) stop_argo ;; 912 | 3) 913 | clear 914 | yellow "\n固定隧道可为json或token,固定隧道端口为8080,自行在cf后台设置\n\njson在f佬维护的站点里获取,获取地址:${purple}https://fscarmen.cloudflare.now.cc${re}\n" 915 | reading "\n请输入你的argo域名: " argo_domain 916 | green "你的Argo域名为:$argo_domain" 917 | ArgoDomain=$argo_domain 918 | reading "\n请输入你的argo密钥(token或json): " argo_auth 919 | if [[ $argo_auth =~ TunnelSecret ]]; then 920 | echo $argo_auth > ${work_dir}/tunnel.json 921 | cat > ${work_dir}/tunnel.yml << EOF 922 | tunnel: $(cut -d\" -f12 <<< "$argo_auth") 923 | credentials-file: ${work_dir}/tunnel.json 924 | protocol: http2 925 | 926 | ingress: 927 | - hostname: $ArgoDomain 928 | service: http://localhost:8080 929 | originRequest: 930 | noTLSVerify: true 931 | - service: http_status:404 932 | EOF 933 | if [ -f /etc/alpine-release ]; then 934 | sed -i '/^command_args=/c\command_args="-c '\''/etc/xray/argo tunnel --edge-ip-version auto --config /etc/xray/tunnel.yml run 2>&1'\''"' /etc/init.d/tunnel 935 | else 936 | sed -i '/^ExecStart=/c ExecStart=/bin/sh -c "/etc/xray/argo tunnel --edge-ip-version auto --config /etc/xray/tunnel.yml run 2>&1"' /etc/systemd/system/tunnel.service 937 | fi 938 | restart_argo 939 | add_split_url 940 | change_argo_domain 941 | elif [[ $argo_auth =~ ^[A-Z0-9a-z=]{120,250}$ ]]; then 942 | if [ -f /etc/alpine-release ]; then 943 | sed -i "/^command_args=/c\command_args=\"-c '/etc/xray/argo tunnel --edge-ip-version auto --no-autoupdate --protocol http2 run --token $argo_auth 2>&1'\"" /etc/init.d/tunnel 944 | else 945 | 946 | sed -i '/^ExecStart=/c ExecStart=/bin/sh -c "/etc/xray/argo tunnel --edge-ip-version auto --no-autoupdate --protocol http2 run --token '$argo_auth' 2>&1"' /etc/systemd/system/tunnel.service 947 | fi 948 | restart_argo 949 | add_split_url 950 | change_argo_domain 951 | else 952 | yellow "你输入的argo域名或token不匹配,请重新输入" 953 | manage_argo 954 | fi 955 | ;; 956 | 4) 957 | clear 958 | if [ -f /etc/alpine-release ]; then 959 | alpine_openrc_services 960 | else 961 | main_systemd_services 962 | fi 963 | get_quick_tunnel 964 | change_argo_domain 965 | ;; 966 | 967 | 5) 968 | if [ -f /etc/alpine-release ]; then 969 | if grep -Fq -- '--url http://localhost:8080' /etc/init.d/tunnel; then 970 | get_quick_tunnel 971 | change_argo_domain 972 | else 973 | yellow "当前使用固定隧道,无法获取临时隧道" 974 | sleep 2 975 | menu 976 | fi 977 | else 978 | if grep -q 'ExecStart=.*--url http://localhost:8080' /etc/systemd/system/tunnel.service; then 979 | get_quick_tunnel 980 | change_argo_domain 981 | else 982 | yellow "当前使用固定隧道,无法获取临时隧道" 983 | sleep 2 984 | menu 985 | fi 986 | fi 987 | ;; 988 | 6) menu ;; 989 | *) red "无效的选项!" ;; 990 | esac 991 | fi 992 | } 993 | 994 | # 获取argo临时隧道 995 | get_quick_tunnel() { 996 | restart_argo 997 | yellow "获取临时argo域名中,请稍等...\n" 998 | sleep 3 999 | if [ -f /etc/xray/argo.log ]; then 1000 | for i in {1..5}; do 1001 | get_argodomain=$(sed -n 's|.*https://\([^/]*trycloudflare\.com\).*|\1|p' /etc/xray/argo.log) 1002 | [ -n "$get_argodomain" ] && break 1003 | sleep 2 1004 | done 1005 | else 1006 | restart_argo 1007 | sleep 6 1008 | get_argodomain=$(sed -n 's|.*https://\([^/]*trycloudflare\.com\).*|\1|p' /etc/xray/argo.log) 1009 | fi 1010 | green "ArgoDomain:${purple}$get_argodomain${re}\n" 1011 | ArgoDomain=$get_argodomain 1012 | } 1013 | 1014 | # 更新Argo域名到订阅 1015 | change_argo_domain() { 1016 | sed -i "5s/sni=[^&]*/sni=$ArgoDomain/; 5s/host=[^&]*/host=$ArgoDomain/" /etc/xray/url.txt 1017 | content=$(cat "$client_dir") 1018 | vmess_urls=$(grep -o 'vmess://[^ ]*' "$client_dir") 1019 | vmess_prefix="vmess://" 1020 | for vmess_url in $vmess_urls; do 1021 | encoded_vmess="${vmess_url#"$vmess_prefix"}" 1022 | decoded_vmess=$(echo "$encoded_vmess" | base64 --decode) 1023 | updated_vmess=$(echo "$decoded_vmess" | jq --arg new_domain "$ArgoDomain" '.host = $new_domain | .sni = $new_domain') 1024 | encoded_updated_vmess=$(echo "$updated_vmess" | base64 | tr -d '\n') 1025 | new_vmess_url="$vmess_prefix$encoded_updated_vmess" 1026 | content=$(echo "$content" | sed "s|$vmess_url|$new_vmess_url|") 1027 | done 1028 | echo "$content" > "$client_dir" 1029 | base64 -w0 ${work_dir}/url.txt > ${work_dir}/sub.txt 1030 | 1031 | while IFS= read -r line; do echo -e "${purple}$line"; done < "$client_dir" 1032 | 1033 | green "\n节点已更新,更新订阅或手动复制以上节点\n" 1034 | } 1035 | 1036 | # 查看节点信息和订阅链接 1037 | check_nodes() { 1038 | if [ ${check_xray} -eq 0 ]; then 1039 | while IFS= read -r line; do purple "${purple}$line"; done < ${work_dir}/url.txt 1040 | server_ip=$(get_realip) 1041 | sub_port=$(sed -n 's/.*:\([0-9]\+\).*/\1/p' /etc/caddy/Caddyfile) 1042 | lujing=$(sed -n 's/.*handle \/\([a-zA-Z0-9]\+\).*/\1/p' /etc/caddy/Caddyfile) 1043 | green "\n\n节点订阅链接:http://$server_ip:$sub_port/$lujing\n" 1044 | else 1045 | yellow "Xray-2go 尚未安装或未运行,请先安装或启动Xray-2go" 1046 | sleep 1 1047 | menu 1048 | fi 1049 | } 1050 | 1051 | # 捕获 Ctrl+C 信号 1052 | trap 'red "已取消操作"; exit' INT 1053 | 1054 | # 主菜单 1055 | menu() { 1056 | while true; do 1057 | check_xray &>/dev/null; check_xray=$? 1058 | check_caddy &>/dev/null; check_caddy=$? 1059 | check_argo &>/dev/null; check_argo=$? 1060 | check_xray_status=$(check_xray) > /dev/null 2>&1 1061 | check_caddy_status=$(check_caddy) > /dev/null 2>&1 1062 | check_argo_status=$(check_argo) > /dev/null 2>&1 1063 | clear 1064 | echo "" 1065 | purple "=== 老王Xray-2go一键安装脚本 ===\n" 1066 | purple " Xray 状态: ${check_xray_status}\n" 1067 | purple " Argo 状态: ${check_argo_status}\n" 1068 | purple "Caddy 状态: ${check_caddy_status}\n" 1069 | green "1. 安装Xray-2go" 1070 | red "2. 卸载Xray-2go" 1071 | echo "===============" 1072 | green "3. Xray-2go管理" 1073 | green "4. Argo隧道管理" 1074 | echo "===============" 1075 | green "5. 查看节点信息" 1076 | green "6. 修改节点配置" 1077 | green "7. 管理节点订阅" 1078 | echo "===============" 1079 | purple "8. ssh综合工具箱" 1080 | purple "9. 安装singbox四合一" 1081 | echo "===============" 1082 | red "0. 退出脚本" 1083 | echo "===========" 1084 | reading "请输入选择(0-9): " choice 1085 | echo "" 1086 | case "${choice}" in 1087 | 1) 1088 | if [ ${check_xray} -eq 0 ]; then 1089 | yellow "Xray-2go 已经安装!" 1090 | else 1091 | install_caddy 1092 | manage_packages install jq unzip iptables openssl coreutils lsof 1093 | install_xray 1094 | 1095 | if [ -x "$(command -v systemctl)" ]; then 1096 | main_systemd_services 1097 | elif [ -x "$(command -v rc-update)" ]; then 1098 | alpine_openrc_services 1099 | change_hosts 1100 | rc-service xray restart 1101 | rc-service tunnel restart 1102 | else 1103 | echo "Unsupported init system" 1104 | exit 1 1105 | fi 1106 | 1107 | sleep 3 1108 | get_info 1109 | add_caddy_conf 1110 | create_shortcut 1111 | fi 1112 | ;; 1113 | 2) uninstall_xray ;; 1114 | 3) manage_xray ;; 1115 | 4) manage_argo ;; 1116 | 5) check_nodes ;; 1117 | 6) change_config ;; 1118 | 7) disable_open_sub ;; 1119 | 8) clear && curl -fsSL https://raw.githubusercontent.com/eooce/ssh_tool/main/ssh_tool.sh -o ssh_tool.sh && chmod +x ssh_tool.sh && ./ssh_tool.sh ;; 1120 | 9) clear && bash <(curl -Ls https://raw.githubusercontent.com/eooce/sing-box/main/sing-box.sh) ;; 1121 | 0) exit 0 ;; 1122 | *) red "无效的选项,请输入 0 到 9" ;; 1123 | esac 1124 | read -n 1 -s -r -p $'\033[1;91m按任意键继续...\033[0m' 1125 | done 1126 | } 1127 | menu 1128 | --------------------------------------------------------------------------------