agent-singbox: 优先从 GitHub Release 下载预编译二进制,失败再源码编译

This commit is contained in:
Muse
2026-10-20 00:25:31 +08:00
parent 11632e74a2
commit f29a2d3375
+35
View File
@@ -14,6 +14,41 @@ if [[ -x "$target" && -x "$stats_target" && "${2:-}" != '--force' ]]; then
exit 0 exit 0
fi fi
# 优先从 GitHub Release 下载预编译二进制,免去现场编译
# Release tag: sing-box-v1.13.21,需上传 nexusgate-sing-box-linux-<arch> 和 nexusgate-sing-box-stats-linux-<arch>
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)" build_dir="$(mktemp -d /tmp/nexusgate-singbox.XXXXXX)"
trap 'rm -rf -- "$build_dir"' EXIT trap 'rm -rf -- "$build_dir"' EXIT
# Go's module and build caches can occupy hundreds of MB indefinitely on a # Go's module and build caches can occupy hundreds of MB indefinitely on a