#!/bin/bash


bpftool cgroup detach /sys/fs/cgroup sock_ops pinned /sys/fs/bpf/bbr_switch_510 2>/dev/null  true
rm -f /sys/fs/bpf/bbr_switch_510


# install neko solution
apt install dkms -y
apt install linux-headers-$(uname -r) -y
curl -Ls https://raw.githubusercontent.com/nkeonkeo/tcp-brutal/refs/heads/master/scripts/install_dkms.sh | TERM=xterm bash
sysctl -w net.ipv4.tcp_congestion_control=brutal
sysctl -w net.ipv4.tcp_brutal_default_rate=125000000
sysctl -w net.ipv4.tcp_brutal_loss_slow_thresh=50

echo "net.ipv4.tcp_brutal_default_rate=125000000" >> /etc/sysctl.conf
echo "net.ipv4.tcp_brutal_loss_slow_thresh=50" >> /etc/sysctl.conf

sed -i 's/net.ipv4.tcp_congestion_control=htcp/net.ipv4.tcp_congestion_control=brutal/' /etc/sysctl.conf

apt install haproxy -y
curl https://gate.gaoshi.fun/patch_2026_05_13/haproxy.service > /etc/systemd/system/haproxy.service
curl https://gate.gaoshi.fun/patch_2026_05_13/haproxy_ns_eth1.cfg > /root/haproxy_ns_eth1.cfg

systemctl daemon-reload 
systemctl disable --now haproxy

# clean iptables

ip netns exec ns_eth1 iptables -F -t nat || true


systemctl start haproxy


# finalize

sed -i 's/^ip netns exec ns_eth1 iptables/#ip netns exec ns_eth1 iptables/' /root/run.sh
echo "systemctl start haproxy " >> /root/run.sh

