Path: blob/master/ALFA-W1F1/RTL8814AU/remove-driver.sh
1306 views
#!/bin/sh12# Purpose: Remove Realtek out-of-kernel USB WiFi adapter drivers.3#4# Supports dkms and non-dkms removals.5#6# To make this file executable:7#8# $ chmod +x remove-driver.sh9#10# To execute this file:11#12# $ sudo ./remove-driver.sh13#14# or15#16# $ sudo sh remove-driver.sh17#18# Copyright(c) 2023 Nick Morrow19#20# This program is free software; you can redistribute it and/or modify21# it under the terms of version 2 of the GNU General Public License as22# published by the Free Software Foundation.23#24# This program is distributed in the hope that it will be useful, but25# WITHOUT ANY WARRANTY; without even the implied warranty of26# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the27# GNU General Public License for more details.2829SCRIPT_NAME="remove-driver.sh"30SCRIPT_VERSION="20230226"31MODULE_NAME="8814au"32DRV_VERSION="5.8.5.1"3334KARCH="$(uname -m)"35KVER="$(uname -r)"36MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/"3738DRV_NAME="rtl${MODULE_NAME}"39OPTIONS_FILE="${MODULE_NAME}.conf"4041# check to ensure sudo was used to start the script42if [ "$(id -u)" -ne 0 ]; then43echo "You must run this script with superuser (root) privileges."44echo "Try: \"sudo ./${SCRIPT_NAME}\""45exit 146fi4748# support for the NoPrompt option allows non-interactive use of this script49NO_PROMPT=050# get the script options51while [ $# -gt 0 ]; do52case $1 in53NoPrompt)54NO_PROMPT=1 ;;55*h|*help|*)56echo "Syntax $0 <NoPrompt>"57echo " NoPrompt - noninteractive mode"58echo " -h|--help - Show help"59exit 160;;61esac62shift63done6465echo ": ---------------------------"6667# displays script name and version68echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}"6970# information that helps with bug reports7172# display architecture73echo ": ${KARCH} (architecture)"7475# display kernel version76echo ": ${KVER} (kernel version)"7778echo ": ---------------------------"79echo8081# check for and remove non-dkms installations82# standard naming83if [ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]; then84echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko"85rm -f "${MODDESTDIR}"${MODULE_NAME}.ko86/sbin/depmod -a "${KVER}"87fi8889# check for and remove non-dkms installations90# with rtl added to module name (PClinuxOS)91if [ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]; then92echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko"93rm -f "${MODDESTDIR}"rtl${MODULE_NAME}.ko94/sbin/depmod -a "${KVER}"95fi9697# check for and remove non-dkms installations98# with compressed module in a unique non-standard location (Armbian)99# Example: /usr/lib/modules/5.15.80-rockchip64/kernel/drivers/net/wireless/rtl8821cu/8821cu.ko.xz100# Dear Armbiam, this is a really bad idea.101if [ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]; then102echo "Removing a non-dkms installation: /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz"103rm -f /usr/lib/modules/"${KVER}"/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz104/sbin/depmod -a "${KVER}"105fi106107# determine if dkms is installed and run the appropriate routines108if command -v dkms >/dev/null 2>&1; then109echo "Removing a dkms installation."110# 2>/dev/null suppresses the output of dkms111dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all 2>/dev/null112RESULT=$?113#echo "Result=${RESULT}"114115# RESULT will be 3 if there are no instances of module to remove116# however we still need to remove various files or the install script117# may complain.118if [ "$RESULT" = "0" ] || [ "$RESULT" = "3" ]; then119if [ "$RESULT" = "0" ]; then120echo "${DRV_NAME}/${DRV_VERSION} has been removed"121fi122else123echo "An error occurred. dkms remove error: ${RESULT}"124echo "Please report this error."125exit $RESULT126fi127fi128129echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d"130rm -f /etc/modprobe.d/${OPTIONS_FILE}131echo "Removing source files from /usr/src/${DRV_NAME}-${DRV_VERSION}"132rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION}133make clean >/dev/null 2>&1134echo "The driver was removed successfully."135echo "You may now delete the driver directory if desired."136echo ": ---------------------------"137echo138139# if NoPrompt is not used, ask user some questions140if [ $NO_PROMPT -ne 1 ]; then141printf "Do you want to reboot now? (recommended) [Y/n] "142read -r yn143case "$yn" in144[nN]) ;;145*) reboot ;;146esac147fi148149150