From f29a2d33758dc24549dc2605c4f2e5bde7c9ca68 Mon Sep 17 00:00:00 2001 From: Muse Date: Tue, 20 Oct 2026 00:25:31 +0800 Subject: [PATCH] =?UTF-8?q?agent-singbox:=20=E4=BC=98=E5=85=88=E4=BB=8E=20?= =?UTF-8?q?GitHub=20Release=20=E4=B8=8B=E8=BD=BD=E9=A2=84=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E4=BA=8C=E8=BF=9B=E5=88=B6=EF=BC=8C=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=86=8D=E6=BA=90=E7=A0=81=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/agent-singbox.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/scripts/agent-singbox.sh b/scripts/agent-singbox.sh index 4dac1d0..6f83537 100644 --- a/scripts/agent-singbox.sh +++ b/scripts/agent-singbox.sh @@ -14,6 +14,41 @@ if [[ -x "$target" && -x "$stats_target" && "${2:-}" != '--force' ]]; then exit 0 fi +# 优先从 GitHub Release 下载预编译二进制,免去现场编译 +# Release tag: sing-box-v1.13.21,需上传 nexusgate-sing-box-linux- 和 nexusgate-sing-box-stats-linux- +try_prebuilt() { + local arch dl_arch release_tag base_url tmp_bin tmp_stats + case "$(uname -m)" in + x86_64|amd64) dl_arch=amd64 ;; + aarch64|arm64) dl_arch=arm64 ;; + *) return 1 ;; + esac + release_tag="${NG_SINGBOX_RELEASE:-sing-box-v1.13.21}" + base_url="https://github.com/imamoxilin/NexusGate/releases/download/${release_tag}" + tmp_bin="$(mktemp /tmp/nexusgate-singbox-bin.XXXXXX)" + tmp_stats="$(mktemp /tmp/nexusgate-singbox-stats.XXXXXX)" + trap 'rm -f -- "$tmp_bin" "$tmp_stats"' RETURN + printf '尝试从 GitHub Release 下载预编译 sing-box...\n' + if curl -fL --retry 2 --connect-timeout 15 -o "$tmp_bin" "${base_url}/nexusgate-sing-box-linux-${dl_arch}" 2>/dev/null && \ + curl -fL --retry 2 --connect-timeout 15 -o "$tmp_stats" "${base_url}/nexusgate-sing-box-stats-linux-${dl_arch}" 2>/dev/null; then + chmod +x "$tmp_bin" "$tmp_stats" + # 简单验证二进制可执行 + if "$tmp_bin" version >/dev/null 2>&1; then + install -m 0755 "$tmp_bin" "${target}.next" + install -m 0755 "$tmp_stats" "${stats_target}.next" + mv -f "${target}.next" "$target" + mv -f "${stats_target}.next" "$stats_target" + printf 'sing-box 预编译版安装完成:%s\n' "$target" + return 0 + fi + fi + printf '预编译包下载失败,回退到源码编译\n' + return 1 +} +if [[ "${NG_SINGBOX_NO_PREBUILT:-}" != "1" ]]; then + try_prebuilt && exit 0 +fi + build_dir="$(mktemp -d /tmp/nexusgate-singbox.XXXXXX)" trap 'rm -rf -- "$build_dir"' EXIT # Go's module and build caches can occupy hundreds of MB indefinitely on a