Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/remove-driver.sh
1306 views
1
#!/bin/sh
2
3
# Purpose: Remove Realtek out-of-kernel USB WiFi adapter drivers.
4
#
5
# Supports dkms and non-dkms removals.
6
#
7
# To make this file executable:
8
#
9
# $ chmod +x remove-driver.sh
10
#
11
# To execute this file:
12
#
13
# $ sudo ./remove-driver.sh
14
#
15
# or
16
#
17
# $ sudo sh remove-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
SCRIPT_NAME="remove-driver.sh"
31
SCRIPT_VERSION="20230226"
32
MODULE_NAME="8814au"
33
DRV_VERSION="5.8.5.1"
34
35
KARCH="$(uname -m)"
36
KVER="$(uname -r)"
37
MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/"
38
39
DRV_NAME="rtl${MODULE_NAME}"
40
OPTIONS_FILE="${MODULE_NAME}.conf"
41
42
# check to ensure sudo was used to start the script
43
if [ "$(id -u)" -ne 0 ]; then
44
echo "You must run this script with superuser (root) privileges."
45
echo "Try: \"sudo ./${SCRIPT_NAME}\""
46
exit 1
47
fi
48
49
# support for the NoPrompt option allows non-interactive use of this script
50
NO_PROMPT=0
51
# get the script options
52
while [ $# -gt 0 ]; do
53
case $1 in
54
NoPrompt)
55
NO_PROMPT=1 ;;
56
*h|*help|*)
57
echo "Syntax $0 <NoPrompt>"
58
echo " NoPrompt - noninteractive mode"
59
echo " -h|--help - Show help"
60
exit 1
61
;;
62
esac
63
shift
64
done
65
66
echo ": ---------------------------"
67
68
# displays script name and version
69
echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}"
70
71
# information that helps with bug reports
72
73
# display architecture
74
echo ": ${KARCH} (architecture)"
75
76
# display kernel version
77
echo ": ${KVER} (kernel version)"
78
79
echo ": ---------------------------"
80
echo
81
82
# check for and remove non-dkms installations
83
# standard naming
84
if [ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]; then
85
echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko"
86
rm -f "${MODDESTDIR}"${MODULE_NAME}.ko
87
/sbin/depmod -a "${KVER}"
88
fi
89
90
# check for and remove non-dkms installations
91
# with rtl added to module name (PClinuxOS)
92
if [ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]; then
93
echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko"
94
rm -f "${MODDESTDIR}"rtl${MODULE_NAME}.ko
95
/sbin/depmod -a "${KVER}"
96
fi
97
98
# check for and remove non-dkms installations
99
# with compressed module in a unique non-standard location (Armbian)
100
# Example: /usr/lib/modules/5.15.80-rockchip64/kernel/drivers/net/wireless/rtl8821cu/8821cu.ko.xz
101
# Dear Armbiam, this is a really bad idea.
102
if [ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]; then
103
echo "Removing a non-dkms installation: /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz"
104
rm -f /usr/lib/modules/"${KVER}"/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz
105
/sbin/depmod -a "${KVER}"
106
fi
107
108
# determine if dkms is installed and run the appropriate routines
109
if command -v dkms >/dev/null 2>&1; then
110
echo "Removing a dkms installation."
111
# 2>/dev/null suppresses the output of dkms
112
dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all 2>/dev/null
113
RESULT=$?
114
#echo "Result=${RESULT}"
115
116
# RESULT will be 3 if there are no instances of module to remove
117
# however we still need to remove various files or the install script
118
# may complain.
119
if [ "$RESULT" = "0" ] || [ "$RESULT" = "3" ]; then
120
if [ "$RESULT" = "0" ]; then
121
echo "${DRV_NAME}/${DRV_VERSION} has been removed"
122
fi
123
else
124
echo "An error occurred. dkms remove error: ${RESULT}"
125
echo "Please report this error."
126
exit $RESULT
127
fi
128
fi
129
130
echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d"
131
rm -f /etc/modprobe.d/${OPTIONS_FILE}
132
echo "Removing source files from /usr/src/${DRV_NAME}-${DRV_VERSION}"
133
rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION}
134
make clean >/dev/null 2>&1
135
echo "The driver was removed successfully."
136
echo "You may now delete the driver directory if desired."
137
echo ": ---------------------------"
138
echo
139
140
# if NoPrompt is not used, ask user some questions
141
if [ $NO_PROMPT -ne 1 ]; then
142
printf "Do you want to reboot now? (recommended) [Y/n] "
143
read -r yn
144
case "$yn" in
145
[nN]) ;;
146
*) reboot ;;
147
esac
148
fi
149
150