Files
packages/net/bsbf-resources/files/usr/sbin/bsbf-bonding
T
Chester A. Unal 8a48a6d0cb bsbf-resources: update to GIT HEAD of 2026-05-11
Update bsbf-resources to the GIT HEAD of 2026-05-11.

- Do not add more than 8 WANs with files/etc/uci-defaults/99-bsbf-bonding.
- resources-client/bsbf_bonding.nft now destroys the bsbf_bonding table
before adding it. Therefore, no need to delete the table anymore. And use
the destroy command to successfully exit even when the table doesn't exist.

Signed-off-by: Chester A. Unal <chester.a.unal@arinc9.com>
2026-05-12 08:01:35 +01:00

96 lines
2.3 KiB
Bash

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (C) 2026 Chester A. Unal <chester.a.unal@arinc9.com>
usage() {
echo "Usage: $0 --status | --enable | --disable | --uninstall"
exit 1
}
[ $# -ne 1 ] && usage
case "$1" in
--status)
for service in bsbf-mptcp xray; do
service "$service" status >/dev/null || disabled=1
done
service bsbf-bonding-nft enabled || disabled=1
[ -n "$disabled" ] && echo "disabled" && exit 1
echo "enabled"
;;
--enable)
# Source /etc/bsbf/bsbf-bonding.conf. Exit if server_ipv4, server_port,
# or uuid is empty.
. /etc/bsbf/bsbf-bonding.conf
if [ -z "$server_ipv4" ] || [ -z "$server_port" ] || [ -z "$uuid" ]; then
echo "server_ipv4, server_port, and uuid on /etc/bsbf/bsbf-bonding.conf must not be empty."
exit 1
fi
# Configure xray.
ucode -l fs -D infile="/usr/share/bsbf/xray.json" \
-D outfile="/etc/xray/config.json" \
-D addr="$server_ipv4" \
-D port="$server_port" \
-D id="$uuid" \
-e '
let j = json(fs.readfile(infile));
j.outbounds[0].settings.address = addr;
j.outbounds[0].settings.port = port;
j.outbounds[0].settings.id = id;
fs.writefile(outfile, sprintf("%.2J\n", j));'
# Flush the MPTCP endpoint table.
ip mp e f
# Enable and (re)start init.d services.
service bsbf-bonding-nft enable
service bsbf-mptcp enable
service xray enable
service bsbf-mptcp restart 2>/dev/null
service xray restart 2>/dev/null
# (Re-)add nftables rules.
nft -f /usr/share/bsbf/bsbf_bonding.nft
;;
--disable)
# Delete nftables rules.
nft destroy table bsbf_bonding
# Disable and stop init.d services.
service bsbf-bonding-nft disable
service bsbf-mptcp disable
service xray disable
service bsbf-mptcp stop 2>/dev/null
service xray stop 2>/dev/null
# Delete bsbf-mptcp files.
rm -f /run/bsbf-mptcp-*
# Flush the MPTCP endpoint table.
ip mp e f
;;
--uninstall)
# Uninstall BSBF packages.
apk del bsbf-bonding bsbf-client-web bsbf-mptcp bsbf-rate-limiting
# Delete nftables rules.
nft destroy table bsbf_bonding
# Restore xray.
rm -f /etc/xray/config.json
uci set xray.enabled.enabled='0'
uci commit
service xray restart 2>/dev/null
# Delete bsbf-mptcp files.
rm -f /run/bsbf-mptcp-*
# Flush the MPTCP endpoint table.
ip mp e f
;;
*)
usage
;;
esac