2021-10-27 12:51:22 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
# Purpose: Install Realtek out-of-kernel USB WiFi adapter drivers.
|
2022-08-21 15:31:50 -05:00
|
|
|
#
|
2022-10-04 12:34:55 -05:00
|
|
|
# Supports dkms and non-dkms installations.
|
2022-08-21 15:31:50 -05:00
|
|
|
|
2021-10-27 12:51:22 -05:00
|
|
|
SCRIPT_NAME="install-driver.sh"
|
2022-10-04 12:34:55 -05:00
|
|
|
SCRIPT_VERSION="20220929"
|
2022-08-21 15:31:50 -05:00
|
|
|
OPTIONS_FILE="88x2bu.conf"
|
2022-10-04 12:34:55 -05:00
|
|
|
|
|
|
|
# Some distros have a non-mainlined, patched-in kernel driver
|
|
|
|
# that has to be deactivated.
|
2022-08-21 15:31:50 -05:00
|
|
|
BLACKLIST_FILE="rtw88_8822bu.conf"
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
MODULE_NAME="88x2bu"
|
|
|
|
KVER="$(uname -r)"
|
|
|
|
MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/"
|
|
|
|
|
2021-10-27 12:51:22 -05:00
|
|
|
DRV_NAME="rtl88x2bu"
|
|
|
|
DRV_VERSION="5.13.1"
|
|
|
|
DRV_DIR="$(pwd)"
|
|
|
|
|
2022-10-04 12:34:55 -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
|
|
|
|
|
|
|
|
# support for the NoPrompt option allows non-interactive use of this script
|
2021-12-14 07:09:23 -06:00
|
|
|
NO_PROMPT=0
|
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
# get the script options
|
2021-10-27 12:51:22 -05:00
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
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
|
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
# displays script name and version
|
|
|
|
echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}"
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
# check for and remove previously installed non-dkms installation
|
|
|
|
if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]]
|
2021-10-27 12:51:22 -05:00
|
|
|
then
|
2022-10-04 12:34:55 -05:00
|
|
|
echo "Removing a non-dkms installation."
|
2022-10-07 15:34:14 -05:00
|
|
|
rm -f ${MODDESTDIR}${MODULE_NAME}.ko
|
2022-10-04 12:34:55 -05:00
|
|
|
/sbin/depmod -a ${KVER}
|
2021-10-27 12:51:22 -05:00
|
|
|
fi
|
|
|
|
|
2022-01-16 11:46:39 -06:00
|
|
|
# information that helps with bug reports
|
|
|
|
# kernel
|
|
|
|
uname -r
|
|
|
|
# architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit
|
|
|
|
uname -m
|
|
|
|
|
2021-10-27 12:51:22 -05:00
|
|
|
echo "Starting installation..."
|
2022-08-21 15:31:50 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
# blacklist the in-kernel module (driver) so that there is no conflict
|
|
|
|
echo "Copying ${BLACKLIST_FILE} to: /etc/modprobe.d"
|
|
|
|
cp -f ${BLACKLIST_FILE} /etc/modprobe.d
|
2022-08-21 15:31:50 -05:00
|
|
|
|
|
|
|
# sets module parameters (driver options)
|
2021-10-27 12:51:22 -05:00
|
|
|
echo "Copying ${OPTIONS_FILE} to: /etc/modprobe.d"
|
|
|
|
cp -f ${OPTIONS_FILE} /etc/modprobe.d
|
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
# determine if dkms is installed and run the appropriate routines
|
|
|
|
if ! command -v dkms >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
echo "The non-dkms installation routines are in use."
|
2022-08-21 15:31:50 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
make clean
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
make
|
|
|
|
RESULT=$?
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
if [[ "$RESULT" != "0" ]]
|
|
|
|
then
|
|
|
|
echo "An error occurred. Error = ${RESULT}"
|
|
|
|
echo "Please report this error."
|
|
|
|
echo "Please copy all screen output and paste it into the report."
|
|
|
|
echo "You will need to run the following before reattempting installation."
|
|
|
|
echo "$ sudo ./remove-driver-no-dkms.sh"
|
|
|
|
exit $RESULT
|
|
|
|
fi
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
# As shown in Makefile
|
|
|
|
# install:
|
|
|
|
# install -p -m 644 $(MODULE_NAME).ko $(MODDESTDIR)
|
|
|
|
# /sbin/depmod -a ${KVER}
|
|
|
|
make install
|
|
|
|
RESULT=$?
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
if [[ "$RESULT" = "0" ]]
|
|
|
|
then
|
|
|
|
echo "The driver was installed successfully."
|
|
|
|
else
|
|
|
|
echo "An error occurred. Error = ${RESULT}"
|
|
|
|
echo "Please report this error."
|
|
|
|
echo "Please copy all screen output and paste it into the report."
|
|
|
|
echo "You will need to run the following before reattempting installation."
|
|
|
|
echo "$ sudo ./remove-driver-no-dkms.sh"
|
|
|
|
exit $RESULT
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "The dkms installation routines are in use."
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
# the dkms add command requires source in /usr/src/${DRV_NAME}-${DRV_VERSION}
|
|
|
|
echo "Copying source files to: /usr/src/${DRV_NAME}-${DRV_VERSION}"
|
|
|
|
cp -rf "${DRV_DIR}" /usr/src/${DRV_NAME}-${DRV_VERSION}
|
|
|
|
|
|
|
|
dkms add -m ${DRV_NAME} -v ${DRV_VERSION}
|
|
|
|
RESULT=$?
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2022-10-04 12:34:55 -05:00
|
|
|
if [[ "$RESULT" != "0" ]]
|
|
|
|
then
|
|
|
|
echo "An error occurred. dkms add error = ${RESULT}"
|
|
|
|
echo "Please report this error."
|
|
|
|
echo "Please copy all screen output and paste it into the report."
|
|
|
|
echo "Run the following before reattempting installation."
|
|
|
|
echo "$ sudo ./remove-driver.sh"
|
|
|
|
exit $RESULT
|
|
|
|
fi
|
|
|
|
|
|
|
|
dkms build -m ${DRV_NAME} -v ${DRV_VERSION}
|
|
|
|
RESULT=$?
|
|
|
|
|
|
|
|
if [[ "$RESULT" != "0" ]]
|
|
|
|
then
|
|
|
|
echo "An error occurred. dkms build error = ${RESULT}"
|
|
|
|
echo "Please report this error."
|
|
|
|
echo "Please copy all screen output and paste it into the report."
|
|
|
|
echo "Run the following before reattempting installation."
|
|
|
|
echo "$ sudo ./remove-driver.sh"
|
|
|
|
exit $RESULT
|
|
|
|
fi
|
|
|
|
|
|
|
|
dkms install -m ${DRV_NAME} -v ${DRV_VERSION}
|
|
|
|
RESULT=$?
|
|
|
|
|
|
|
|
if [[ "$RESULT" = "0" ]]
|
|
|
|
then
|
|
|
|
echo "The driver was installed successfully."
|
|
|
|
else
|
|
|
|
echo "An error occurred. dkms install error = ${RESULT}"
|
|
|
|
echo "Please report this error."
|
|
|
|
echo "Please copy all screen output and paste it into the report."
|
|
|
|
echo "Run the following before reattempting installation."
|
|
|
|
echo "$ sudo ./remove-driver.sh"
|
|
|
|
exit $RESULT
|
|
|
|
fi
|
|
|
|
fi
|
2021-10-27 12:51:22 -05:00
|
|
|
|
2021-12-14 07:09:23 -06:00
|
|
|
# unblock wifi
|
2021-10-27 12:51:22 -05:00
|
|
|
rfkill unblock wlan
|
|
|
|
|
2021-12-14 07:09:23 -06:00
|
|
|
# if NoPrompt is not used, ask user some questions to complete installation
|
2021-10-27 12:51:22 -05:00
|
|
|
if [ $NO_PROMPT -ne 1 ]
|
|
|
|
then
|
|
|
|
read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r
|
2021-12-14 07:09:23 -06:00
|
|
|
echo
|
2021-10-27 12:51:22 -05:00
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]
|
|
|
|
then
|
|
|
|
nano /etc/modprobe.d/${OPTIONS_FILE}
|
|
|
|
fi
|
|
|
|
|
2021-12-14 07:09:23 -06:00
|
|
|
read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
|
|
|
|
echo
|
2021-10-27 12:51:22 -05:00
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]
|
|
|
|
then
|
|
|
|
reboot
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|