diff --git a/xu1 b/xu1 index 64a5b55..219e220 100644 --- a/xu1 +++ b/xu1 @@ -1,14 +1,12 @@ #!/bin/bash # ========================================== -# 标题:X-UI 终极自动安装脚本 (咸V咆哮多线程防拦截版) +# 标题:X-UI 终极自动安装脚本 (咸V咆哮极限防卡死版) # 特性: -# 1. 纯直链下载,彻底摆脱 GitHub 访问限制 -# 2. 引入 Aria2 & Axel 极速多线程下载,伪装 Chrome 绕过防盗链拦截 -# 3. 智能文件大小校验,彻底杜绝 154B 微型假网页报错 -# 4. 双模式安装,自定义库自动附加安全随机路径防探测 -# 5. 完美集成官方 Let's Encrypt SSL 申请 (IP/域名) -# 6. 自动开启 BBR 加速与系统环境优化清理 +# 1. 10秒极限超时熔断机制,连不上瞬间切换,绝不挂机死等。 +# 2. 强制全网 IPv4 协议,解决 IPv6 路由黑洞导致的无响应。 +# 3. 直链 + GitHub 公益镜像节点双源自动灾备切换。 +# 4. 引入智能文件校验,彻底防 154B 假页面拦截。 # ========================================== # --- 颜色配置 --- @@ -19,64 +17,66 @@ Blue="\033[36m" Font="\033[0m" # --- 核心配置 --- -# 配置二的自定义数据库链接 DB_URL="https://git.77582585.xyz/3344/dock/releases/download/3xui1/1.db" -# 配置二的专属授权码 PRIVATE_AUTH_CODE="7758258" INSTALL_PATH="/usr/local/x-ui" DB_PATH="/etc/x-ui/x-ui.db" -# 强制伪装的浏览器 User-Agent FAKE_UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" -# 检查 root 权限 [[ $EUID -ne 0 ]] && echo -e "${Red}错误:请使用 root 权限运行此脚本!${Font}" && exit 1 -# 随机字符串生成器 gen_random_string() { local length="$1" echo $(LC_ALL=C tr -dc 'a-zA-Z0-9' 方案一:调用 Aria2 (4线程) 极速下载引擎...${Font}" + echo -e "${Yellow} -> 方案一:Aria2 (强制IPv4/10秒熔断)...${Font}" if command -v aria2c >/dev/null; then - aria2c -x 4 -s 4 -k 1M --user-agent="$FAKE_UA" --allow-overwrite=true --dir="$(dirname "$file")" --out="$(basename "$file")" "$url" >/dev/null 2>&1 + aria2c -x 4 -s 4 -k 1M --connect-timeout=10 --timeout=10 --max-tries=2 --disable-ipv6=true --user-agent="$FAKE_UA" --allow-overwrite=true --dir="$(dirname "$file")" --out="$(basename "$file")" "$url" >/dev/null 2>&1 check_file_valid && return 0 fi - echo -e "${Yellow} -> 方案二:调用 Axel (4线程) 轻量级加速引擎...${Font}" + echo -e "${Yellow} -> 方案二:Axel (强制IPv4/10秒熔断)...${Font}" if command -v axel >/dev/null; then - axel -n 4 -U "$FAKE_UA" -o "$file" "$url" >/dev/null 2>&1 + axel -4 -n 4 -T 10 -U "$FAKE_UA" -o "$file" "$url" >/dev/null 2>&1 check_file_valid && return 0 fi - echo -e "${Yellow} -> 方案三:退回 Wget (强制伪装浏览器) 单线程兜底...${Font}" - wget --no-check-certificate --user-agent="$FAKE_UA" --timeout=30 --tries=3 -O "$file" "$url" >/dev/null 2>&1 + echo -e "${Yellow} -> 方案三:Wget (强制IPv4/单线程兜底)...${Font}" + wget -4 --no-check-certificate --user-agent="$FAKE_UA" -T 15 -t 2 -O "$file" "$url" >/dev/null 2>&1 check_file_valid && return 0 - echo -e "${Yellow} -> 方案四:Curl (强制 HTTP/1.1 降级) 终极兜底...${Font}" - curl --http1.1 -L -k -A "$FAKE_UA" --connect-timeout 30 --retry 3 -o "$file" "$url" >/dev/null 2>&1 + echo -e "${Yellow} -> 方案四:Curl (强制HTTP1.1降级)...${Font}" + curl -4 --http1.1 -L -k -A "$FAKE_UA" --connect-timeout 10 -m 30 --retry 2 -o "$file" "$url" >/dev/null 2>&1 check_file_valid && return 0 + # 终极备用节点切换 + if [[ -n "$fallback_url" ]]; then + echo -e "${Red}!! 警告:直链节点全军覆没!启用方案五:GitHub 加速镜像池兜底 !!${Font}" + wget -4 --no-check-certificate --user-agent="$FAKE_UA" -T 20 -t 3 -O "$file" "$fallback_url" >/dev/null 2>&1 + check_file_valid && return 0 + fi + return 1 } @@ -124,9 +124,9 @@ else fi # ========================================== -# 步骤 2:安装基础依赖与多线程工具 +# 步骤 2:安装基础依赖 # ========================================== -echo -e "${Yellow}>> [2/7] 正在安装多线程下载器与必备依赖 (aria2, axel, sqlite3...)${Font}" +echo -e "${Yellow}>> [2/7] 正在安装极速下载器与必备依赖...${Font}" if command -v apt-get >/dev/null; then apt-get update -y -q >/dev/null 2>&1 apt-get install -y -q aria2 axel wget curl tar tzdata socat ca-certificates sqlite3 bc >/dev/null 2>&1 @@ -139,12 +139,13 @@ SERVER_IP=$(curl -s4m5 api.ipify.org) [[ -z "$SERVER_IP" ]] && SERVER_IP=$(curl -s6m5 api64.ipify.org) # ========================================== -# 步骤 3:架构匹配与多线程直链下载 +# 步骤 3:架构匹配与多源拉取 # ========================================== echo -e "${Yellow}>> [3/7] 识别架构并拉取核心程序...${Font}" ARCH=$(uname -m) DOWNLOAD_URL="" FILE_NAME="" +FALLBACK_URL="" # 终极备用加速源 case $ARCH in x86_64|amd64) DOWNLOAD_URL="https://git.77582585.xyz/attachments/40eeb013-5006-423f-ad74-a0541ab340f4"; FILE_NAME="x-ui-linux-amd64.tar.gz" ;; @@ -157,15 +158,17 @@ case $ARCH in *) echo -e "${Red}不支持的架构: $ARCH${Font}" && exit 1 ;; esac -echo -e "${Green}✓ 检测到架构: $ARCH,启动多重防拦截下载引擎...${Font}" +# 配置兜底镜像加速链 (当自定义直链失效时启用) +FALLBACK_URL="https://ghproxy.net/https://github.com/MHSanaei/3x-ui/releases/latest/download/${FILE_NAME}" + +echo -e "${Green}✓ 检测到架构: $ARCH,启动极速灾备下载引擎...${Font}" systemctl stop x-ui >/dev/null 2>&1 rm -rf /usr/local/x-ui mkdir -p /usr/local/ cd /usr/local/ -# 开始智能下载 -if ! download_file "$DOWNLOAD_URL" "$FILE_NAME"; then - echo -e "${Red}!! 终极下载失败:四大引擎全灭或直链失效,请检查服务器网络或链接 !!${Font}" +if ! download_file "$DOWNLOAD_URL" "$FILE_NAME" "$FALLBACK_URL"; then + echo -e "${Red}!! 终极下载彻底失败:连加速镜像池也挂了,请检查服务器是否能连接外网 !!${Font}" exit 1 fi @@ -222,12 +225,11 @@ if [ "$INSTALL_MODE" == "1" ]; then else echo -e "${Green}✓ 模式二:拉取自定义数据库...${Font}" - # 强制将下载下限调整为 10KB,因为 1.db 一般较小,防误判丢弃 rm -f "$DB_PATH" if command -v aria2c >/dev/null; then - aria2c -x 4 -s 4 --user-agent="$FAKE_UA" --allow-overwrite=true --dir="$(dirname "$DB_PATH")" --out="$(basename "$DB_PATH")" "$DB_URL" >/dev/null 2>&1 + aria2c -x 4 -s 4 --connect-timeout=10 --disable-ipv6=true --user-agent="$FAKE_UA" --allow-overwrite=true --dir="$(dirname "$DB_PATH")" --out="$(basename "$DB_PATH")" "$DB_URL" >/dev/null 2>&1 else - wget --no-check-certificate --user-agent="$FAKE_UA" --timeout=30 --tries=3 -O "$DB_PATH" "$DB_URL" >/dev/null 2>&1 + wget -4 --no-check-certificate --user-agent="$FAKE_UA" -T 15 -t 2 -O "$DB_PATH" "$DB_URL" >/dev/null 2>&1 fi if [ ! -s "$DB_PATH" ]; then @@ -265,8 +267,8 @@ echo "" echo -e "${Blue}══════════════════════════════════════════════════${Font}" echo -e "${Yellow}>> [6/7] SSL 证书安全设置 (强烈推荐配置 HTTPS)${Font}" echo -e "${Blue}══════════════════════════════════════════════════${Font}" -echo -e " 1. ${Green}使用 Let's Encrypt 申请域名证书${Font} (需提前解析域名至本机,有效期90天)" -echo -e " 2. ${Green}使用 Let's Encrypt 申请 IP 证书${Font} (自动绑定本机IP,有效期6天自动续期)" +echo -e " 1. ${Green}使用 Let's Encrypt 申请域名证书${Font} (需解析域名至本机,有效期90天)" +echo -e " 2. ${Green}使用 Let's Encrypt 申请 IP 证书${Font} (自动绑定本机IP,有效期6天自动续)" echo -e " 3. ${Red}跳过,裸奔 HTTP${Font} (极易被墙探测,不推荐)" read -rp "请选择 SSL 申请方式 [1-3]: " SSL_CHOICE @@ -276,7 +278,7 @@ if [[ "$SSL_CHOICE" == "1" || "$SSL_CHOICE" == "2" ]]; then iptables -I INPUT -p tcp --dport 80 -j ACCEPT 2>/dev/null if ! command -v ~/.acme.sh/acme.sh &>/dev/null; then - echo -e "${Yellow}>> 正在安装 acme.sh 证书申请工具...${Font}" + echo -e "${Yellow}>> 正在安装 acme.sh 证书工具...${Font}" curl -s https://get.acme.sh | sh >/dev/null 2>&1 fi