File PKGBUILD of Package network-sing-box-master-git
# Maintainer: neycrol <330578697@qq.com>
pkgname=sing-box-master-git
_pkgname=sing-box
pkgver=1.12.12.r55.gb2316b5
pkgrel=3
pkgdesc="Sing-box (Git) with AVX2 opt, CLI wrapper, auto subconverter & Fish completion"
arch=('x86_64')
url="https://sing-box.sagernet.org/"
license=('GPL-3.0-only')
groups=('sing-box-suite') # 记得加上组名
depends=('glibc')
makedepends=('git' 'go')
optdepends=('jq: for config manipulation' 'subconverter: for subscription conversion' 'fzf: for interactive selection')
provides=('sing-box')
conflicts=('sing-box' 'sing-box-bin' 'sing-box-git')
backup=('etc/sing-box/config_template.json')
source=(
"sing-box.tar.gz"
"sing-box-wrapper.sh"
"config_template.json"
"sing-box.service"
"sing-box.fish"
"vendor.tar.gz"
)
sha256sums=('SKIP' 'SKIP' 'SKIP' 'SKIP' 'SKIP' 'SKIP')
options=('!strip' '!debug')
pkgver() {
local _ver _ts
if [[ -f "${srcdir}/sing-box.obsinfo" ]]; then
_ver=$(sed -n 's/^version: //p' "${srcdir}/sing-box.obsinfo" | head -n1)
fi
if [[ -z "$_ver" && -f "${srcdir}/._servicedata" ]]; then
_ver=$(sed -n 's/.*<param name="version">\(.*\)<\/param>.*/\1/p' "${srcdir}/._servicedata" | head -n1)
fi
if [[ -z "$_ver" && -d "${srcdir}/sing-box" ]]; then
_ts=$(find "${srcdir}/sing-box" -type f -printf '%T@\n' 2>/dev/null | sort -n | tail -n1 | cut -d. -f1)
if [[ -n "$_ts" ]]; then
_ver=$(date -u -d "@${_ts}" +%Y%m%d.%H%M%S 2>/dev/null)
fi
fi
if [[ -z "$_ver" ]]; then
_ver="${pkgver}"
fi
echo "${_ver//-/_}"
}
build() {
local _workdir="$srcdir/$_pkgname"
if [ ! -d "$_workdir" ]; then
_workdir=$(find "$srcdir" -maxdepth 1 -type d -name "${_pkgname}-*" | head -n 1)
if [ -z "$_workdir" ]; then
echo "Missing source dir for $_pkgname"
return 1
fi
mv "$_workdir" "$srcdir/$_pkgname"
_workdir="$srcdir/$_pkgname"
fi
cd "$_workdir"
rm -rf vendor
if [ -d "$srcdir/vendor" ]; then
mv "$srcdir/vendor" "$_workdir/vendor"
fi
export CGO_ENABLED=1
export GOAMD64=v3
export GOFLAGS="-mod=vendor"
local _tags=$(sed -n 's/^TAGS[[:space:]]*?=[[:space:]]*//p' Makefile)
local _ldflags="-s -w -X 'github.com/sagernet/sing-box/constant.Version=${pkgver}' -checklinkname=0"
msg2 "Building Core with AVX2..."
go build -v -trimpath -tags "$_tags" -ldflags "$_ldflags" -o sing-box-core ./cmd/sing-box
}
package() {
# 1. 核心二进制
install -Dm755 "$srcdir/$_pkgname/sing-box-core" "$pkgdir/usr/lib/sing-box/sing-box-core"
# 2. Wrapper 脚本
install -Dm755 "$srcdir/sing-box-wrapper.sh" "$pkgdir/usr/bin/sing-box"
# 3. 配置模板与目录
install -dm755 "$pkgdir/etc/sing-box"
install -Dm644 "$srcdir/config_template.json" "$pkgdir/etc/sing-box/config_template.json"
touch "$pkgdir/etc/sing-box/subscriptions"
chmod 600 "$pkgdir/etc/sing-box/subscriptions"
# 4. Systemd 服务
install -Dm644 "$srcdir/sing-box.service" "$pkgdir/usr/lib/systemd/system/sing-box.service"
# 5. Fish 补全 【新增】
install -Dm644 "$srcdir/sing-box.fish" "$pkgdir/usr/share/fish/vendor_completions.d/sing-box.fish"
# 6. 文档 License
cd "$srcdir/$_pkgname"
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}