Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/install-driver.sh
1306 views
1
#!/bin/sh
2
3
# Purpose: Install Realtek out-of-kernel USB WiFi adapter drivers.
4
#
5
# Supports dkms and non-dkms installations.
6
#
7
# To make this file executable:
8
#
9
# $ chmod +x install-driver.sh
10
#
11
# To execute this file:
12
#
13
# $ sudo ./install-driver.sh
14
#
15
# or
16
#
17
# $ sudo sh install-driver.sh
18
#
19
# Copyright(c) 2023 Nick Morrow
20
#
21
# This program is free software; you can redistribute it and/or modify
22
# it under the terms of version 2 of the GNU General Public License as
23
# published by the Free Software Foundation.
24
#
25
# This program is distributed in the hope that it will be useful, but
26
# WITHOUT ANY WARRANTY; without even the implied warranty of
27
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
# GNU General Public License for more details.
29
30
# Need to install
31
apt install debhelper dpkg-dev dkms libelf-dev bc -y
32
33
SCRIPT_NAME="install-driver.sh"
34
SCRIPT_VERSION="20230227"
35
MODULE_NAME="8814au"
36
DRV_VERSION="5.8.5.1"
37
38
KARCH="$(uname -m)"
39
KVER="$(uname -r)"
40
MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/"
41
42
DRV_NAME="rtl${MODULE_NAME}"
43
DRV_DIR="$(pwd)"
44
OPTIONS_FILE="${MODULE_NAME}.conf"
45
46
# check to ensure sudo was used to start the script
47
if [ "$(id -u)" -ne 0 ]; then
48
echo "You must run this script with superuser (root) privileges."
49
echo "Try: \"sudo ./${SCRIPT_NAME}\""
50
exit 1
51
fi
52
53
# support for the NoPrompt option allows non-interactive use of this script
54
NO_PROMPT=0
55
# get the script options
56
while [ $# -gt 0 ]
57
do
58
case $1 in
59
NoPrompt)
60
NO_PROMPT=1 ;;
61
*h|*help|*)
62
echo "Syntax $0 <NoPrompt>"
63
echo " NoPrompt - noninteractive mode"
64
echo " -h|--help - Show help"
65
exit 1
66
;;
67
esac
68
shift
69
done
70
71
# ensure /usr/sbin is in the PATH so iw can be found
72
if ! echo "$PATH" | grep -qw sbin; then
73
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
74
fi
75
76
# check to ensure gcc is installed
77
if ! command -v gcc >/dev/null 2>&1; then
78
echo "A required package is not installed."
79
echo "Please install the following package: gcc"
80
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
81
exit 1
82
fi
83
84
# check to ensure bc is installed
85
if ! command -v bc >/dev/null 2>&1; then
86
echo "A required package is not installed."
87
echo "Please install the following package: bc"
88
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
89
exit 1
90
fi
91
92
# check to ensure make is installed
93
if ! command -v make >/dev/null 2>&1; then
94
echo "A required package is not installed."
95
echo "Please install the following package: make"
96
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
97
exit 1
98
fi
99
100
# check to see if the correct header files are installed
101
if [ ! -d "/lib/modules/$(uname -r)/build" ]; then
102
echo "Your kernel header files aren't properly installed."
103
echo "Please consult your distro documentation or user support forums."
104
echo "Once the header files are properly installed, please run \"sudo ./${SCRIPT_NAME}\""
105
exit 1
106
fi
107
108
# check to ensure iw is installed
109
if ! command -v iw >/dev/null 2>&1; then
110
echo "A required package is not installed."
111
echo "Please install the following package: iw"
112
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
113
exit 1
114
fi
115
116
# check to ensure rfkill is installed
117
if ! command -v rfkill >/dev/null 2>&1; then
118
echo "A required package is not installed."
119
echo "Please install the following package: rfkill"
120
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
121
exit 1
122
fi
123
124
DEFAULT_EDITOR="$(cat default-editor.txt)"
125
# try to find the user's default text editor through the EDITORS_SEARCH array
126
for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; do
127
command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break
128
done
129
# fail if no editor was found
130
if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1; then
131
echo "No text editor found (default: ${DEFAULT_EDITOR})."
132
echo "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor.txt' to specify your editor."
133
echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\""
134
exit 1
135
fi
136
137
echo ": ---------------------------"
138
139
# displays script name and version
140
echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}"
141
142
# information that helps with bug reports
143
144
# display architecture
145
echo ": ${KARCH} (architecture)"
146
147
SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }')
148
sproc=$(nproc)
149
# avoid Out of Memory condition in low-RAM systems by limiting core usage
150
if [ "$sproc" -gt 1 ]; then
151
if [ "$SMEM" -lt 1400000 ]
152
then
153
sproc=2
154
fi
155
if [ "$SMEM" -lt 700000 ]
156
then
157
sproc=1
158
fi
159
fi
160
161
# display number of in-use processing units / total processing units
162
echo ": ${sproc}/$(nproc) (in-use/total processing units)"
163
164
# display total system memory
165
echo ": ${SMEM} (total system memory)"
166
167
# display kernel version
168
echo ": ${KVER} (kernel version)"
169
170
# display gcc version
171
gcc_ver=$(gcc --version | grep -i gcc)
172
echo ": ""${gcc_ver}"
173
174
# display dkms version if installed
175
if command -v dkms >/dev/null 2>&1; then
176
dkms_ver=$(dkms --version)
177
echo ": ""${dkms_ver}"
178
fi
179
180
# display secure mode status
181
if command -v mokutil >/dev/null 2>&1; then
182
if mokutil --sb-state | grep -i enabled >/dev/null 2>&1; then
183
echo ": SecureBoot enabled"
184
fi
185
if mokutil --sb-state | grep -i disabled >/dev/null 2>&1; then
186
echo ": SecureBoot disabled"
187
fi
188
if mokutil --sb-state | grep -i EFI >/dev/null 2>&1; then
189
echo ": EFI variables are not supported on this system"
190
fi
191
else
192
echo ": mokutil not installed"
193
fi
194
195
196
echo ": ---------------------------"
197
echo
198
199
echo "Checking for previously installed drivers."
200
201
# check for and remove non-dkms installations
202
# standard naming
203
if [ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]; then
204
echo ": ---------------------------"
205
echo
206
echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko"
207
rm -f "${MODDESTDIR}"${MODULE_NAME}.ko
208
/sbin/depmod -a "${KVER}"
209
echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d"
210
rm -f /etc/modprobe.d/${OPTIONS_FILE}
211
echo "Removing source files from /usr/src/${DRV_NAME}-${DRV_VERSION}"
212
rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION}
213
make clean >/dev/null 2>&1
214
echo "Removal complete."
215
fi
216
217
# check for and remove non-dkms installations
218
# with rtl added to module name (PClinuxOS)
219
if [ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]; then
220
echo ": ---------------------------"
221
echo
222
echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko"
223
rm -f "${MODDESTDIR}"rtl${MODULE_NAME}.ko
224
/sbin/depmod -a "${KVER}"
225
echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d"
226
rm -f /etc/modprobe.d/${OPTIONS_FILE}
227
echo "Removing source files from /usr/src/${DRV_NAME}-${DRV_VERSION}"
228
rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION}
229
make clean >/dev/null 2>&1
230
echo "Removal complete."
231
fi
232
233
# check for and remove non-dkms installations
234
# with compressed module in a unique non-standard location (Armbian)
235
# Example: /usr/lib/modules/5.15.80-rockchip64/kernel/drivers/net/wireless/rtl8821cu/8821cu.ko.xz
236
# Dear Armbiam, this is a really bad idea.
237
if [ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]; then
238
echo ": ---------------------------"
239
echo
240
echo "Removing a non-dkms installation: /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz"
241
rm -f /usr/lib/modules/"${KVER}"/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz
242
/sbin/depmod -a "${KVER}"
243
echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d"
244
rm -f /etc/modprobe.d/${OPTIONS_FILE}
245
echo "Removing source files from /usr/src/${DRV_NAME}-${DRV_VERSION}"
246
rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION}
247
make clean >/dev/null 2>&1
248
echo "Removal complete."
249
fi
250
251
# check for and remove dkms installations
252
if command -v dkms >/dev/null 2>&1; then
253
if dkms status | grep -i ${DRV_NAME}; then
254
echo ": ---------------------------"
255
echo
256
# need to add code here to delete any DRV_VERSION
257
echo "Removing a dkms installation."
258
dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all
259
echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d"
260
rm -f /etc/modprobe.d/${OPTIONS_FILE}
261
echo "Removing source files from /usr/src/${DRV_NAME}-${DRV_VERSION}"
262
rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION}
263
echo "Removal complete."
264
fi
265
fi
266
267
# sets module parameters (driver options) and blacklisted modules
268
echo ": ---------------------------"
269
echo
270
echo "Starting installation."
271
echo "Installing ${OPTIONS_FILE} to /etc/modprobe.d"
272
cp -f ${OPTIONS_FILE} /etc/modprobe.d
273
274
# determine if dkms is installed and run the appropriate installation routines
275
if ! command -v dkms >/dev/null 2>&1; then
276
echo "The non-dkms installation routines are in use."
277
278
make clean >/dev/null 2>&1
279
280
make -j"$(nproc)"
281
RESULT=$?
282
283
if [ "$RESULT" != "0" ]; then
284
echo "An error occurred: ${RESULT}"
285
echo "Please report this error."
286
echo "Please copy all screen output and paste it into the problem report."
287
echo "You will need to run the following before reattempting installation."
288
echo "$ sudo ./remove-driver.sh"
289
exit $RESULT
290
fi
291
292
# if secure boot is active, use sign-install
293
if command -v mokutil >/dev/null 2>&1; then
294
if mokutil --sb-state | grep -i enabled >/dev/null 2>&1; then
295
echo ": SecureBoot enabled - read FAQ about SecureBoot"
296
make sign-install
297
RESULT=$?
298
else
299
make install
300
RESULT=$?
301
fi
302
else
303
make install
304
RESULT=$?
305
fi
306
307
if [ "$RESULT" = "0" ]; then
308
make clean >/dev/null 2>&1
309
echo "The driver was installed successfully."
310
echo ": ---------------------------"
311
echo
312
else
313
echo "An error occurred: ${RESULT}"
314
echo "Please report this error."
315
echo "Please copy all screen output and paste it into the problem report."
316
echo "You will need to run the following before reattempting installation."
317
echo "$ sudo ./remove-driver.sh"
318
exit $RESULT
319
fi
320
else
321
echo "The dkms installation routines are in use."
322
323
# the dkms add command requires source in /usr/src/${DRV_NAME}-${DRV_VERSION}
324
echo "Copying source files to /usr/src/${DRV_NAME}-${DRV_VERSION}"
325
cp -rf "${DRV_DIR}" /usr/src/${DRV_NAME}-${DRV_VERSION}
326
327
dkms add -m ${DRV_NAME} -v ${DRV_VERSION}
328
RESULT=$?
329
330
# RESULT will be 3 if the DKMS tree already contains the same module/version
331
# combo. You cannot add the same module/version combo more than once.
332
if [ "$RESULT" != "0" ]; then
333
if [ "$RESULT" = "3" ]; then
334
echo "This driver may already be installed."
335
echo "Run the following and then reattempt installation."
336
echo "$ sudo ./remove-driver.sh"
337
exit $RESULT
338
else
339
echo "An error occurred. dkms add error: ${RESULT}"
340
echo "Please report this error."
341
echo "Please copy all screen output and paste it into the problem report."
342
echo "Run the following before reattempting installation."
343
echo "$ sudo ./remove-driver.sh"
344
exit $RESULT
345
fi
346
else
347
echo "The driver was added to dkms successfully."
348
echo ": ---------------------------"
349
fi
350
351
if command -v /usr/bin/time >/dev/null 2>&1; then
352
/usr/bin/time -f "Compile time: %U seconds" dkms build -m ${DRV_NAME} -v ${DRV_VERSION}
353
else
354
dkms build -m ${DRV_NAME} -v ${DRV_VERSION}
355
fi
356
RESULT=$?
357
358
if [ "$RESULT" != "0" ]; then
359
echo "An error occurred. dkms build error: ${RESULT}"
360
echo "Please report this error."
361
echo "Please copy all screen output and paste it into the problem report."
362
echo "Run the following before reattempting installation."
363
echo "$ sudo ./remove-driver.sh"
364
exit $RESULT
365
else
366
echo "The driver was built by dkms successfully."
367
echo ": ---------------------------"
368
fi
369
370
dkms install -m ${DRV_NAME} -v ${DRV_VERSION}
371
RESULT=$?
372
373
if [ "$RESULT" != "0" ]; then
374
echo "An error occurred. dkms install error: ${RESULT}"
375
echo "Please report this error."
376
echo "Please copy all screen output and paste it into the problem report."
377
echo "Run the following before reattempting installation."
378
echo "$ sudo ./remove-driver.sh"
379
exit $RESULT
380
else
381
echo "The driver was installed by dkms successfully."
382
echo ": ---------------------------"
383
echo
384
fi
385
fi
386
387
# provide driver upgrade information
388
echo "Info: Upgrade this driver with the following commands as needed:"
389
echo "$ git pull"
390
echo "$ sudo sh install-driver.sh"
391
echo "Note: Upgrades to this driver should be performed before distro upgrades."
392
echo "Note: Upgrades can be performed as often as you like."
393
echo "Note: Work on this driver is continuous."
394
echo ": ---------------------------"
395
echo
396
397
# unblock wifi
398
if command -v rfkill >/dev/null 2>&1; then
399
rfkill unblock wlan
400
else
401
echo "Unable to run $ rfkill unblock wlan"
402
fi
403
404
# if NoPrompt is not used, ask user some questions
405
if [ $NO_PROMPT -ne 1 ]; then
406
printf "Do you want to edit the driver options file now? (recommended) [Y/n] "
407
read -r yn
408
case "$yn" in
409
[nN]) ;;
410
*) ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} ;;
411
esac
412
413
printf "Do you want to apply the new options by rebooting now? (recommended) [Y/n] "
414
read -r yn
415
case "$yn" in
416
[nN]) ;;
417
*) reboot ;;
418
esac
419
fi
420
421