From 5dfd0cdbfc1cba1d504fa8a8f0746ee688be7da7 Mon Sep 17 00:00:00 2001 From: fscarmen <62703343+fscarmen@users.noreply.github.com> Date: Fri, 26 Jun 2026 23:56:41 +0800 Subject: [PATCH] fix: resolve loss of UUID when adding/removing protocols in sb -r MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: 修复 sb -r 添加或删除协议时 UUID 丢失的问题 --- docker_init.sh | 21 ++++++++++++--------- sing-box.sh | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/docker_init.sh b/docker_init.sh index ea172c0..a9e5117 100644 --- a/docker_init.sh +++ b/docker_init.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# 脚本更新日期 2026.06.05 +# 脚本更新日期 2026.06.27 set -e WORK_DIR=/sing-box @@ -8,8 +8,8 @@ SUBSCRIBE_TEMPLATE="https://raw.githubusercontent.com/fscarmen/client_template/m # 自定义字体彩色,read 函数 warning() { echo -e "\033[31m\033[01m$*\033[0m"; } # 红色 -info() { echo -e "\033[32m\033[01m$*\033[0m"; } # 绿色 -hint() { echo -e "\033[33m\033[01m$*\033[0m"; } # 黄色 +info() { echo -e "\033[32m\033[01m$*\033[0m"; } # 绿色 +hint() { echo -e "\033[33m\033[01m$*\033[0m"; } # 黄色 # 判断系统架构,以下载相应的应用 case "$ARCH" in @@ -30,13 +30,16 @@ check_latest_sing-box() { local FORCE_VERSION=$(wget --no-check-certificate --tries=2 --timeout=3 -qO- https://raw.githubusercontent.com/fscarmen/sing-box/refs/heads/main/force_version | sed 's/^[vV]//g') # 没有强制指定版本时,获取最新版本 - grep -q '.' <<< "$FORCE_VERSION" || local FORCE_VERSION=$(wget --no-check-certificate --tries=2 --timeout=3 -qO- https://api.github.com/repos/SagerNet/sing-box/releases | awk -F '["v-]' '/tag_name/{print $5}' | sort -Vr | sed -n '1p') + if grep -q '.' <<< "$FORCE_VERSION"; then + echo "$FORCE_VERSION" + return + else + local VERSION_LIST=$(wget --no-check-certificate --tries=2 --timeout=3 -qO- https://api.github.com/repos/SagerNet/sing-box/releases | sed -n '/tag_name/ s/^[ ]*//gp') + local LATEST_VERSION=$(awk -F '["v-]' '/tag_name/{print $5}' <<< "$VERSION_LIST" | sort -Vr | sed -n '1p') - # 获取最终版本号 - local VERSION=$(wget --no-check-certificate --tries=2 --timeout=3 -qO- https://api.github.com/repos/SagerNet/sing-box/releases | awk -F '["v]' -v var="tag_name.*$FORCE_VERSION" '$0 ~ var {print $5; exit}') - VERSION=${VERSION:-'1.13.0-rc.4'} - - echo "$VERSION" + # 获取最终版本号 + awk -F '["v]' -v var="tag_name.*$LATEST_VERSION" '$0 ~ var {print $5; exit}' <<< "$VERSION_LIST" + fi } # 安装 sing-box 容器 diff --git a/sing-box.sh b/sing-box.sh index 35425e4..01601fb 100644 --- a/sing-box.sh +++ b/sing-box.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # 当前脚本版本号 -VERSION='v1.3.14 (2026.06.20)' +VERSION='v1.3.14 (2026.06.27)' # Github 反代加速代理 GITHUB_PROXY=('https://hub.glowp.xyz/' 'https://proxy.vvvv.ee/') @@ -56,8 +56,8 @@ E[7]="Install dependence-list:" C[7]="安装依赖列表:" E[8]="All dependencies already exist and do not need to be installed additionally." C[8]="所有依赖已存在,不需要额外安装" -E[9]="To upgrade, press [y]. No upgrade by default:" -C[9]="升级请按 [y],默认不升级:" +E[9]="Whether to upgrade [y/N] (default is N):" +C[9]="是否升级 [y/N] (默认为 N):" E[10]="Please enter VPS IP (Default: \${SERVER_IP_DEFAULT}):" C[10]="请输入 VPS IP (默认为: \${SERVER_IP_DEFAULT}):" E[11]="Please enter the starting port number. Must be \${MIN_PORT} - \${MAX_PORT}, consecutive \${NUM} free ports are required (Default: \${START_PORT_DEFAULT}):" @@ -204,8 +204,8 @@ E[81]="Adaptive Clash / V2rayN / Throne / ShadowRocket / SFI / SFA / SFM Clients C[81]="自适应 Clash / V2rayN / Throne / ShadowRocket / SFI / SFA / SFM 客户端" E[82]="template" C[82]="模版" -E[83]="To uninstall Nginx press [y], it is not uninstalled by default:" -C[83]="如要卸载 Nginx 请按 [y],默认不卸载:" +E[83]="Whether to uninstall Nginx [y/N] (default is N):" +C[83]="是否卸载 Nginx [y/N] (默认为 N):" E[84]="Set SElinux: enforcing --> disabled" C[84]="设置 SElinux: enforcing --> disabled" E[85]="Please enter Argo Token, Argo Json or Cloudflare API\n\n [*] Token: Visit https://dash.cloudflare.com/ , Zero Trust > Networks > Connectors > Create a tunnel > Select Cloudflared\n\n [*] Json: Users can easily obtain it through the following website: https://fscarmen.cloudflare.now.cc\n\n [*] Cloudflare API: Visit https://dash.cloudflare.com/profile/api-tokens > Create Token > Create Custom Token > Add the following permissions:\n - Account > Cloudflare One Connectors: cloudflared > Edit\n - Zone > DNS > Edit\n\n - Account Resources: Include > Required Account\n - Zone Resources: Include > Specific zone > Argo Root Domain" @@ -278,8 +278,8 @@ E[118]="Please enter [Token, Json, API] value:" C[118]="请输入 [Token, Json, API] 的值:" E[119]="Using Cloudflare API to create Tunnel and handle DNS config..." C[119]="使用 Cloudflare API 创建 Tunnel 和处理 DNS 配置..." -E[120]="Found existing tunnel with the same name. Tunnel ID: \$EXISTING_TUNNEL_ID. Status: \$EXISTING_TUNNEL_STATUS. Overwrite? [y/N] (default y):" -C[120]="发现同名隧道已创建,隧道 ID: \$EXISTING_TUNNEL_ID,状态: \$EXISTING_TUNNEL_STATUS。是否覆盖? [y/N] (默认为 y):" +E[120]="Found existing tunnel with the same name. Tunnel ID: \$EXISTING_TUNNEL_ID. Status: \$EXISTING_TUNNEL_STATUS. Overwrite? [Y/n] (default is Y):" +C[120]="发现同名隧道已创建,隧道 ID: \$EXISTING_TUNNEL_ID,状态: \$EXISTING_TUNNEL_STATUS。是否覆盖? [Y/n] (默认为 Y):" E[121]="Change node configuration (sb -d)" C[121]="修改节点配置 (sb -d)" E[122]="Invalid access token. Please roll at https://dash.cloudflare.com/profile/api-tokens to re-generate." @@ -332,8 +332,8 @@ E[145]="UFW is not active. PortHopping forwarding rules were written, but you sh C[145]="UFW 未处于激活状态。PortHopping 转发规则已写入,但建议手动启用 UFW 以确保策略生效" E[146]="Failed to update UFW PortHopping forwarding rules. Please check UFW configuration files manually." C[146]="更新 UFW 的 PortHopping 转发规则失败,请手动检查 UFW 配置文件" -E[147]="Hysteria2 Realm is useful for China-back routing or machines without public inbound access. It is not recommended when the server already has a public inbound IP/port. Enable Realm? [y/N]:" -C[147]="Hysteria2 Realm 适用于回国或者没有公网入口的机器;有公网入口时不建议使用。是否启用?[y/N]:" +E[147]="Hysteria2 Realm is useful for China-back routing or machines without public inbound access. It is not recommended when the server already has a public inbound IP/port. Enable Realm? [y/N] (default is N):" +C[147]="Hysteria2 Realm 适用于回国或者没有公网入口的机器;有公网入口时不建议使用。是否启用?[y/N] (默认为 N):" E[148]="WARP-assisted hole punching is useful in strict NAT environments. When direct hole punching fails, Cloudflare WARP can provide a CF egress path to improve success. Enable it? [y/N]:" C[148]="WARP 辅助打洞(适用于 NAT 严格环境):当 NAT 类型较严格(如对称 NAT)导致直连打洞失败时,可借助 Cloudflare WARP 获取一个 CF 出口 IP 作为中转,提升打洞成功率。是否启用?[y/N]:" E[150]="Custom warp-ep outbounds rules (rules: \${CUSTOM_ROUTE_COUNT:-0})" @@ -417,7 +417,7 @@ calc_install_steps() { # 检测是否需要启用 Github CDN,如能直接连通 api.github.com,则不使用 check_cdn() { local PROXY CODE PID CMD - local _WAIT_COUNT=120 + local _WAIT_COUNT=40 local PIDS=() local API_URL='https://api.github.com/repos/SagerNet/sing-box/releases' @@ -2128,7 +2128,7 @@ get_sing_box_version() { local API_RESPONSE=$(wget --no-check-certificate --server-response --tries=2 --timeout=3 -qO- "${GH_PROXY}https://api.github.com/repos/SagerNet/sing-box/releases" 2>&1 | grep -E '^[ ]+HTTP/|tag_name') if grep -q 'HTTP.* 200' <<< "$API_RESPONSE"; then local VERSION_LATEST=$(awk -F '["v-]' '/tag_name/{print $5}' <<< "$API_RESPONSE" | sort -Vr | sed -n '1p') - local RESULT_VERSION=$(wget --no-check-certificate --tries=2 --timeout=3 -qO- ${GH_PROXY}https://api.github.com/repos/SagerNet/sing-box/releases | awk -F '["v]' -v var="tag_name.*$VERSION_LATEST" '$0 ~ var {print $5; exit}') + local RESULT_VERSION=$(awk -F '["v]' -v var="tag_name.*$VERSION_LATEST" '$0 ~ var {print $5; exit}' <<< "$API_RESPONSE") else local RESULT_VERSION="$DEFAULT_NEWEST_VERSION" fi @@ -5249,7 +5249,7 @@ change_protocols() { # 用于新节点的配置信息 if [ "${#UUID[@]}" -gt 0 ]; then - UUID_CONFIRM="${UUID[0]}" + UUID_CONFIRM="$(printf "%s\n" "${UUID[@]}" | grep -m 1 . )" elif grep -q '.' <<< "${TROJAN_PASSWORD}"; then UUID_CONFIRM="${TROJAN_PASSWORD}" else