forked from AMV007/alx_dkms_installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·132 lines (123 loc) · 4.32 KB
/
setup
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
#!/bin/bash
#
# Original version by Marcel Sackermann 2017-03-06
# Patched by Markus Blatt on 2018-10-17 to support
# the patch for kernel version >= 4.18 by phonics
# from 2018-10-09
kv=$(uname -r | grep -Po '^[0-9]\.[0-9]+(\.[1-9]+)?')
IFS='.' read -ra kv_numbers <<< "$kv"
linux_dir="linux-$kv"
alx_driver_path="drivers/net/ethernet/atheros/alx"
dkms_dir="/usr/src/alx-$kv"
deb_dependencies="git patch dkms"
get_linux_source() {
if [ ! -d $linux_dir ]; then
echo "Downloading kernel source for $kv by git..."
git clone --depth 1 -b "v$kv" git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git "linux-$kv"
if [ $? != 0 ]; then
echo "git failed to download the source. Check the output for information."
exit 1
else
echo "Done"
return 0
fi
else
if [ ! -d $linux_dir/$alx_driver_path ]; then
echo "Git refuses clone into an non empty directory but '$linux_dir' exists and does not contain the driver source that should be located at '$linux_dir/$alx_driver_path'. Please delete or move the directory yourself so git may download the source."
exit 1
fi
fi
}
get_deps() {
echo "Checking dependencies..."
for i in $deb_dependencies; do
which $i > /dev/null
if [ $? != 0 ];then
if [ -f /etc/debian_version ]; then
echo "installing dependencies... ($deb_dependencies)"
sudo apt-get install $deb_dependencies -y
if [ $? != 0 ]; then
echo "Could not install dependencies. Check the output for information."
exit 1
fi
else
echo "Please make sure you have the following dependencies installed: $deb_dependencies"
exit 1
fi
fi
done
echo "Done"
return 0
}
prepare_src() {
echo "Preparing dkms module source..."
patch="000-enable-alx-wol.patch"
offset=8
# newer patch for kernel 5.16 and up
if [ "${kv_numbers[0]}" -ge 5 ] && [ "${kv_numbers[1]}" -ge 16 ]; then
echo "Using 5.16 patch..."
patch="000-enable-alx-wol-5.16.patch"
offset=6
# newer patch for kernel 5.15
if [ "${kv_numbers[0]}" -ge 5 ] && [ "${kv_numbers[1]}" -ge 15 ]; then
echo "Using 5.16 patch..."
patch="000-enable-alx-wol-5.15.patch"
offset=6
# newer patch for kernel 5.10 and up
if [ "${kv_numbers[0]}" -ge 5 ] && [ "${kv_numbers[1]}" -ge 16 ]; then
echo "Using 5.16 patch..."
patch="000-enable-alx-wol-5.16.patch"
offset=6
# newer patch for kernel 5.16 and up
elif [ "${kv_numbers[0]}" -ge 5 ] && [ "${kv_numbers[1]}" -ge 10 ]; then
echo "Using 5.10 patch..."
patch="000-enable-alx-wol-5.10.patch"
offset=6
elif [ "${kv_numbers[0]}" -ge 5 ] && [ "${kv_numbers[1]}" -ge 4 ]; then
echo "Using 5.4+ patch..."
patch="000-enable-alx-wol-5.4.x.patch"
offset=6
# newer patch for kernel 4.18 and up
elif [ "${kv_numbers[0]}" -ge 4 ] && [ "${kv_numbers[1]}" -ge 18 ] || [ "${kv_numbers[0]}" -ge 5 ] && [ "${kv_numbers[1]}" -lt 4 ]; then
echo "Using 4.18+ patch..."
patch="000-enable-alx-wol-4.18.patch"
offset=6
# newer patch for kernel 4.9 and up
elif [ "${kv_numbers[0]}" -ge 4 ] && [ "${kv_numbers[1]}" -ge 9 ] && [ "${kv_numbers[1]}" -lt 18 ]; then
echo "Using 4.9+ patch..."
patch="000-enable-alx-wol-4.9.patch"
offset=5
fi
if [ -d "$dkms_dir/src" ]; then sudo rm -Rf $dkms_dir/src; fi
sudo mkdir -p $dkms_dir/src &&
sed "s|KERNEL_VERSION|$kv|g" dkms.conf | sudo tee $dkms_dir/dkms.conf > /dev/null &&
sudo cp $linux_dir/$alx_driver_path/* $dkms_dir/src &&
sudo patch -d $dkms_dir/src -V never -r - -t -s -N -p$offset < "$patch" &&
echo "Done"
}
dkms_remove(){
if /usr/sbin/dkms status | grep alx ; then
echo "uninstalling dkms module"
sudo /usr/sbin/dkms remove alx/$kv --all
fi
}
dkms_add() {
echo "Adding dkms module alx/$kv"
sudo dkms add alx/$kv
status=$?
if [ $status != 0 ] && [ $status != 3 ]; then
echo "something went wrong. Check the output for information."
elif [ $status != 0 ]; then
if [ $status = 3 ]; then
echo "Seems the dkms module is already enabled. Don't worry about that error."
fi
echo "Done"
return 0
fi
}
get_deps && get_linux_source && prepare_src && dkms_remove && dkms_add && sudo dkms autoinstall alx/$kv && sudo update-initramfs -u
if [ "$?" != "0" ]; then
echo "!!! there is some error"
else
echo "all ok, now you may need reboot"
fi