From 2def66aec5a11b4d582be833d3ddc73573a17bf7 Mon Sep 17 00:00:00 2001 From: morrownr Date: Sun, 4 Dec 2022 21:31:45 -0600 Subject: [PATCH] more work on the installational and removal scripts --- install-driver.sh | 72 ++++++++++++++++++++++++++++++++-------- remove-driver.sh | 83 ++++++++++++++++++++++++++++++----------------- 2 files changed, 112 insertions(+), 43 deletions(-) diff --git a/install-driver.sh b/install-driver.sh index 336176e..23cc588 100755 --- a/install-driver.sh +++ b/install-driver.sh @@ -5,11 +5,9 @@ # Supports dkms and non-dkms installations. SCRIPT_NAME="install-driver.sh" - -SCRIPT_VERSION="20221126" +SCRIPT_VERSION="20221204" MODULE_NAME="88x2bu" DRV_VERSION="5.13.1" - OPTIONS_FILE="${MODULE_NAME}.conf" KVER="$(uname -r)" @@ -20,8 +18,8 @@ MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/" DRV_NAME="rtl${MODULE_NAME}" DRV_DIR="$(pwd)" -# Some distros have non-mainlined, patched-in kernel drivers -# that have to be deactivated. +# Some distros have a non-mainlined, patched-in kernel driver +# that has to be deactivated. BLACKLIST_FILE="rtw88_8822bu.conf" # check to ensure sudo was used @@ -32,6 +30,42 @@ then exit 1 fi +# check to ensure mokutil is installed +if ! command -v mokutil >/dev/null 2>&1 +then + echo "A required package appears to not be installed." + echo "Please install the following package: mokutil" + echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" + exit 1 +fi + +# check to ensure nano is installed +if ! command -v nano >/dev/null 2>&1 +then + echo "A required package appears to not be installed." + echo "Please install the following package: nano" + echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" + exit 1 +fi + +# check to ensure rfkill is installed +if ! command -v rfkill >/dev/null 2>&1 +then + echo "A required package appears to not be installed." + echo "Please install the following package: rfkill" + echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" + exit 1 +fi + +# check to ensure iw is installed +if ! command -v iw >/dev/null 2>&1 +then + echo "A required package appears to not be installed." + echo "Please install the following package: iw" + echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" + exit 1 +fi + # support for the NoPrompt option allows non-interactive use of this script NO_PROMPT=0 @@ -54,7 +88,7 @@ done # displays script name and version echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}" -# check for and remove previously installed non-dkms installation +# check for and remove non-dkms installation if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]] then echo "Removing a non-dkms installation." @@ -63,14 +97,22 @@ then fi # information that helps with bug reports + # kernel -echo "Kernel=${KVER}" +echo "Linux Kernel=${KVER}" + # architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit -echo "Architecture=${KARCH}" -#getconf LONG_BIT (may be handy in the future) +echo "CPU Architecture=${KARCH}" + +# gcc version +gcc_ver=$(gcc --version | grep -i gcc) +echo "gcc --version="${gcc_ver} + +# check for secure mode +# # blacklist the in-kernel module (driver) so that there is no conflict -echo "Copying ${BLACKLIST_FILE} to: /etc/modprobe.d" +echo "Installing ${BLACKLIST_FILE} to: /etc/modprobe.d" cp -f ${BLACKLIST_FILE} /etc/modprobe.d # sets module parameters (driver options) @@ -106,6 +148,7 @@ then if [[ "$RESULT" = "0" ]] then + make clean >/dev/null 2>&1 echo "The driver was installed successfully." else echo "An error occurred. Error = ${RESULT}" @@ -178,20 +221,23 @@ else fi # unblock wifi -rfkill unblock wlan +if command -v rfkill >/dev/null 2>&1 +then + rfkill unblock wlan +else + echo "Unable to run $ rfkill unblock wlan" +fi # if NoPrompt is not used, ask user some questions to complete installation if [ $NO_PROMPT -ne 1 ] then read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r - echo if [[ $REPLY =~ ^[Yy]$ ]] then nano /etc/modprobe.d/${OPTIONS_FILE} fi read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r - echo if [[ $REPLY =~ ^[Yy]$ ]] then reboot diff --git a/remove-driver.sh b/remove-driver.sh index 73f2586..fda8b77 100755 --- a/remove-driver.sh +++ b/remove-driver.sh @@ -1,22 +1,25 @@ #!/bin/bash -# Purpose: Remove Realtek USB WiFi adapter drivers. +# Purpose: Remove Realtek out-of-kernel USB WiFi adapter drivers. # # Supports dkms and non-dkms removals. SCRIPT_NAME="remove-driver.sh" -SCRIPT_VERSION="20221007" +SCRIPT_VERSION="20221204" MODULE_NAME="88x2bu" DRV_VERSION="5.13.1" OPTIONS_FILE="${MODULE_NAME}.conf" KVER="$(uname -r)" +KARCH="$(uname -m)" KSRC="/lib/modules/${KVER}/build" MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/" DRV_NAME="rtl${MODULE_NAME}" DRV_DIR="$(pwd)" +# Some distros have a non-mainlined, patched-in kernel driver +# that has to be deactivated. BLACKLIST_FILE="rtw88_8822bu.conf" # check to ensure sudo was used @@ -27,10 +30,10 @@ then exit 1 fi -# support for NoPrompt allows non-interactive use of this script +# support for the NoPrompt option allows non-interactive use of this script NO_PROMPT=0 -# get the options +# get the script options while [ $# -gt 0 ] do case $1 in @@ -48,38 +51,58 @@ done # displays script name and version echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}" -echo "Starting removal..." -if ! command -v dkms >/dev/null 2>&1 +# check for and remove non-dkms installation +if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]] then - make uninstall -else - dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all -fi -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 - echo "Deleting ${OPTIONS_FILE} from /etc/modprobe.d" - rm -f /etc/modprobe.d/${OPTIONS_FILE} - echo "Deleting ${BLACKLIST_FILE} from /etc/modprobe.d" - rm -f /etc/modprobe.d/${BLACKLIST_FILE} - echo "Deleting source files from /usr/src/${DRV_NAME}-${DRV_VERSION}" - rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION} -# echo "Removing a non-dkms installation." + echo "Removing a non-dkms installation." rm -f ${MODDESTDIR}${MODULE_NAME}.ko /sbin/depmod -a ${KVER} - echo "The driver was removed successfully." - echo "You may now delete the driver directory if desired." -else - echo "An error occurred. dkms remove error = ${RESULT}" - echo "Please report this error." - exit $RESULT fi +# information that helps with bug reports + +# kernel +echo "Linux Kernel=${KVER}" + +# architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit +echo "CPU Architecture=${KARCH}" + +# determine if dkms is installed and run the appropriate routines +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. + if [[ ("$RESULT" = "0")||("$RESULT" = "3") ]] + then + if [[ ("$RESULT" = "0") ]] + then + echo "${DRV_NAME}/${DRV_VERSION} has been removed" + fi + else + echo "An error occurred. dkms remove error = ${RESULT}" + echo "Please report this error." + exit $RESULT + fi +fi + +echo "Removing ${BLACKLIST_FILE} from /etc/modprobe.d" +rm -f /etc/modprobe.d/${BLACKLIST_FILE} +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." + # if NoPrompt is not used, ask user some questions to complete removal if [ $NO_PROMPT -ne 1 ] then