-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
bbrv3.sh
331 lines (305 loc) · 11.2 KB
/
bbrv3.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash
#
# XanMod kernel and BBRv3 Bash Script
# Author: github.com/opiran-club
#
# It provides options to install required packages, configure XanMod kernel and BBRv3
# download the appropriate configuration and program.
#
# supported architectures: x86_64, amd64
# Supported operating systems: Ubuntu 18.04/20.04/22.04 , Debian 10/11
#
# Usage:
# - Run the script with root privileges.
# - Follow the on-screen prompts to install, configure, or uninstall
#
# For more information and updates, visit github.com/opiran-club and @opiranclub on telegram.
#
# Disclaimer:
# This script comes with no warranties or guarantees. Use it at your own risk.
CYAN="\e[96m"
GREEN="\e[92m"
YELLOW="\e[93m"
RED="\e[91m"
BLUE="\e[94m"
MAGENTA="\e[95m"
NC="\e[0m"
ask_reboot() {
echo ""
echo -e "\n ${YELLOW}Reboot now? (Recommended) ${GREEN}[y/n]${NC}"
echo ""
read reboot
case "$reboot" in
[Yy])
systemctl reboot
;;
*)
return
;;
esac
exit
}
press_enter() {
echo -e "\n ${RED}Press Enter to continue... ${NC}"
read
}
# Define logo segments
logo1=" ______ _______ __ _______ __ _____ ___ "
logo2=" / \ | __ \ | \ / \ / \ \ \| \ "
logo3=" / ____ \ ( |__) ) | | | | / \ |.\ \ | "
logo4=" / / ) )| ____/ | | |_____/ ) /' /\ \ |: \ \ | "
logo5=" ( (____/ / ( / |. | // / // __' \ |. \ \.| "
logo6=" \ / / \ /\ |\ |: __ \ / / \\ \ | \ \| "
logo7=" \_____/ (_______) (__\_|_)|__| \___)(___/ \___)\___|\____\) "
logo() {
echo -e "${BLUE}${logo1:0:24}${RED}${logo1:24:19}${WHITE}${logo1:43:14}${GREEN}${logo1:57}${NC}"
echo -e "${BLUE}${logo2:0:24}${RED}${logo2:24:19}${WHITE}${logo2:43:14}${GREEN}${logo2:57}${NC}"
echo -e "${BLUE}${logo3:0:24}${RED}${logo3:24:19}${WHITE}${logo3:43:14}${GREEN}${logo3:57}${NC}"
echo -e "${BLUE}${logo4:0:24}${RED}${logo4:24:19}${WHITE}${logo4:43:14}${GREEN}${logo4:57}${NC}"
echo -e "${BLUE}${logo5:0:24}${RED}${logo5:24:19}${WHITE}${logo5:43:14}${GREEN}${logo5:57}${NC}"
echo -e "${BLUE}${logo6:0:24}${RED}${logo6:24:19}${WHITE}${logo6:43:14}${GREEN}${logo6:57}${NC}"
echo -e "${BLUE}${logo7:0:24}${RED}${logo7:24:19}${WHITE}${logo7:43:14}${GREEN}${logo7:57}${NC}"
}
if [ "$EUID" -ne 0 ]; then
echo -e "\n ${RED}This script must be run as root.${NC}"
exit 1
fi
cpu_level() {
os=""
if [ -f /etc/os-release ]; then
source /etc/os-release
case $ID in
"debian" | "ubuntu")
os="Debian/Ubuntu"
;;
"centos")
os="CentOS"
;;
"fedora")
os="Fedora"
;;
"arch")
os="Arch"
;;
*)
os="Unknown"
;;
esac
fi
cpu_support_info=$(/usr/bin/awk -f <(wget -qO - https://raw.githubusercontent.com/opiran-club/VPS-Optimizer/main/checkcpu.sh))
if [[ $cpu_support_info == "CPU supports x86-64-v"* ]]; then
cpu_support_level=${cpu_support_info#CPU supports x86-64-v}
echo -e "${MAGENTA}Current CPU Level:${GREEN} x86-64 Level $cpu_support_level${NC}"
return $cpu_support_level
else
echo -e "${RED}OS or CPU level is not supported by the XanMod kernel and cannot be installed.${NC}"
return 0
fi
}
install_xanmod() {
clear
cpu_support_info=$(/usr/bin/awk -f <(wget -qO - https://raw.githubusercontent.com/opiran-club/VPS-Optimizer/main/checkcpu.sh))
if [[ $cpu_support_info == "CPU supports x86-64-v"* ]]; then
cpu_support_level=${cpu_support_info#CPU supports x86-64-v}
echo -e "${CYAN}Current CPU Level: x86-64 Level $cpu_support_level${NC}"
else
echo -e "${RED}OS or CPU level is not supported by the XanMod kernel and cannot be installed.${NC}"
return 1
fi
echo ""
echo ""
echo -e "${YELLOW} Installing XanMod kernel${NC}"
echo ""
echo -e "${CYAN}Kernel official website: https://xanmod.org${NC}"
echo -e "${CYAN}SourceForge: https://sourceforge.net/projects/xanmod/files/releases/lts/${NC}"
echo ""
echo ""
echo -ne "${YELLOW}Do you want to continue downloading and installing the XanMod kernel? [y/n]:${NC} "
read continue
if [[ $continue == [Yy] ]]; then
echo ""
echo ""
wget -qO - https://gitlab.com/afrd.gpg | sudo gpg --dearmor -o /usr/share/keyrings/xanmod-archive-keyring.gpg
echo 'deb [signed-by=/usr/share/keyrings/xanmod-archive-keyring.gpg] http://deb.xanmod.org releases main' | sudo tee /etc/apt/sources.list.d/xanmod-release.list
temp_folder=$(mktemp -d)
cd $temp_folder
case $cpu_support_level in
1)
apt-get update
apt-get install linux-xanmod-x64v1 -y
;;
2)
apt-get update
apt-get install linux-xanmod-x64v2 -y
;;
3)
apt-get update
apt-get install linux-xanmod-x64v3 -y
;;
4)
apt-get update
apt-get install linux-xanmod-x64v4 -y
;;
*)
echo -e "${RED}Your CPU is not supported by the XanMod kernel and cannot be installed.${NC}"
return 1
;;
esac
echo -e "${GREEN}The XanMod kernel has been installed successfully.${NC}"
press_enter
sleep 0.5
clear
echo ""
echo -e "${GREEN} GRUB boot updating ${NC}"
echo ""
echo ""
echo -ne "${YELLOW}Do you need to update the GRUB boot configuration? (y/n) [Default: y]:${NC} "
read grub
case $grub in
[Yy])
update-grub
echo ""
echo -e "${GREEN}The GRUB boot configuration has been updated.${NC}"
;;
[Nn])
echo -e "${RED}It is not recommended, but the optimization has been aborted.${NC}"
;;
*)
echo -e "${RED}Invalid option, skipping GRUB boot configuration update.${NC}"
;;
esac
else
echo -e "${RED}XanMod kernel installation failed.${NC}"
fi
}
uninstall_xanmod() {
clear
current_kernel_version=$(uname -r)
if [[ $current_kernel_version == *-xanmod* ]]; then
echo -e "${CYAN}Current kernel: ${GREEN}$current_kernel_version${NC}"
echo -e "${RED}Uninstalling XanMod Kernel...${NC}"
echo ""
echo -ne "${GREEN}Do you want to uninstall the XanMod kernel and restore the original kernel? (y/n): ${NC}"
read confirm
if [[ $confirm == [yY] ]]; then
echo -e "${GREEN}Uninstalling XanMod kernel and restoring the original kernel...${NC}"
for i in $(seq 1 4); do
apt-get purge linux-xanmod-x64v$i -y
done
apt-get update
apt-get autoremove -y
update-grub
if [ $? -eq 0 ]; then
echo ""
echo -e "${GREEN}The XanMod kernel has been uninstalled, and the original kernel has been restored.${NC}"
echo -e "${GREEN}The GRUB boot configuration has been updated. Please reboot to take effect.${NC}"
else
echo ""
echo -e "${RED}XanMod kernel uninstallation failed.${NC}"
fi
else
echo ""
echo -e "${RED}Canceled the uninstall operation.${NC}"
fi
else
echo ""
echo -e "${RED}The current kernel is not the XanMod kernel, and the uninstall operation cannot be performed.${NC}"
fi
}
bbrv3() {
clear
echo ""
echo ""
echo -e "${YELLOW}Are you sure you want to optimize kernel parameters for better network performance? (y/n): ${NC}${GREEN} "
read optimize_choice
echo -e "${NC}"
case $optimize_choice in
y|Y)
clear
echo -e "${YELLOW}Backing up original kernel parameter configuration... ${NC}"
cp /etc/sysctl.conf /etc/sysctl.conf.bak
echo -e "${YELLOW}Optimizing kernel parameters for better network performance... ${NC}"
cat <<EOL >> /etc/sysctl.conf
# BBRv3 Optimization for Better Network Performance
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_congestion_control = bbr
EOL
sysctl -p
if [ $? -eq 0 ]; then
echo -e "${GREEN}Kernel parameter optimization for better network performance was successful.${NC}"
else
echo -e "${RED}Kernel parameter optimization failed. Restoring the original configuration...${NC}"
mv /etc/sysctl.conf.bak /etc/sysctl.conf
fi
;;
n|N)
echo ""
echo -e "${RED}Canceled kernel parameter optimization.${NC}"
;;
*)
echo ""
echo -e "${RED}Invalid input. Optimization canceled.${NC}"
;;
esac
}
while true; do
linux_version=$(awk -F= '/^PRETTY_NAME=/{gsub(/"/, "", $2); print $2}' /etc/os-release)
kernel_version=$(uname -r)
tg_title="https://t.me/OPIran-Official"
yt_title="youtube.com/@opiran-inistitute"
clear
logo
echo -e "\e[93m╔═══════════════════════════════════════════════╗\e[0m"
echo -e "\e[93m║ \e[96mBBRv3 using xanmod kernel \e[93m║\e[0m"
echo -e "\e[93m╠═══════════════════════════════════════════════╣\e[0m"
echo ""
echo -e "${CYAN} ${tg_title} ${NC}"
echo -e "${CYAN} ${yt_title} ${NC}"
echo ""
printf "\e[93m+-----------------------------------------------+\e[0m\n"
echo ""
echo -e "${MAGENTA}linux version Info:${GREEN}${linux_version}${NC}"
echo -e "${MAGENTA}kernel Info:${GREEN}${kernel_version}${NC}"
cpu_level
echo ""
echo -e "${RED} !! TIP !! ${NC}"
echo ""
echo -e "${CYAN}Supported OS: ${GREEN} Ubuntu / Debian ${NC}"
echo -e "${CYAN}Supported CPU level ${GREEN} [1/2/3/4] ${NC}"
echo ""
printf "\e[93m+-----------------------------------------------+\e[0m\n"
echo ""
echo -e "${GREEN} 1) ${NC} Install XanMod kernel & BBRv3 & Grub boot conf. ${NC}"
echo -e "${GREEN} 2) ${NC} Uninstall XanMod kernel and restore to default ${NC}"
echo ""
echo -e "${GREEN} E) ${NC} Exit the menu${NC}"
echo ""
echo -ne "${GREEN}Select an option: ${NC} "
read choice
case $choice in
1)
install_xanmod
bbrv3
ask_reboot
;;
2)
uninstall_xanmod
ask_reboot
;;
E|e)
echo "Exiting..."
exit 0
;;
*)
echo "Invalid choice. Please enter a valid option."
;;
esac
echo -e "\n${RED}Press Enter to continue... ${NC}"
read
done