-
Notifications
You must be signed in to change notification settings - Fork 62
/
add_turboacc.sh
executable file
·114 lines (99 loc) · 4.7 KB
/
add_turboacc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
# shellcheck disable=SC2016
trap 'rm -rf "$TMPDIR"' EXIT
TMPDIR=$(mktemp -d) || exit 1
NO_SFE=false
while [[ $# -gt 0 ]]; do
case $1 in
--no-sfe)
NO_SFE=true
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
if ! [ -d "./package" ]; then
echo "./package not found"
exit 1
fi
VERSION_NUMBER=$(sed -n '/VERSION_NUMBER:=$(if $(VERSION_NUMBER),$(VERSION_NUMBER),.*)/p' include/version.mk|sed -e 's/.*$(VERSION_NUMBER),//' -e 's/)//')
kernel_versions="$(find "./include"|sed -n '/kernel-[0-9]/p'|sed -e "s@./include/kernel-@@" |sed ':a;N;$!ba;s/\n/ /g')"
if [ -z "$kernel_versions" ]; then
echo "Error: Unable to get kernel version, script exited"
exit 1
fi
echo "kernel version: $kernel_versions, No SFE: $NO_SFE"
if [ -d "./package/turboacc" ]; then
echo "./package/turboacc already exists,delete it?[Y/N]"
read -r answer
if [[ $answer =~ ^[Yy]$ ]]; then
rm -rf "./package/turboacc"
else
echo "You selected 'No', script exited"
exit 0
fi
fi
git clone --depth=1 --single-branch https://github.com/fullcone-nat-nftables/nft-fullcone "$TMPDIR/turboacc/nft-fullcone" || exit 1
git clone --depth=1 --single-branch https://github.com/chenmozhijin/turboacc "$TMPDIR/turboacc/turboacc" || exit 1
if [[ $# = 2 ]] && [[ $1 = "update" ]]; then
mkdir -p "$TMPDIR/package"
cp -RT "$2" "$TMPDIR/package" || exit 1
echo "get the package from $2"
else
git clone --depth=1 --single-branch --branch "package" https://github.com/chenmozhijin/turboacc "$TMPDIR/package" || exit 1
fi
cp -r "$TMPDIR/turboacc/turboacc/luci-app-turboacc" "$TMPDIR/turboacc/luci-app-turboacc"
rm -rf "$TMPDIR/turboacc/turboacc"
if [ "$NO_SFE" = false ]; then
cp -r "$TMPDIR/package/shortcut-fe" "$TMPDIR/turboacc/shortcut-fe"
fi
for kernel_version in $kernel_versions ;do
patch_953_path="./target/linux/generic/hack-$kernel_version/953-net-patch-linux-kernel-to-support-shortcut-fe.patch"
patch_613_path="./target/linux/generic/pending-$kernel_version/613-netfilter_optional_tcp_window_check.patch"
if [ "$kernel_version" = "6.6" ] || [ "$kernel_version" = "6.1" ] || [ "$kernel_version" = "5.15" ]; then
patch_952_path="./target/linux/generic/hack-$kernel_version/952-add-net-conntrack-events-support-multiple-registrant.patch"
patch_952="952-add-net-conntrack-events-support-multiple-registrant.patch"
elif [ "$kernel_version" = "5.10" ]; then
patch_952_path="./target/linux/generic/hack-$kernel_version/952-net-conntrack-events-support-multiple-registrant.patch"
patch_952="952-net-conntrack-events-support-multiple-registrant.patch"
else
echo "Unsupported kernel version: $kernel_version"
exit 1
fi
for file_path in "$patch_952_path" "$patch_953_path" "$patch_613_path" ;do
if [ -a "$file_path" ]; then
echo "$file_path already exists,delete."
rm -rf "$file_path"
fi
done
cp -f "$TMPDIR/package/hack-$kernel_version/$patch_952" "$patch_952_path"
if [ "$NO_SFE" = false ]; then
cp -f "$TMPDIR/package/hack-$kernel_version/953-net-patch-linux-kernel-to-support-shortcut-fe.patch" "$patch_953_path"
cp -f "$TMPDIR/package/pending-$kernel_version/613-netfilter_optional_tcp_window_check.patch" "$patch_613_path"
fi
if ! grep -q "CONFIG_NF_CONNTRACK_CHAIN_EVENTS" "./target/linux/generic/config-$kernel_version" ; then
echo "# CONFIG_NF_CONNTRACK_CHAIN_EVENTS is not set" >> "./target/linux/generic/config-$kernel_version"
fi
if [ "$NO_SFE" = false ] && ! grep -q "CONFIG_SHORTCUT_FE" "./target/linux/generic/config-$kernel_version" ; then
echo "# CONFIG_SHORTCUT_FE is not set" >> "./target/linux/generic/config-$kernel_version"
fi
done
cp -r "$TMPDIR/turboacc" "./package/turboacc"
rm -rf ./package/libs/libnftnl ./package/network/config/firewall4 ./package/network/utils/nftables
if [[ "$VERSION_NUMBER" =~ ^22.03.* ]]; then
FIREWALL4_VERSION="7ae5e14bbd7265cc67ec870c3bb0c8e197bb7ca9"
LIBNFTNL_VERSION="1.2.1"
NFTABLES_VERSION="1.0.2"
else
FIREWALL4_VERSION=$(grep -o 'FIREWALL4_VERSION=.*' "$TMPDIR/package/version" | cut -d '=' -f 2)
LIBNFTNL_VERSION=$(grep -o 'LIBNFTNL_VERSION=.*' "$TMPDIR/package/version" | cut -d '=' -f 2)
NFTABLES_VERSION=$(grep -o 'NFTABLES_VERSION=.*' "$TMPDIR/package/version" | cut -d '=' -f 2)
fi
cp -RT "$TMPDIR/package/firewall4-$FIREWALL4_VERSION/firewall4" ./package/network/config/firewall4
cp -RT "$TMPDIR/package/libnftnl-$LIBNFTNL_VERSION/libnftnl" ./package/libs/libnftnl
cp -RT "$TMPDIR/package/nftables-$NFTABLES_VERSION/nftables" ./package/network/utils/nftables
echo "Finish"
exit 0