Skip to content

Instantly share code, notes, and snippets.

@WangKaifei
Created June 4, 2018 06:43
Show Gist options
  • Save WangKaifei/37bf3df075a4a59fe3ac570397ff929a to your computer and use it in GitHub Desktop.
Save WangKaifei/37bf3df075a4a59fe3ac570397ff929a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Usage:
# curl https://raw.githubusercontent.com/linhua55/lkl_study/master/get-rinetd.sh | bash
export RINET_URL="https://github.com/linhua55/lkl_study/releases/download/v1.2/rinetd_bbr"
if [ "$(id -u)" != "0" ]; then
echo "ERROR: Please run as root"
exit 1
fi
for CMD in curl iptables grep cut xargs systemctl ip awk
do
if ! type -p ${CMD}; then
echo -e "\e[1;31mtool ${CMD} is not installed, abort.\e[0m"
exit 1
fi
done
echo -e "1. Clean up rinetd-bbr"
systemctl disable rinetd-bbr.service
killall -9 rinetd-bbr
rm -rf /usr/bin/rinetd-bbr /etc/rinetd-bbr.conf /etc/systemd/system/rinetd-bbr.service
echo "2. Download rinetd-bbr from $RINET_URL"
curl -L "${RINET_URL}" >/usr/bin/rinetd-bbr
chmod +x /usr/bin/rinetd-bbr
echo "3. Generate /etc/rinetd-bbr.conf"
read -p "Input ports you want to speed up: " PORTS </dev/tty
for d in $PORTS
do
cat <<EOF >> /etc/rinetd-bbr.conf
0.0.0.0 $d 0.0.0.0 $d
EOF
done
IFACE=$(ip -4 addr | awk '{if ($1 ~ /inet/ && $NF ~ /^[ve]/) {a=$NF}} END{print a}')
echo "4. Generate /etc/systemd/system/rinetd-bbr.service"
cat <<EOF > /etc/systemd/system/rinetd-bbr.service
[Unit]
Description=rinetd with bbr
Documentation=https://github.com/linhua55/lkl_study
[Service]
ExecStart=/usr/bin/rinetd-bbr -f -c /etc/rinetd-bbr.conf raw ${IFACE}
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
echo "4. Enable rinetd-bbr Service"
systemctl enable rinetd-bbr.service
echo "5. Start rinetd-bbr Service"
systemctl start rinetd-bbr.service
if systemctl status rinetd-bbr >/dev/null; then
echo "rinetd-bbr started."
echo "$PORTS speed up completed."
echo "vi /etc/rinetd-bbr.conf as needed."
echo "killall -9 rinetd-bbr for restart."
else
echo "rinetd-bbr failed."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment