-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.sh
executable file
·183 lines (148 loc) · 4.37 KB
/
build.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
#
# ~matrix
MATRIX_RTL8187_PATCH="${PWD}/rtl8187-matrix.patch"
MATRIX_BACKPORTS_V6X_PATCH="${PWD}/backports-matrix-v6.x.patch"
KALI_INJECTION_PATCH="${PWD}/kali-wifi-injection.patch"
CLEAN=0
BUILD=0
INSTALL=0
UNINSTALL=0
OS_DIST=$(lsb_release -is 2>/dev/null)
if [ -z ${OS_DIST} ]; then
echo "! Missing lsb_release ... probably wrong OS" 1>&2
exit 2
fi
if [ $EUID -ne 0 ]; then
echo "! This script must be run as root" 1>&2
exit 1
fi
function usage()
{
echo -e "> Usage $0 <options>\n\noptions:\n" \
"\t-c\t Cleanup workdir.\n" \
"\t-b\t Build rtl8187 kernel wireless driver.\n" \
"\t-i\t Install rtl8187 kernel wireless.\n" \
"\t-u\t Uninstall rtl8187 kernel wireless.\n"
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
while getopts ":cbiu" opt; do
case $opt in
c)
CLEAN=1
;;
b)
BUILD=1
;;
i)
INSTALL=1
;;
u)
UNINSTALL=1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
*)
usage
exit 0
;;
esac
done
if ([ ${INSTALL} -eq 1 ] && [ ${UNINSTALL} -eq 1 ]) ||
([ ${BUILD} -eq 1 ] && [ ${UNINSTALL} -eq 1 ]); then
echo "! Invalid arguments."
usage
exit 1
fi
if [ ${CLEAN} -eq 1 ]; then
rm -rf tmp backports.tar.xz
fi
if [ ${BUILD} -eq 1 ]; then
rm -rf tmp
if [ ! -f "backports.tar.xz" ]; then
wget -c https://cdn.kernel.org/pub/linux/kernel/projects/backports/stable/v5.15.92/backports-5.15.92-1.tar.xz -O backports.tar.xz
if [ $? -ne 0 ]; then
echo "! Failed to download backports ..."
exit 1
fi
fi
if [ ! -f "${MATRIX_RTL8187_PATCH}" ]; then
wget https://raw.githubusercontent.com/matrix/backports-rtl8187/master/rtl8187-matrix.patch -O rtl8187-matrix.patch
if [ $? -ne 0 ]; then
echo "! Failed to download rtl8187 matrix patch ..."
exit 1
fi
fi
if [ ! -f "${MATRIX_BACKPORTS_V6X_PATCH}" ]; then
wget https://raw.githubusercontent.com/matrix/backports-rtl8187/master/backports-matrix-v6.x.patch -O backports-matrix-v6.x.patch
if [ $? -ne 0 ]; then
echo "! Failed to download backports matrix v6.x patch ..."
exit 1
fi
fi
if [ ! -f "${KALI_INJECTION_PATCH}" ]; then
wget 'https://gitlab.com/kalilinux/packages/linux/raw/kali/master/debian/patches/features/all/kali-wifi-injection.patch?inline=false' -O kali-wifi-injection.patch
if [ $? -ne 0 ]; then
echo "! Failed to download wifi injection kali patch ..."
exit 1
fi
fi
mkdir -p tmp/backports
tar xJf backports.tar.xz -C tmp/backports --strip-components=1
if [ $? -ne 0 ]; then
echo "! Failed to extrack backports ..."
rm -rf backports.tar.xz
exit 1
fi
kver=$(uname -r | cut -d. -f1)
if [ ${kver} -eq 6 ]; then
cd tmp/backports && patch -p1 --dry-run < ${MATRIX_BACKPORTS_V6X_PATCH} &>/dev/null && patch -p1 < ${MATRIX_BACKPORTS_V6X_PATCH} && cd - &> /dev/null
if [ $? -ne 0 ]; then
echo "! Failed to patch backports for kernel 6.x"
exit 1
fi
fi
cd tmp/backports && \
patch -p1 --dry-run < ${MATRIX_RTL8187_PATCH} && patch -p1 < ${MATRIX_RTL8187_PATCH} && \
patch -p1 --dry-run < ${KALI_INJECTION_PATCH} && patch -p1 < ${KALI_INJECTION_PATCH} && \
make defconfig-rtl8187 && make && cd - &> /dev/null
if [ $? -ne 0 ]; then
echo "! Failed to build rtl8187 wireless driver."
exit 1
fi
cd ..
fi
if [ ${INSTALL} -eq 1 ]; then
if [ ! -d "tmp/backports" ]; then
echo "! Failed to install rtl8187 wireless driver : build dir not found."
exit 1
fi
cd tmp/backports && make modules_install
if [ $? -ne 0 ]; then
echo "! Failed to install rtl8187 wireless driver."
exit 1
fi
cd - &> /dev/null
echo -e "\n>> Backports wireless drivers have been installed correctly.\n" \
" If you want skip reboot please remove the following modules (and also those who use them) : mac80211 cfg80211\n" \
" If everything is ok you can replug your external wireless device to load the new rtl8187 driver.\n\n"
fi
if [ ${UNINSTALL} -eq 1 ]; then
if [ ! -d "tmp/backports" ]; then
echo "! Failed to uninstall rtl8187 wireless driver : build dir not found."
exit 1
fi
cd tmp/backports && make uninstall
if [ $? -ne 0 ]; then
echo "! Failed to uninstall rtl8187 wireless driver."
exit 1
fi
cd - &> /dev/null
echo -e "\n>> Backports wireless drivers have been uninstalled correctly.\n" \
" If you want skip reboot please remove the following modules (and also those who use them) : mac80211 cfg80211\n" \
" If everything is ok you can replug your external wireless device to load the old rtl8187 driver.\n\n"
fi