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