Skip to content

Commit 292c22a

Browse files
committed
release: Add openwrt packages
1 parent a66772f commit 292c22a

File tree

8 files changed

+213
-19
lines changed

8 files changed

+213
-19
lines changed

.fpm_openwrt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-s dir
2+
--name sing-box
3+
--category net
4+
--license GPL-3.0-or-later
5+
--description "The universal proxy platform."
6+
--url "https://sing-box.sagernet.org/"
7+
--maintainer "nekohasekai <[email protected]>"
8+
9+
--config-files /etc/config/sing-box
10+
--config-files /etc/sing-box/config.json
11+
12+
--depends ca-bundle
13+
--depends kmod-inet-diag
14+
--depends kmod-tun
15+
--depends firewall4
16+
17+
--after-install release/config/openwrt.postinst
18+
--before-remove release/config/openwrt.prerm
19+
20+
release/config/config.json=/etc/sing-box/config.json
21+
22+
release/config/openwrt.conf=/etc/config/sing-box
23+
release/config/openwrt.init=/etc/init.d/sing-box
24+
release/config/openwrt.keep=/lib/upgrade/keep.d/sing-box
25+
26+
release/completions/sing-box.bash=/usr/share/bash-completion/completions/sing-box.bash
27+
release/completions/sing-box.fish=/usr/share/fish/vendor_completions.d/sing-box.fish
28+
release/completions/sing-box.zsh=/usr/share/zsh/site-functions/_sing-box
29+
30+
LICENSE=/usr/share/licenses/sing-box/LICENSE

.fpm renamed to .fpm_systemd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-s dir
22
--name sing-box
33
--category net
4-
--license GPLv3-or-later
4+
--license GPL-3.0-or-later
55
--description "The universal proxy platform."
66
--url "https://sing-box.sagernet.org/"
77
--maintainer "nekohasekai <[email protected]>"

.github/deb2ipk.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# mod from https://gist.github.com/pldubouilh/c5703052986bfdd404005951dee54683
3+
4+
set -e -o pipefail
5+
6+
PROJECT=$(dirname "$0")/../..
7+
TMP_PATH=`mktemp -d`
8+
cp $2 $TMP_PATH
9+
pushd $TMP_PATH
10+
11+
DEB_NAME=`ls *.deb`
12+
ar x $DEB_NAME
13+
14+
mkdir control
15+
pushd control
16+
tar xf ../control.tar.gz
17+
rm md5sums
18+
sed "s/Architecture:\\ \w*/Architecture:\\ $1/g" ./control -i
19+
cat control
20+
tar czf ../control.tar.gz ./*
21+
popd
22+
23+
mkdir data
24+
pushd data
25+
tar xf ../data.tar.gz
26+
rm -r usr/share/doc
27+
tar czf ../data.tar.gz ./*
28+
popd
29+
30+
DEB_NAME=${DEB_NAME%.deb}
31+
tar czf $DEB_NAME.ipk control.tar.gz data.tar.gz debian-binary
32+
popd
33+
34+
cp $TMP_PATH/$DEB_NAME.ipk $3
35+
rm -r $TMP_PATH

.github/workflows/build.yml

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,23 @@ jobs:
7272
arch: [ "386", amd64, arm64 ]
7373
legacy_go: [ false ]
7474
include:
75-
- { os: linux, arch: amd64, debian: amd64, rpm: x86_64, pacman: x86_64 }
76-
- { os: linux, arch: "386", debian: i386, rpm: i386 }
77-
- { os: linux, arch: arm, goarm: "6", debian: armel, rpm: armv6hl }
78-
- { os: linux, arch: arm, goarm: "7", debian: armhf, rpm: armv7hl, pacman: armv7hl }
79-
- { os: linux, arch: arm64, debian: arm64, rpm: aarch64, pacman: aarch64 }
80-
- { os: linux, arch: mips64le, debian: mips64el, rpm: mips64el }
81-
- { os: linux, arch: mipsle, debian: mipsel, rpm: mipsel }
75+
- { os: linux, arch: amd64, debian: amd64, rpm: x86_64, pacman: x86_64, openwrt: "x86_64" }
76+
- { os: linux, arch: "386", go386: sse2, debian: i386, rpm: i386, openwrt: "i386_pentium4" }
77+
- { os: linux, arch: "386", go386: softfloat, openwrt: "i386_pentium-mmx" }
78+
- { os: linux, arch: arm, goarm: "5", openwrt: "arm_arm926ej-s arm_cortex-a7 arm_cortex-a9 arm_fa526 arm_xscale" }
79+
- { os: linux, arch: arm, goarm: "6", debian: armel, rpm: armv6hl, openwrt: "arm_arm1176jzf-s_vfp" }
80+
- { os: linux, arch: arm, goarm: "7", debian: armhf, rpm: armv7hl, pacman: armv7hl, openwrt: "arm_cortex-a5_vfpv4 arm_cortex-a7_neon-vfpv4 arm_cortex-a7_vfpv4 arm_cortex-a8_vfpv3 arm_cortex-a9_neon arm_cortex-a9_vfpv3-d16 arm_cortex-a15_neon-vfpv4" }
81+
- { os: linux, arch: arm64, debian: arm64, rpm: aarch64, pacman: aarch64, openwrt: "aarch64_cortex-a53 aarch64_cortex-a72 aarch64_cortex-a76 aarch64_generic" }
82+
- { os: linux, arch: mips, gomips: softfloat, openwrt: "mips_24kc mips_4kec mips_mips32" }
83+
- { os: linux, arch: mipsle, gomips: hardfloat, debian: mipsel, rpm: mipsel, openwrt: "mipsel_24kc_24kf" }
84+
- { os: linux, arch: mipsle, gomips: softfloat, openwrt: "mipsel_24kc mipsel_74kc mipsel_mips32" }
85+
- { os: linux, arch: mips64, gomips: softfloat, openwrt: "mips64_mips64r2 mips64_octeonplus" }
86+
- { os: linux, arch: mips64le, gomips: hardfloat, debian: mips64el, rpm: mips64el }
87+
- { os: linux, arch: mips64le, gomips: softfloat, openwrt: "mips64el_mips64r2" }
8288
- { os: linux, arch: s390x, debian: s390x, rpm: s390x }
8389
- { os: linux, arch: ppc64le, debian: ppc64el, rpm: ppc64le }
84-
- { os: linux, arch: riscv64, debian: riscv64, rpm: riscv64 }
85-
- { os: linux, arch: loong64, debian: loongarch64, rpm: loongarch64 }
90+
- { os: linux, arch: riscv64, debian: riscv64, rpm: riscv64, openwrt: "riscv64_generic" }
91+
- { os: linux, arch: loong64, debian: loongarch64, rpm: loongarch64, openwrt: "loongarch64_generic" }
8692

8793
- { os: windows, arch: "386", legacy_go: true }
8894
- { os: windows, arch: amd64, legacy_go: true }
@@ -147,7 +153,10 @@ jobs:
147153
CGO_ENABLED: "0"
148154
GOOS: ${{ matrix.os }}
149155
GOARCH: ${{ matrix.arch }}
156+
GO386: ${{ matrix.go386 }}
150157
GOARM: ${{ matrix.goarm }}
158+
GOMIPS: ${{ matrix.gomips }}
159+
GOMIPS64: ${{ matrix.gomips }}
151160
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152161
- name: Build Android
153162
if: matrix.os == 'android'
@@ -167,12 +176,17 @@ jobs:
167176
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168177
- name: Set name
169178
run: |-
170-
ARM_VERSION=$([ -n '${{ matrix.goarm}}' ] && echo 'v${{ matrix.goarm}}' || true)
171-
LEGACY=$([ '${{ matrix.legacy_go }}' = 'true' ] && echo "-legacy" || true)
172-
DIR_NAME="sing-box-${{ needs.calculate_version.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }}${ARM_VERSION}${LEGACY}"
173-
PKG_NAME="sing-box_${{ needs.calculate_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}${ARM_VERSION}"
179+
DIR_NAME="sing-box-${{ needs.calculate_version.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }}"
180+
if [[ -n "${{ matrix.goarm }}" ]]; then
181+
DIR_NAME="${DIR_NAME}v${{ matrix.goarm }}"
182+
elif [[ -n "${{ matrix.go386 }}" && "${{ matrix.go386 }}" != 'sse2' ]]; then
183+
DIR_NAME="${DIR_NAME}-${{ matrix.go386 }}"
184+
elif [[ -n "${{ matrix.gomips }}" && "${{ matrix.gomips }}" != 'hardfloat' ]]; then
185+
DIR_NAME="${DIR_NAME}-${{ matrix.gomips }}"
186+
elif [[ "${{ matrix.legacy_go }}" == 'true' ]]; then
187+
DIR_NAME="${DIR_NAME}-legacy"
188+
fi
174189
echo "DIR_NAME=${DIR_NAME}" >> "${GITHUB_ENV}"
175-
echo "PKG_NAME=${PKG_NAME}" >> "${GITHUB_ENV}"
176190
PKG_VERSION="${{ needs.calculate_version.outputs.version }}"
177191
PKG_VERSION="${PKG_VERSION//-/\~}"
178192
echo "PKG_VERSION=${PKG_VERSION}" >> "${GITHUB_ENV}"
@@ -182,9 +196,10 @@ jobs:
182196
set -xeuo pipefail
183197
sudo gem install fpm
184198
sudo apt-get install -y debsigs
199+
cp .fpm_systemd .fpm
185200
fpm -t deb \
186201
-v "$PKG_VERSION" \
187-
-p "dist/${PKG_NAME}.deb" \
202+
-p "dist/sing-box_${{ needs.calculate_version.outputs.version }}_${{ matrix.os }}_${{ matrix.debian }}.deb" \
188203
--architecture ${{ matrix.debian }} \
189204
dist/sing-box=/usr/bin/sing-box
190205
curl -Lo '/tmp/debsigs.diff' 'https://gitlab.com/debsigs/debsigs/-/commit/160138f5de1ec110376d3c807b60a37388bc7c90.diff'
@@ -199,9 +214,10 @@ jobs:
199214
run: |-
200215
set -xeuo pipefail
201216
sudo gem install fpm
217+
cp .fpm_systemd .fpm
202218
fpm -t rpm \
203219
-v "$PKG_VERSION" \
204-
-p "dist/${PKG_NAME}.rpm" \
220+
-p "dist/sing-box_${{ needs.calculate_version.outputs.version }}_${{ matrix.os }}_${{ matrix.rpm }}.rpm" \
205221
--architecture ${{ matrix.rpm }} \
206222
dist/sing-box=/usr/bin/sing-box
207223
cat > $HOME/.rpmmacros <<EOF
@@ -218,11 +234,27 @@ jobs:
218234
set -xeuo pipefail
219235
sudo gem install fpm
220236
sudo apt-get install -y libarchive-tools
237+
cp .fpm_systemd .fpm
221238
fpm -t pacman \
222239
-v "$PKG_VERSION" \
223-
-p "dist/${PKG_NAME}.pkg.tar.zst" \
240+
-p "dist/sing-box_${{ needs.calculate_version.outputs.version }}_${{ matrix.os }}_${{ matrix.pacman }}.pkg.tar.zst" \
224241
--architecture ${{ matrix.pacman }} \
225242
dist/sing-box=/usr/bin/sing-box
243+
- name: Package OpenWrt
244+
if: matrix.openwrt != ''
245+
run: |-
246+
set -xeuo pipefail
247+
sudo gem install fpm
248+
cp .fpm_openwrt .fpm
249+
fpm -t deb \
250+
-v "$PKG_VERSION" \
251+
-p "dist/openwrt.deb" \
252+
--architecture all \
253+
dist/sing-box=/usr/bin/sing-box
254+
for architecture in ${{ matrix.openwrt }}; do
255+
.github/deb2ipk.sh "$architecture" "dist/openwrt.deb" "dist/sing-box_${{ needs.calculate_version.outputs.version }}_openwrt_${architecture}.ipk"
256+
done
257+
rm "dist/openwrt.deb"
226258
- name: Archive
227259
run: |
228260
set -xeuo pipefail
@@ -242,7 +274,7 @@ jobs:
242274
- name: Upload artifact
243275
uses: actions/upload-artifact@v4
244276
with:
245-
name: binary-${{ matrix.os }}_${{ matrix.arch }}${{ matrix.goarm && format('v{0}', matrix.goarm) }}${{ matrix.legacy_go && '-legacy' || '' }}
277+
name: binary-${{ matrix.os }}_${{ matrix.arch }}${{ matrix.goarm && format('v{0}', matrix.goarm) }}${{ matrix.go386 && format('_{0}', matrix.go386) }}${{ matrix.gomips && format('_{0}', matrix.gomips) }}${{ matrix.legacy_go && '-legacy' || '' }}
246278
path: "dist"
247279
build_android:
248280
name: Build Android

docs/installation/tools/install.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
set -xeuo pipefail
4+
5+
download_beta=false
6+
download_version=""
7+
8+
for arg in "$@"; do
9+
if [[ "$arg" == "--beta" ]]; then
10+
download_beta=true
11+
elif [[ "$arg" == "--version" ]]; then
12+
download_version=true
13+
elif [[ "$download_version" == 'true' ]]; then
14+
download_version="$arg"
15+
else
16+
echo "Unknown argument: $arg"
17+
echo "Usage: $0 [--beta] [--version <version>]"
18+
exit 1
19+
fi
20+
done
21+
22+
if [[ $(command -v dpkg) ]]; then
23+
os="linux"
24+
arch=$(dpkg --print-architecture)
25+
package_suffix=".deb"
26+
package_install="dpkg -i"
27+
elif [[ $(command -v dnf) ]]; then
28+
os="linux"
29+
arch=$(uname -m)
30+
package_suffix=".rpm"
31+
package_install="dnf install -y"
32+
elif [[ $(command -v rpm) ]]; then
33+
os="linux"
34+
arch=$(uname -m)
35+
package_suffix=".rpm"
36+
package_install="rpm -i"
37+
elif [[ $(command -v pacman) ]]; then
38+
os="linux"
39+
arch=$(uname -m)
40+
package_suffix=".pkg.tar.zst"
41+
package_install="pacman -U --noconfirm"
42+
elif [[ $(command -v opkg) ]]; then
43+
os="openwrt"
44+
source /etc/os-release
45+
arch="$OPENWRT_ARCH"
46+
package_suffix=".ipk"
47+
package_install="opkg install -y"
48+
else
49+
echo "Missing supported package manager."
50+
exit 1
51+
fi
52+
53+
if [[ -z "$download_version" ]]; then
54+
55+
header=""
56+
if [ -n "$GITHUB_TOKEN" ]; then
57+
header="-H \"Authorization: token $GITHUB_TOKEN\""
58+
fi
59+
60+
if [[ "$download_beta" != 'true' ]]; then
61+
download_version=$(curl -s --fail-with-body "$header" https://api.github.com/repos/SagerNet/sing-box/releases/latest |
62+
grep tag_name |
63+
cut -d ":" -f2 |
64+
sed 's/\"//g;s/\,//g;s/\ //g;s/v//')
65+
else
66+
download_version=$(curl -s --fail-with-body "$header" https://api.github.com/repos/SagerNet/sing-box/releases |
67+
grep tag_name |
68+
head -n 1 |
69+
cut -d ":" -f2 |
70+
sed 's/\"//g;s/\,//g;s/\ //g;s/v//')
71+
fi
72+
73+
fi
74+
75+
package_name="sing-box_${download_version}_${os}_${arch}${package_suffix}"
76+
package_url="https://github.com/SagerNet/sing-box/releases/download/v${download_version}/${package_name}"
77+
78+
echo "Downloading $package_url"
79+
curl --fail-with-body -Lo "$package_name" "$package_url"
80+
81+
if [[ $(command -v sudo) ]]; then
82+
package_install="sudo $package_install"
83+
fi
84+
85+
echo "$package_install $package_name"
86+
$package_install "$package_name"
87+
rm "$package_name"

release/config/openwrt.keep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/sing-box/

release/config/openwrt.postinst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
3+
[ -s ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
4+
. ${IPKG_INSTROOT}/lib/functions.sh
5+
default_postinst $0 $@

release/config/openwrt.prerm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
[ -s ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
3+
. ${IPKG_INSTROOT}/lib/functions.sh
4+
default_prerm $0 $@

0 commit comments

Comments
 (0)