From 08c72e9cb4089200932a892e9a184e04ec5b0781 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Wed, 25 Jan 2023 21:45:40 +1100 Subject: [PATCH 1/8] Converted to non-Bash editor searching --- edit-options.sh | 11 +++-------- install-driver.sh | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/edit-options.sh b/edit-options.sh index 7316127..030b06a 100755 --- a/edit-options.sh +++ b/edit-options.sh @@ -26,8 +26,7 @@ SCRIPT_NAME="edit-options.sh" SCRIPT_VERSION="20230120" OPTIONS_FILE="8821cu.conf" -DEFAULT_EDITOR="$(/dev/null 2>&1 - then - TEXT_EDITOR="${editor}" - break - fi + command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break done # Fail if no editor was found diff --git a/install-driver.sh b/install-driver.sh index dca23a6..a2c551b 100755 --- a/install-driver.sh +++ b/install-driver.sh @@ -38,8 +38,7 @@ OPTIONS_FILE="${MODULE_NAME}.conf" SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }') sproc=$(nproc) -DEFAULT_EDITOR="$(/dev/null 2>&1 - then - TEXT_EDITOR="${editor}" - break - fi + command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break done # Fail if no editor was found From 2954b29f7df55119c279495253794921515d8610 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Wed, 25 Jan 2023 22:35:30 +1100 Subject: [PATCH 2/8] Squashed all the if/then, while/do and for/do fragments onto single lines --- dkms-make.sh | 6 ++-- edit-options.sh | 12 +++---- install-driver.sh | 84 ++++++++++++++++------------------------------- remove-driver.sh | 30 ++++++----------- 4 files changed, 44 insertions(+), 88 deletions(-) diff --git a/dkms-make.sh b/dkms-make.sh index c571ad8..8cbd783 100755 --- a/dkms-make.sh +++ b/dkms-make.sh @@ -7,10 +7,8 @@ SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }') sproc=$(nproc) # Avoid Out of Memory condition in low-RAM systems by limiting core usage. -if [ "$sproc" -gt 1 ] -then - if [ "$SMEM" -lt 1400000 ] - then +if [ "$sproc" -gt 1 ]; then + if [ "$SMEM" -lt 1400000 ]; then sproc=2 fi fi diff --git a/edit-options.sh b/edit-options.sh index 030b06a..58a3edd 100755 --- a/edit-options.sh +++ b/edit-options.sh @@ -28,22 +28,19 @@ SCRIPT_VERSION="20230120" OPTIONS_FILE="8821cu.conf" DEFAULT_EDITOR="$(cat default-editor.txt)" -if [[ $EUID -ne 0 ]] -then +if [[ $EUID -ne 0 ]]; then echo "You must run this script with superuser (root) privileges." echo "Try: \"sudo ./${SCRIPT_NAME}\"" exit 1 fi # Try to find the user's default text editor through the EDITORS_SEARCH array -for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; -do +for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; do command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break done # Fail if no editor was found -if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1 -then +if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1; then echo "No text editor found (default: ${DEFAULT_EDITOR})." echo "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor.txt' to specify your editor." echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\"" @@ -54,8 +51,7 @@ ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} read -p "Do you want to apply the new options by rebooting now? [y/N] " -n 1 -r echo # move to a new line -if [[ $REPLY =~ ^[Yy]$ ]] -then +if [[ $REPLY =~ ^[Yy]$ ]]; then reboot fi diff --git a/install-driver.sh b/install-driver.sh index a2c551b..73821b7 100755 --- a/install-driver.sh +++ b/install-driver.sh @@ -41,8 +41,7 @@ sproc=$(nproc) DEFAULT_EDITOR="$(cat default-editor.txt)" # check to ensure sudo was used -if [[ $EUID -ne 0 ]] -then +if [[ $EUID -ne 0 ]]; then echo "You must run this script with superuser (root) privileges." echo "Try: \"sudo ./${SCRIPT_NAME}\"" exit 1 @@ -54,8 +53,7 @@ if ! echo "$PATH" | grep -qw sbin; then fi # check to ensure gcc is installed -if ! command -v gcc >/dev/null 2>&1 -then +if ! command -v gcc >/dev/null 2>&1; then echo "A required package is not installed." echo "Please install the following package: gcc" echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" @@ -63,8 +61,7 @@ then fi # check to ensure make is installed -if ! command -v make >/dev/null 2>&1 -then +if ! command -v make >/dev/null 2>&1; then echo "A required package is not installed." echo "Please install the following package: make" echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" @@ -80,8 +77,7 @@ if [ ! -d "/lib/modules/$(uname -r)/build" ]; then fi # check to ensure iw is installed -if ! command -v iw >/dev/null 2>&1 -then +if ! command -v iw >/dev/null 2>&1; then echo "A required package is not installed." echo "Please install the following package: iw" echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" @@ -89,8 +85,7 @@ then fi # check to ensure rfkill is installed -if ! command -v rfkill >/dev/null 2>&1 -then +if ! command -v rfkill >/dev/null 2>&1; then echo "A required package is not installed." echo "Please install the following package: rfkill" echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" @@ -98,14 +93,12 @@ then fi # Try to find the user's default text editor through the EDITORS_SEARCH array -for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; -do +for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; do command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break done # Fail if no editor was found -if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1 -then +if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1; then echo "No text editor found (default: ${DEFAULT_EDITOR})." echo "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor.txt' to specify your editor." echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\"" @@ -116,8 +109,7 @@ fi NO_PROMPT=0 # get the script options -while [ $# -gt 0 ] -do +while [ $# -gt 0 ]; do case $1 in NoPrompt) NO_PROMPT=1 ;; @@ -145,8 +137,7 @@ echo ": ${KARCH} (ARCH)" echo ": ${SMEM} (SMEM)" # Avoid Out of Memory condition in low-RAM systems by limiting core usage. -if [ "$sproc" -gt 1 ] -then +if [ "$sproc" -gt 1 ]; then if [ "$SMEM" -lt 1400000 ] then sproc=2 @@ -163,15 +154,13 @@ gcc_ver=$(gcc --version | grep -i gcc) echo ": "${gcc_ver} # display dkms version if installed -if command -v dkms >/dev/null 2>&1 -then +if command -v dkms >/dev/null 2>&1; then dkms_ver=$(dkms --version) echo ": "${dkms_ver} fi # display secure mode status if mokutil is installed -if command -v mokutil >/dev/null 2>&1 -then +if command -v mokutil >/dev/null 2>&1; then sb_state=$(mokutil --sb-state) echo ": "${sb_state} fi @@ -190,8 +179,7 @@ echo ": ---------------------------" # check for and remove non-dkms installations # standard naming -if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]] -then +if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]]; then echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko" rm -f ${MODDESTDIR}${MODULE_NAME}.ko /sbin/depmod -a ${KVER} @@ -204,8 +192,7 @@ fi # check for and remove non-dkms installations # with rtl added to module name (PClinuxOS) -if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]] -then +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} @@ -220,8 +207,7 @@ fi # 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 +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} @@ -233,10 +219,8 @@ then fi # check for and remove dkms installations -if command -v dkms >/dev/null 2>&1 -then - if dkms status | grep -i ${DRV_NAME} - then +if command -v dkms >/dev/null 2>&1; then + if dkms status | grep -i ${DRV_NAME}; then echo "Removing a dkms installation: ${DRV_NAME}" dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d" @@ -251,8 +235,7 @@ echo "Installing ${OPTIONS_FILE} to /etc/modprobe.d" cp -f ${OPTIONS_FILE} /etc/modprobe.d # determine if dkms is installed and run the appropriate routines -if ! command -v dkms >/dev/null 2>&1 -then +if ! command -v dkms >/dev/null 2>&1; then echo "The non-dkms installation routines are in use." make clean >/dev/null 2>&1 @@ -260,8 +243,7 @@ then make -j$(nproc) RESULT=$? - if [[ "$RESULT" != "0" ]] - then + if [[ "$RESULT" != "0" ]]; then echo "An error occurred: ${RESULT}" echo "Please report this error." echo "Please copy all screen output and paste it into the problem report." @@ -277,8 +259,7 @@ then make install RESULT=$? - if [[ "$RESULT" = "0" ]] - then + if [[ "$RESULT" = "0" ]]; then make clean >/dev/null 2>&1 echo "The driver was installed successfully." else @@ -301,10 +282,8 @@ else # RESULT will be 3 if the DKMS tree already contains the same module/version # combo. You cannot add the same module/version combo more than once. - if [[ "$RESULT" != "0" ]] - then - if [[ "$RESULT" = "3" ]] - then + if [[ "$RESULT" != "0" ]]; then + if [[ "$RESULT" = "3" ]]; then echo "This driver may already be installed." echo "Run the following and then reattempt installation." echo "$ sudo ./remove-driver.sh" @@ -321,16 +300,14 @@ else echo "The driver was added to dkms successfully." fi - if command -v /usr/bin/time >/dev/null 2>&1 - then + if command -v /usr/bin/time >/dev/null 2>&1; then /usr/bin/time -f "Compile time: %U seconds" dkms build -m ${DRV_NAME} -v ${DRV_VERSION} else dkms build -m ${DRV_NAME} -v ${DRV_VERSION} fi RESULT=$? - if [[ "$RESULT" != "0" ]] - then + 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 problem report." @@ -344,8 +321,7 @@ else dkms install -m ${DRV_NAME} -v ${DRV_VERSION} RESULT=$? - if [[ "$RESULT" != "0" ]] - then + if [[ "$RESULT" != "0" ]]; then echo "An error occurred. dkms install error: ${RESULT}" echo "Please report this error." echo "Please copy all screen output and paste it into the problem report." @@ -358,27 +334,23 @@ else fi # unblock wifi -if command -v rfkill >/dev/null 2>&1 -then +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 -if [ $NO_PROMPT -ne 1 ] -then +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 + if [[ $REPLY =~ ^[Yy]$ ]]; then ${TEXT_EDITOR} /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 + if [[ $REPLY =~ ^[Yy]$ ]]; then reboot fi fi diff --git a/remove-driver.sh b/remove-driver.sh index d9a3699..8eff657 100755 --- a/remove-driver.sh +++ b/remove-driver.sh @@ -37,8 +37,7 @@ DRV_DIR="$(pwd)" OPTIONS_FILE="${MODULE_NAME}.conf" # check to ensure sudo was used -if [[ $EUID -ne 0 ]] -then +if [[ $EUID -ne 0 ]]; then echo "You must run this script with superuser (root) privileges." echo "Try: \"sudo ./${SCRIPT_NAME}\"" exit 1 @@ -48,8 +47,7 @@ fi NO_PROMPT=0 # get the script options -while [ $# -gt 0 ] -do +while [ $# -gt 0 ]; do case $1 in NoPrompt) NO_PROMPT=1 ;; @@ -68,8 +66,7 @@ echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}" # check for and remove non-dkms installations # standard naming -if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]] -then +if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]]; then echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko" rm -f ${MODDESTDIR}${MODULE_NAME}.ko /sbin/depmod -a ${KVER} @@ -77,8 +74,7 @@ fi # check for and remove non-dkms installations # with rtl added to module name (PClinuxOS) -if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]] -then +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} @@ -88,8 +84,7 @@ fi # 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 +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} @@ -104,8 +99,7 @@ echo ": ${KVER}" echo ": ${KARCH}" # determine if dkms is installed and run the appropriate routines -if command -v dkms >/dev/null 2>&1 -then +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 @@ -115,10 +109,8 @@ then # 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 + if [[ ("$RESULT" = "0")||("$RESULT" = "3") ]]; then + if [[ ("$RESULT" = "0") ]]; then echo "${DRV_NAME}/${DRV_VERSION} has been removed" fi else @@ -137,12 +129,10 @@ 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 -if [ $NO_PROMPT -ne 1 ] -then +if [ $NO_PROMPT -ne 1 ]; then read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r echo - if [[ $REPLY =~ ^[Yy]$ ]] - then + if [[ $REPLY =~ ^[Yy]$ ]]; then reboot fi fi From 8fe4a3bc2adbc18c68850101048ba51f081c02d1 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Wed, 25 Jan 2023 23:12:04 +1100 Subject: [PATCH 3/8] Addressed whines from "shellcheck -s sh" --- edit-options.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/edit-options.sh b/edit-options.sh index 58a3edd..83c7f7d 100755 --- a/edit-options.sh +++ b/edit-options.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Purpose: Make it easier to edit the driver options file. # @@ -28,7 +28,7 @@ SCRIPT_VERSION="20230120" OPTIONS_FILE="8821cu.conf" DEFAULT_EDITOR="$(cat default-editor.txt)" -if [[ $EUID -ne 0 ]]; then +if [ "$(id -u)" -ne 0 ]; then echo "You must run this script with superuser (root) privileges." echo "Try: \"sudo ./${SCRIPT_NAME}\"" exit 1 @@ -47,11 +47,15 @@ if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1; then exit 1 fi +# displays script name and version +echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}" + ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} -read -p "Do you want to apply the new options by rebooting now? [y/N] " -n 1 -r +echo "Do you want to apply the new options by rebooting now? [y/N] " +read -r REPLY echo # move to a new line -if [[ $REPLY =~ ^[Yy]$ ]]; then +if [ "${REPLY}" = y ] || [ "${REPLY}" = Y ]; then reboot fi From 7e932ac90dec100bcc4cd3a41077ced25588e123 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Wed, 25 Jan 2023 23:17:49 +1100 Subject: [PATCH 4/8] Addressed whines from "shellcheck -s sh" --- dkms-make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkms-make.sh b/dkms-make.sh index 8cbd783..0689c87 100755 --- a/dkms-make.sh +++ b/dkms-make.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # SMEM needs to be set here if dkms build is not initiated by install-driver.sh SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }') From b4a7f21fdd3d2cda883fc2a239172a8e030c5072 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Wed, 25 Jan 2023 23:52:41 +1100 Subject: [PATCH 5/8] Addressed whines from "shellcheck -s sh" --- install-driver.sh | 52 ++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/install-driver.sh b/install-driver.sh index 73821b7..77712d5 100755 --- a/install-driver.sh +++ b/install-driver.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Purpose: Install Realtek out-of-kernel USB WiFi adapter drivers. # @@ -41,7 +41,7 @@ sproc=$(nproc) DEFAULT_EDITOR="$(cat default-editor.txt)" # check to ensure sudo was used -if [[ $EUID -ne 0 ]]; then +if [ "$(id -u)" -ne 0 ]; then echo "You must run this script with superuser (root) privileges." echo "Try: \"sudo ./${SCRIPT_NAME}\"" exit 1 @@ -151,18 +151,18 @@ echo ": ${KVER} (KVER)" # display gcc version gcc_ver=$(gcc --version | grep -i gcc) -echo ": "${gcc_ver} +echo ": ${gcc_ver}" # display dkms version if installed if command -v dkms >/dev/null 2>&1; then dkms_ver=$(dkms --version) - echo ": "${dkms_ver} + echo ": ${dkms_ver}" fi # display secure mode status if mokutil is installed if command -v mokutil >/dev/null 2>&1; then sb_state=$(mokutil --sb-state) - echo ": "${sb_state} + echo ": ${sb_state}" fi echo ": ---------------------------" @@ -179,10 +179,10 @@ echo ": ---------------------------" # check for and remove non-dkms installations # standard naming -if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]]; then +if [ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]; then echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko" - rm -f ${MODDESTDIR}${MODULE_NAME}.ko - /sbin/depmod -a ${KVER} + rm -f "${MODDESTDIR}${MODULE_NAME}.ko" + /sbin/depmod -a "${KVER}" 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}" @@ -192,10 +192,10 @@ fi # check for and remove non-dkms installations # with rtl added to module name (PClinuxOS) -if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]]; then +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} + rm -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" + /sbin/depmod -a "${KVER}" 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}" @@ -207,10 +207,10 @@ fi # 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 +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} + rm -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" + /sbin/depmod -a "${KVER}" 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}" @@ -240,10 +240,10 @@ if ! command -v dkms >/dev/null 2>&1; then make clean >/dev/null 2>&1 - make -j$(nproc) + make "-j$(nproc)" RESULT=$? - if [[ "$RESULT" != "0" ]]; then + if [ "$RESULT" != "0" ]; then echo "An error occurred: ${RESULT}" echo "Please report this error." echo "Please copy all screen output and paste it into the problem report." @@ -259,7 +259,7 @@ if ! command -v dkms >/dev/null 2>&1; then make install RESULT=$? - if [[ "$RESULT" = "0" ]]; then + if [ "$RESULT" = "0" ]; then make clean >/dev/null 2>&1 echo "The driver was installed successfully." else @@ -282,8 +282,8 @@ else # RESULT will be 3 if the DKMS tree already contains the same module/version # combo. You cannot add the same module/version combo more than once. - if [[ "$RESULT" != "0" ]]; then - if [[ "$RESULT" = "3" ]]; then + if [ "$RESULT" != "0" ]; then + if [ "$RESULT" = "3" ]; then echo "This driver may already be installed." echo "Run the following and then reattempt installation." echo "$ sudo ./remove-driver.sh" @@ -307,7 +307,7 @@ else fi RESULT=$? - if [[ "$RESULT" != "0" ]]; then + 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 problem report." @@ -321,7 +321,7 @@ else dkms install -m ${DRV_NAME} -v ${DRV_VERSION} RESULT=$? - if [[ "$RESULT" != "0" ]]; then + if [ "$RESULT" != "0" ]; then echo "An error occurred. dkms install error: ${RESULT}" echo "Please report this error." echo "Please copy all screen output and paste it into the problem report." @@ -342,15 +342,17 @@ fi # if NoPrompt is not used, ask user some questions if [ $NO_PROMPT -ne 1 ]; then - read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r + echo "Do you want to edit the driver options file now? [y/N]" + read -r REPLY echo - if [[ $REPLY =~ ^[Yy]$ ]]; then + if [ "$REPLY" = y ] || [ "$REPLY" = Y ]; then ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} fi - read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r + echo "Do you want to reboot now? (recommended) [y/N]" + read -r REPLY echo - if [[ $REPLY =~ ^[Yy]$ ]]; then + if [ "$REPLY" = y ] || [ "$REPLY" = Y ]; then reboot fi fi From 5fd204f3df6d07d3a9cfee349b642e63e2778b64 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Wed, 25 Jan 2023 23:57:32 +1100 Subject: [PATCH 6/8] Addressed whines from "shellcheck -s sh" --- save-log.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/save-log.sh b/save-log.sh index 4957198..0a79ca0 100755 --- a/save-log.sh +++ b/save-log.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/dash +#!/bin/sh # SCRIPT_NAME="save-log.sh" # @@ -12,7 +13,7 @@ SCRIPT_NAME="save-log.sh" # # $ sudo ./edit-options.sh # -if [[ $EUID -ne 0 ]]; then +if [ "$(id -u)" -ne 0 ]; then echo "You must run this script with superuser (root) privileges." echo "Try: \"sudo ./${SCRIPT_NAME}\"" exit 1 @@ -24,7 +25,7 @@ rm -f -- rtw.log dmesg | cut -d"]" -f2- | grep "RTW" >> rtw.log RESULT=$? -if [[ "$RESULT" != "0" ]]; then +if [ "$RESULT" != "0" ]; then echo "An error occurred while running: ${SCRIPT_NAME}" echo "Did you set a log level > 0 ?" exit 1 From c0281e1d05b301c73f02d135c678b6d053bf0716 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Thu, 26 Jan 2023 00:09:22 +1100 Subject: [PATCH 7/8] Addressed whines from "shellcheck -s sh" --- remove-driver.sh | 32 ++++++++++++++++---------------- save-log.sh | 1 - 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/remove-driver.sh b/remove-driver.sh index 8eff657..9b00cf7 100755 --- a/remove-driver.sh +++ b/remove-driver.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Purpose: Remove Realtek out-of-kernel USB WiFi adapter drivers. # @@ -33,11 +33,10 @@ KARCH="$(uname -m)" MODDESTDIR="/lib/modules/${KVER}/kernel/drivers/net/wireless/" DRV_NAME="rtl${MODULE_NAME}" -DRV_DIR="$(pwd)" OPTIONS_FILE="${MODULE_NAME}.conf" # check to ensure sudo was used -if [[ $EUID -ne 0 ]]; then +if [ "$(id -u)" -ne 0 ]; then echo "You must run this script with superuser (root) privileges." echo "Try: \"sudo ./${SCRIPT_NAME}\"" exit 1 @@ -66,28 +65,28 @@ echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}" # check for and remove non-dkms installations # standard naming -if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]]; then +if [ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]; then echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko" - rm -f ${MODDESTDIR}${MODULE_NAME}.ko - /sbin/depmod -a ${KVER} + rm -f "${MODDESTDIR}${MODULE_NAME}.ko" + /sbin/depmod -a "${KVER}" fi # check for and remove non-dkms installations # with rtl added to module name (PClinuxOS) -if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]]; then +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} + 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 +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} + 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 @@ -109,8 +108,8 @@ if command -v dkms >/dev/null 2>&1; then # 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 + if [ "$RESULT" = "0" ] || [ "$RESULT" = "3" ]; then + if [ "$RESULT" = "0" ]; then echo "${DRV_NAME}/${DRV_VERSION} has been removed" fi else @@ -130,9 +129,10 @@ echo "You may now delete the driver directory if desired." # if NoPrompt is not used, ask user some questions if [ $NO_PROMPT -ne 1 ]; then - read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r + echo "Do you want to reboot now? (recommended) [y/N]" + read -r REPLY echo - if [[ $REPLY =~ ^[Yy]$ ]]; then + if [ "$REPLY" = y ] || [ "$REPLY" = Y ]; then reboot fi fi diff --git a/save-log.sh b/save-log.sh index 0a79ca0..e3afbe8 100755 --- a/save-log.sh +++ b/save-log.sh @@ -1,4 +1,3 @@ -#!/usr/bin/dash #!/bin/sh # SCRIPT_NAME="save-log.sh" From 53e8b12bcbb52fdf9c0787801e18c7f258e7b464 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Thu, 26 Jan 2023 01:33:34 +1100 Subject: [PATCH 8/8] Use printf and case around the read statements to make the prompts a bit friendlier --- edit-options.sh | 8 ++++---- install-driver.sh | 16 ++++++++-------- remove-driver.sh | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/edit-options.sh b/edit-options.sh index 83c7f7d..aa9af3a 100755 --- a/edit-options.sh +++ b/edit-options.sh @@ -52,11 +52,11 @@ echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}" ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} -echo "Do you want to apply the new options by rebooting now? [y/N] " +printf "Do you want to apply the new options by rebooting now? [y/N] " read -r REPLY echo # move to a new line -if [ "${REPLY}" = y ] || [ "${REPLY}" = Y ]; then - reboot -fi +case "$REPLY" in + [yY]*) reboot ;; +esac exit 0 diff --git a/install-driver.sh b/install-driver.sh index 77712d5..5c6e1a9 100755 --- a/install-driver.sh +++ b/install-driver.sh @@ -342,19 +342,19 @@ fi # if NoPrompt is not used, ask user some questions if [ $NO_PROMPT -ne 1 ]; then - echo "Do you want to edit the driver options file now? [y/N]" + printf "Do you want to edit the driver options file now? [y/N] " read -r REPLY echo - if [ "$REPLY" = y ] || [ "$REPLY" = Y ]; then - ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} - fi + case "$REPLY" in + [yY]*) ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} ;; + esac - echo "Do you want to reboot now? (recommended) [y/N]" + printf "Do you want to reboot now? (recommended) [y/N] " read -r REPLY echo - if [ "$REPLY" = y ] || [ "$REPLY" = Y ]; then - reboot - fi + case "$REPLY" in + [yY]*) reboot ;; + esac fi exit 0 diff --git a/remove-driver.sh b/remove-driver.sh index 9b00cf7..7131eda 100755 --- a/remove-driver.sh +++ b/remove-driver.sh @@ -129,12 +129,12 @@ echo "You may now delete the driver directory if desired." # if NoPrompt is not used, ask user some questions if [ $NO_PROMPT -ne 1 ]; then - echo "Do you want to reboot now? (recommended) [y/N]" + printf "Do you want to reboot now? (recommended) [y/N] " read -r REPLY echo - if [ "$REPLY" = y ] || [ "$REPLY" = Y ]; then - reboot - fi + case "$REPLY" in + [yY]*) reboot ;; + esac fi exit 0