From c0281e1d05b301c73f02d135c678b6d053bf0716 Mon Sep 17 00:00:00 2001 From: Miles Goodhew Date: Thu, 26 Jan 2023 00:09:22 +1100 Subject: [PATCH] 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"