Skip to content

Instantly share code, notes, and snippets.

@chenjie
Last active August 19, 2018 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenjie/918a2d4f56c8210d4c72b1438dd3f511 to your computer and use it in GitHub Desktop.
Save chenjie/918a2d4f56c8210d4c72b1438dd3f511 to your computer and use it in GitHub Desktop.
BBR installation script translation and backup.
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================
# System Required: Debian/Ubuntu
# Description: Modified version of BBR
# Version: 1.0
# Author: 雨落无声
# Blog: https://www.zhujiboke.com
# From https://doub.io
# Translation: jellycsc (Chenjie Ni)
#=================================================
#Check Root
[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script"; exit 1; }
#Check OS
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
bit=`uname -m`
dir=`pwd`
installbbr(){
#Install GCC
apt-get update
apt-get install build-essential -y
apt-get install make gcc-4.9 -y
#Download Kernel V4.10
wget -O headers-all.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.15/linux-headers-4.10.15-041015_4.10.15-041015.201705080411_all.deb
dpkg -i headers-all.deb
if [[ ${bit} == "i386" ]]; then
wget --no-check-certificate -O headers.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.15/linux-headers-4.10.15-041015-generic_4.10.15-041015.201705080411_i386.deb
wget --no-check-certificate -O image.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.15/linux-image-4.10.15-041015-generic_4.10.15-041015.201705080411_i386.deb
elif [[ ${bit} == "x86_64" ]]; then
wget --no-check-certificate -O headers.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.15/linux-headers-4.10.15-041015-generic_4.10.15-041015.201705080411_amd64.deb
wget --no-check-certificate -O image.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.15/linux-image-4.10.15-041015-generic_4.10.15-041015.201705080411_amd64.deb
else
echo -e "No support for ${bit} !" && exit 1
fi
dpkg -i headers.deb
dpkg -i image.deb
rm -rf headers-all.deb
rm -rf headers.deb image.deb
#Uninstall Other Kernel
deb_total=`dpkg -l | grep linux-image | awk '{print $2}' | grep -v "4.10.15" | wc -l`
if [ "${deb_total}" > "1" ]; then
echo -e "Detected ${deb_total} kernels,start uninstalling..."
for((integer = 1; integer <= ${deb_total}; integer++))
do
deb_del=`dpkg -l|grep linux-image | awk '{print $2}' | grep -v "4.10.15" | head -${integer}`
echo -e "Start uninstalling ${deb_del} kernel..."
apt-get purge -y ${deb_del}
echo -e "Uninstalling ${deb_del} th kernel is complete,continue..."
done
deb_total=`dpkg -l|grep linux-image | awk '{print $2}' | grep -v "4.10.15" | wc -l`
if [ "${deb_total}" = "0" ]; then
echo -e "Kernel uninstallation is completed,continue..."
else
echo -e " Kernel uninstallation ERROR!" && exit 1
fi
else
echo -e " Kernel number error!" && exit 1
fi
#Finish Install
update-grub
echo -e "\033[42;37m[Note]\033[0m After rebooting the VPS,please re-run this script and start BBR \033[42;37m bash bbr.sh start \033[0m"
stty erase '^H' && read -p "Rebooting required, shall we reboot now? [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
echo -e "\033[41;37m[INFO]\033[0m VPS is rebooting..."
reboot
fi
}
startbbr(){
mkdir -p $dir/tsunami && cd $dir/tsunami
wget --no-check-certificate -O ./tcp_tsunami.c https://raw.githubusercontent.com/ILLKX/BBR-Mod-backup/master/tcp_tsunami.c
echo "obj-m:=tcp_tsunami.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9
insmod tcp_tsunami.ko
cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
depmod -a
modprobe tcp_tsunami
rm -rf /etc/sysctl.conf
wget -O /etc/sysctl.conf -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/YankeeBBR/master/sysctl.conf
sysctl -p
cd .. && rm -rf $dir/tsunami
echo "BBR is started successfully!"
}
action=$1
[ -z $1 ] && action=install
case "$action" in
install|start)
${action}bbr
;;
*)
echo "Wrong input !"
echo "Usage: { install | start }"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment