-
Notifications
You must be signed in to change notification settings - Fork 25
/
dkms_install.sh
executable file
·128 lines (101 loc) · 2.89 KB
/
dkms_install.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
#!/bin/sh
echo "Please refer to https://github.com/KozakaiAya/TCP_BBR/tree/master/code for available BBR variants"
if [ $(id -u) -ne 0 ]; then
echo "Cowardly refuse to continue without root permission"
exit 1
fi
read -p "Enter desired kernel version (4.15, 5.4, etc.): " kernel_ver
read -p "Enter BBR variant (bbr, tsunami, tsunamio, etc.): " algo
prefix=bbr
mkdir -p $prefix
cd $prefix
bbr_file=tcp_$algo
bbr_src=$bbr_file.c
bbr_obj=$bbr_file.o
mkdir -p src
cd src
wget -O ./$bbr_src https://raw.githubusercontent.com/KozakaiAya/TCP_BBR/master/code/v$kernel_ver/$bbr_src
if [ ! $? -eq 0 ]; then
echo "Download Error"
cd ../..
rm -rf $prefix
exit 1
fi
echo "===== Succussfully downloaded $bbr_src ====="
# Create Makefile
cat > ./Makefile << EOF
obj-m:=$bbr_obj
default:
make -C /lib/modules/\$(shell uname -r)/build M=\$(PWD)/src modules
clean:
-rm modules.order
-rm Module.symvers
-rm .[!.]* ..?*
-rm $bbr_file.mod
-rm $bbr_file.mod.c
-rm *.o
-rm *.cmd
EOF
# Create dkms.conf
cd ..
cat > ./dkms.conf << EOF
MAKE="'make' -C src/"
CLEAN="make -C src/ clean"
BUILT_MODULE_NAME=$bbr_file
BUILT_MODULE_LOCATION=src/
DEST_MODULE_LOCATION=/updates/net/ipv4
PACKAGE_NAME=$algo
PACKAGE_VERSION=$kernel_ver
REMAKE_INITRD=yes
EOF
# Start dkms install
echo "===== Start installation ====="
cp -R . /usr/src/$algo-$kernel_ver
dkms add -m $algo -v $kernel_ver
if [ ! $? -eq 0 ]; then
echo "DKMS add failed"
dkms remove -m $algo/$kernel_ver --all
exit 1
fi
dkms build -m $algo -v $kernel_ver
if [ ! $? -eq 0 ]; then
echo "DKMS build failed"
dkms remove -m $algo/$kernel_ver --all
exit 1
fi
dkms install -m $algo -v $kernel_ver
if [ ! $? -eq 0 ]; then
echo "DKMS install failed"
dkms remove -m $algo/$kernel_ver --all
exit 1
fi
# Test loading module
modprobe $bbr_file
if [ ! $? -eq 0 ]; then
echo "modprobe failed, please check your environment"
echo "Please use \"dkms remove -m $algo/$kernel_ver --all\" to remove the dkms module"
exit 1
fi
sysctl -w net.core.default_qdisc=fq
if [ ! $? -eq 0 ]; then
echo "sysctl test failed, please check your environment"
echo "Please use \"dkms remove -m $algo/$kernel_ver --all\" to remove the dkms module"
exit 1
fi
sysctl -w net.ipv4.tcp_congestion_control=$algo
if [ ! $? -eq 0 ]; then
echo "sysctl test failed, please check your environment"
echo "Please use \"dkms remove -m $algo/$kernel_ver --all\" to remove the dkms module"
exit 1
fi
# Auto-load kernel module at system startup
echo $bbr_file | sudo tee -a /etc/modules
echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control = $algo" >> /etc/sysctl.conf
sysctl -p
if [ ! $? -eq 0 ]; then
echo "sysctl failed, please check your environment"
echo "Please use \"dkms remove -m $algo/$kernel_ver --all\" to remove the dkms module"
exit 1
fi
echo "===== Installation succeeded, enjoy! ====="