1
0
mirror of https://github.com/morrownr/8821cu-20210916.git synced 2024-12-21 22:06:32 +00:00

Merge pull request #58 from M0les/main

Remove "Bashisms" from scripts
This commit is contained in:
Nick 2023-01-26 07:29:28 -06:00 committed by GitHub
commit 169993a75a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 138 deletions

View File

@ -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 }')
@ -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

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# Purpose: Make it easier to edit the driver options file.
#
@ -26,42 +26,37 @@
SCRIPT_NAME="edit-options.sh"
SCRIPT_VERSION="20230120"
OPTIONS_FILE="8821cu.conf"
DEFAULT_EDITOR="$(<default-editor.txt)"
EDITORS_SEARCH=("${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" "vi")
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
fi
# Try to find the user's default text editor through the EDITORS_SEARCH array
for editor in ${EDITORS_SEARCH[@]}
do
if command -v "${editor}" >/dev/null 2>&1
then
TEXT_EDITOR="${editor}"
break
fi
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}\""
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
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 =~ ^[Yy]$ ]]
then
reboot
fi
case "$REPLY" in
[yY]*) reboot ;;
esac
exit 0

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# Purpose: Install Realtek out-of-kernel USB WiFi adapter drivers.
#
@ -38,12 +38,10 @@ OPTIONS_FILE="${MODULE_NAME}.conf"
SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }')
sproc=$(nproc)
DEFAULT_EDITOR="$(<default-editor.txt)"
EDITORS_SEARCH=("${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" "vi")
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
@ -55,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}\""
@ -64,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}\""
@ -81,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}\""
@ -90,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}\""
@ -99,18 +93,12 @@ then
fi
# Try to find the user's default text editor through the EDITORS_SEARCH array
for editor in ${EDITORS_SEARCH[@]}
do
if command -v "${editor}" >/dev/null 2>&1
then
TEXT_EDITOR="${editor}"
break
fi
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}\""
@ -121,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 ;;
@ -150,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
@ -165,20 +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
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
if command -v mokutil >/dev/null 2>&1; then
sb_state=$(mokutil --sb-state)
echo ": "${sb_state}
echo ": ${sb_state}"
fi
echo ": ---------------------------"
@ -195,11 +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}"
@ -209,11 +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}"
@ -225,11 +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}"
@ -238,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"
@ -256,17 +235,15 @@ 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
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."
@ -282,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
@ -306,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"
@ -326,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."
@ -349,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."
@ -363,29 +334,27 @@ 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
read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r
if [ $NO_PROMPT -ne 1 ]; then
printf "Do you want to edit the driver options file now? [y/N] "
read -r REPLY
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE}
fi
case "$REPLY" in
[yY]*) ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} ;;
esac
read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
printf "Do you want to reboot now? (recommended) [y/N] "
read -r REPLY
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
reboot
fi
case "$REPLY" in
[yY]*) reboot ;;
esac
fi
exit 0

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# Purpose: Remove Realtek out-of-kernel USB WiFi adapter drivers.
#
@ -33,12 +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
@ -48,8 +46,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,31 +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
@ -104,8 +98,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 +108,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,14 +128,13 @@ 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
read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
if [ $NO_PROMPT -ne 1 ]; then
printf "Do you want to reboot now? (recommended) [y/N] "
read -r REPLY
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
reboot
fi
case "$REPLY" in
[yY]*) reboot ;;
esac
fi
exit 0

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
SCRIPT_NAME="save-log.sh"
#
@ -12,7 +12,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 +24,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