88x2bu-20210702/remove-driver.sh

145 lines
4.2 KiB
Bash
Raw Normal View History

2023-01-27 10:16:08 -06:00
#!/bin/sh
2021-10-27 12:51:22 -05:00
# Purpose: Remove Realtek out-of-kernel USB WiFi adapter drivers.
2022-08-21 15:31:50 -05:00
#
# Supports dkms and non-dkms removals.
2023-01-27 10:16:08 -06:00
#
# To make this file executable:
#
2023-02-24 14:14:49 -06:00
# $ chmod +x remove-driver.sh
2023-01-27 10:16:08 -06:00
#
# To execute this file:
#
2023-02-24 14:14:49 -06:00
# $ sudo ./remove-driver.sh
#
# or
#
# $ sudo sh remove-driver.sh
2023-01-27 10:16:08 -06:00
#
2023-01-09 12:27:31 -06:00
# Copyright(c) 2023 Nick Morrow
2022-12-20 23:53:39 -06:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
2021-10-27 12:51:22 -05:00
SCRIPT_NAME="remove-driver.sh"
2023-01-27 10:16:08 -06:00
SCRIPT_VERSION="20230126"
MODULE_NAME="88x2bu"
2022-10-19 16:15:30 -05:00
DRV_VERSION="5.13.1"
KARCH="$(uname -m)"
2023-01-30 15:29:07 -06:00
KVER="$(uname -r)"
MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/"
2022-10-19 16:15:30 -05:00
DRV_NAME="rtl${MODULE_NAME}"
2022-12-20 23:53:39 -06:00
OPTIONS_FILE="${MODULE_NAME}.conf"
2022-10-19 16:15:30 -05:00
2023-01-27 10:16:08 -06:00
# check to ensure sudo was used to start the script
if [ "$(id -u)" -ne 0 ]; then
echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1
fi
2021-12-14 07:09:23 -06:00
# support for the NoPrompt option allows non-interactive use of this script
NO_PROMPT=0
# get the script options
2023-01-27 10:16:08 -06:00
while [ $# -gt 0 ]; do
2021-12-14 07:09:23 -06:00
case $1 in
NoPrompt)
NO_PROMPT=1 ;;
*h|*help|*)
echo "Syntax $0 <NoPrompt>"
echo " NoPrompt - noninteractive mode"
echo " -h|--help - Show help"
exit 1
;;
esac
shift
done
2023-01-27 10:16:08 -06:00
echo ": ---------------------------"
# displays script name and version
2023-01-09 22:56:11 -06:00
echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}"
2021-10-27 12:51:22 -05:00
2023-01-27 10:16:08 -06:00
# information that helps with bug reports
# display architecture
2023-01-30 15:29:07 -06:00
echo ": ${KARCH} (architecture)"
2023-01-27 10:16:08 -06:00
# display kernel version
2023-01-30 15:29:07 -06:00
echo ": ${KVER} (kernel version)"
2023-01-27 10:16:08 -06:00
echo ": ---------------------------"
2022-12-30 15:14:47 -06:00
# check for and remove non-dkms installations
# standard naming
2023-01-27 10:16:08 -06:00
if [ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]; then
2022-12-30 15:14:47 -06:00
echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko"
2023-01-27 10:16:08 -06:00
rm -f "${MODDESTDIR}"${MODULE_NAME}.ko
/sbin/depmod -a "${KVER}"
fi
2021-10-27 12:51:22 -05:00
2022-12-30 15:14:47 -06:00
# check for and remove non-dkms installations
# with rtl added to module name (PClinuxOS)
2023-01-27 10:16:08 -06:00
if [ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]; then
2022-12-30 15:14:47 -06:00
echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko"
2023-01-27 10:16:08 -06:00
rm -f "${MODDESTDIR}"rtl${MODULE_NAME}.ko
/sbin/depmod -a "${KVER}"
2022-12-30 15:14:47 -06:00
fi
# check for and remove non-dkms installations
# with compressed module in a unique non-standard location (Armbian)
# Example: /usr/lib/modules/5.15.80-rockchip64/kernel/drivers/net/wireless/rtl8821cu/8821cu.ko.xz
# Dear Armbiam, this is a really bad idea.
2023-01-27 10:16:08 -06:00
if [ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]; then
2022-12-30 15:14:47 -06:00
echo "Removing a non-dkms installation: /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz"
2023-01-27 10:16:08 -06:00
rm -f /usr/lib/modules/"${KVER}"/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz
/sbin/depmod -a "${KVER}"
2022-12-30 15:14:47 -06:00
fi
# determine if dkms is installed and run the appropriate routines
2023-01-27 10:16:08 -06:00
if command -v dkms >/dev/null 2>&1; then
echo "Removing a dkms installation."
# 2>/dev/null suppresses the output of dkms
dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all 2>/dev/null
RESULT=$?
#echo "Result=${RESULT}"
# RESULT will be 3 if there are no instances of module to remove
# however we still need to remove various files or the install script
# may complain.
2023-01-27 10:16:08 -06:00
if [ "$RESULT" = "0" ] || [ "$RESULT" = "3" ]; then
if [ "$RESULT" = "0" ]; then
echo "${DRV_NAME}/${DRV_VERSION} has been removed"
fi
else
2022-12-30 15:14:47 -06:00
echo "An error occurred. dkms remove error: ${RESULT}"
echo "Please report this error."
exit $RESULT
fi
2021-10-27 12:51:22 -05:00
fi
echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d"
rm -f /etc/modprobe.d/${OPTIONS_FILE}
echo "Removing source files from /usr/src/${DRV_NAME}-${DRV_VERSION}"
rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION}
make clean >/dev/null 2>&1
echo "The driver was removed successfully."
echo "You may now delete the driver directory if desired."
2022-12-30 15:14:47 -06:00
# if NoPrompt is not used, ask user some questions
2023-01-27 10:16:08 -06:00
if [ $NO_PROMPT -ne 1 ]; then
2023-01-30 15:29:07 -06:00
printf "Do you want to reboot now? (recommended) [y/N] "
2023-01-27 10:16:08 -06:00
read -r REPLY
case "$REPLY" in
[yY]*) reboot ;;
esac
2021-10-27 12:51:22 -05:00
fi