88x2bu-20210702/remove-driver.sh

144 lines
4.0 KiB
Bash
Raw Normal View History

2021-10-27 12:51:22 -05:00
#!/bin/bash
# Purpose: Remove Realtek out-of-kernel USB WiFi adapter drivers.
2022-08-21 15:31:50 -05:00
#
# Supports dkms and non-dkms removals.
2022-08-21 15:31:50 -05: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-09 12:27:31 -06:00
SCRIPT_VERSION="20230109"
MODULE_NAME="88x2bu"
2022-10-19 16:15:30 -05:00
DRV_VERSION="5.13.1"
KVER="$(uname -r)"
KARCH="$(uname -m)"
2023-01-10 16:09:36 -06:00
#KSRC="/lib/modules/${KVER}/build"
MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/"
2022-10-19 16:15:30 -05:00
DRV_NAME="rtl${MODULE_NAME}"
2021-12-14 07:09:23 -06:00
DRV_DIR="$(pwd)"
2022-12-20 23:53:39 -06:00
OPTIONS_FILE="${MODULE_NAME}.conf"
2022-10-19 16:15:30 -05:00
# check to ensure sudo was used
if [[ $EUID -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
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
# 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
2022-12-30 15:14:47 -06:00
# check for and remove non-dkms installations
# standard naming
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"
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)
if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]]
then
echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko"
rm -f ${MODDESTDIR}rtl${MODULE_NAME}.ko
/sbin/depmod -a ${KVER}
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.
if [[ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]]
then
echo "Removing a non-dkms installation: /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz"
rm -f /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz
/sbin/depmod -a ${KVER}
fi
# information that helps with bug reports
2022-12-20 23:53:39 -06:00
# display kernel version
2023-01-09 18:16:40 -06:00
echo ": ${KVER}"
2022-12-20 23:53:39 -06:00
# display architecture
2023-01-09 18:16:40 -06:00
echo ": ${KARCH}"
# determine if dkms is installed and run the appropriate routines
if command -v dkms >/dev/null 2>&1
2021-10-27 12:51:22 -05:00
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.
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
if [ $NO_PROMPT -ne 1 ]
2021-12-14 07:09:23 -06:00
then
read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
reboot
fi
2021-10-27 12:51:22 -05:00
fi
exit 0