forked from matrix/backports-rtl8187
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·153 lines (125 loc) · 3.71 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
#!/bin/bash
#
# ~matrix
MATRIX_RTL8187_PATCH="${PWD}/rtl8187-matrix.patch"
KALI_INJECTION_PATCH="${PWD}/kali-wifi-injection.patch"
CLEAN=0
BUILD=0
INSTALL=0
UNINSTALL=0
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 --no-check-certificate -c https://cdn.kernel.org/pub/linux/kernel/projects/backports/stable/v5.15.81/backports-5.15.81-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 --no-check-certificate https://raw.githubusercontent.com/xpz3/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 "${KALI_INJECTION_PATCH}" ]; then
wget --no-check-certificate '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
#Fix freeze
sed -i "s\cat $^ ;\cat ${PWD}/tmp/backports/net/wireless/certs/sforshee.hex ;\g" tmp/backports/net/wireless/Makefile
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 && sudo 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 && sudo 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