1
0
mirror of https://github.com/morrownr/8821cu-20210916.git synced 2024-11-18 19:44:48 +00:00

Squashed all the if/then, while/do and for/do fragments onto single lines

This commit is contained in:
Miles Goodhew 2023-01-25 22:35:30 +11:00
parent 08c72e9cb4
commit 2954b29f7d
4 changed files with 44 additions and 88 deletions

View File

@ -7,10 +7,8 @@ SMEM=$(LANG=C free | awk '/Mem:/ { print $2 }')
sproc=$(nproc) sproc=$(nproc)
# Avoid Out of Memory condition in low-RAM systems by limiting core usage. # Avoid Out of Memory condition in low-RAM systems by limiting core usage.
if [ "$sproc" -gt 1 ] if [ "$sproc" -gt 1 ]; then
then if [ "$SMEM" -lt 1400000 ]; then
if [ "$SMEM" -lt 1400000 ]
then
sproc=2 sproc=2
fi fi
fi fi

View File

@ -28,22 +28,19 @@ SCRIPT_VERSION="20230120"
OPTIONS_FILE="8821cu.conf" OPTIONS_FILE="8821cu.conf"
DEFAULT_EDITOR="$(cat default-editor.txt)" DEFAULT_EDITOR="$(cat default-editor.txt)"
if [[ $EUID -ne 0 ]] if [[ $EUID -ne 0 ]]; then
then
echo "You must run this script with superuser (root) privileges." echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\"" echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1 exit 1
fi fi
# Try to find the user's default text editor through the EDITORS_SEARCH array # Try to find the user's default text editor through the EDITORS_SEARCH array
for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; do
do
command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break
done done
# Fail if no editor was found # Fail if no editor was found
if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1 if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1; then
then
echo "No text editor found (default: ${DEFAULT_EDITOR})." 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 "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor.txt' to specify your editor."
echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\"" 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 read -p "Do you want to apply the new options by rebooting now? [y/N] " -n 1 -r
echo # move to a new line echo # move to a new line
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY =~ ^[Yy]$ ]]; then
then
reboot reboot
fi fi

View File

@ -41,8 +41,7 @@ sproc=$(nproc)
DEFAULT_EDITOR="$(cat default-editor.txt)" DEFAULT_EDITOR="$(cat default-editor.txt)"
# check to ensure sudo was used # check to ensure sudo was used
if [[ $EUID -ne 0 ]] if [[ $EUID -ne 0 ]]; then
then
echo "You must run this script with superuser (root) privileges." echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\"" echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1 exit 1
@ -54,8 +53,7 @@ if ! echo "$PATH" | grep -qw sbin; then
fi fi
# check to ensure gcc is installed # check to ensure gcc is installed
if ! command -v gcc >/dev/null 2>&1 if ! command -v gcc >/dev/null 2>&1; then
then
echo "A required package is not installed." echo "A required package is not installed."
echo "Please install the following package: gcc" echo "Please install the following package: gcc"
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
@ -63,8 +61,7 @@ then
fi fi
# check to ensure make is installed # check to ensure make is installed
if ! command -v make >/dev/null 2>&1 if ! command -v make >/dev/null 2>&1; then
then
echo "A required package is not installed." echo "A required package is not installed."
echo "Please install the following package: make" echo "Please install the following package: make"
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
@ -80,8 +77,7 @@ if [ ! -d "/lib/modules/$(uname -r)/build" ]; then
fi fi
# check to ensure iw is installed # check to ensure iw is installed
if ! command -v iw >/dev/null 2>&1 if ! command -v iw >/dev/null 2>&1; then
then
echo "A required package is not installed." echo "A required package is not installed."
echo "Please install the following package: iw" echo "Please install the following package: iw"
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
@ -89,8 +85,7 @@ then
fi fi
# check to ensure rfkill is installed # check to ensure rfkill is installed
if ! command -v rfkill >/dev/null 2>&1 if ! command -v rfkill >/dev/null 2>&1; then
then
echo "A required package is not installed." echo "A required package is not installed."
echo "Please install the following package: rfkill" echo "Please install the following package: rfkill"
echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\"" echo "Once the package is installed, please run \"sudo ./${SCRIPT_NAME}\""
@ -98,14 +93,12 @@ then
fi fi
# Try to find the user's default text editor through the EDITORS_SEARCH array # Try to find the user's default text editor through the EDITORS_SEARCH array
for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; for TEXT_EDITOR in "${VISUAL}" "${EDITOR}" "${DEFAULT_EDITOR}" vi; do
do
command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break command -v "${TEXT_EDITOR}" >/dev/null 2>&1 && break
done done
# Fail if no editor was found # Fail if no editor was found
if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1 if ! command -v "${TEXT_EDITOR}" >/dev/null 2>&1; then
then
echo "No text editor found (default: ${DEFAULT_EDITOR})." 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 "Please install ${DEFAULT_EDITOR} or edit the file 'default-editor.txt' to specify your editor."
echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\"" echo "Once complete, please run \"sudo ./${SCRIPT_NAME}\""
@ -116,8 +109,7 @@ fi
NO_PROMPT=0 NO_PROMPT=0
# get the script options # get the script options
while [ $# -gt 0 ] while [ $# -gt 0 ]; do
do
case $1 in case $1 in
NoPrompt) NoPrompt)
NO_PROMPT=1 ;; NO_PROMPT=1 ;;
@ -145,8 +137,7 @@ echo ": ${KARCH} (ARCH)"
echo ": ${SMEM} (SMEM)" echo ": ${SMEM} (SMEM)"
# Avoid Out of Memory condition in low-RAM systems by limiting core usage. # Avoid Out of Memory condition in low-RAM systems by limiting core usage.
if [ "$sproc" -gt 1 ] if [ "$sproc" -gt 1 ]; then
then
if [ "$SMEM" -lt 1400000 ] if [ "$SMEM" -lt 1400000 ]
then then
sproc=2 sproc=2
@ -163,15 +154,13 @@ gcc_ver=$(gcc --version | grep -i gcc)
echo ": "${gcc_ver} echo ": "${gcc_ver}
# display dkms version if installed # display dkms version if installed
if command -v dkms >/dev/null 2>&1 if command -v dkms >/dev/null 2>&1; then
then
dkms_ver=$(dkms --version) dkms_ver=$(dkms --version)
echo ": "${dkms_ver} echo ": "${dkms_ver}
fi fi
# display secure mode status if mokutil is installed # display secure mode status if mokutil is installed
if command -v mokutil >/dev/null 2>&1 if command -v mokutil >/dev/null 2>&1; then
then
sb_state=$(mokutil --sb-state) sb_state=$(mokutil --sb-state)
echo ": "${sb_state} echo ": "${sb_state}
fi fi
@ -190,8 +179,7 @@ echo ": ---------------------------"
# check for and remove non-dkms installations # check for and remove non-dkms installations
# standard naming # standard naming
if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]] if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]]; then
then
echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko" echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko"
rm -f ${MODDESTDIR}${MODULE_NAME}.ko rm -f ${MODDESTDIR}${MODULE_NAME}.ko
/sbin/depmod -a ${KVER} /sbin/depmod -a ${KVER}
@ -204,8 +192,7 @@ fi
# check for and remove non-dkms installations # check for and remove non-dkms installations
# with rtl added to module name (PClinuxOS) # with rtl added to module name (PClinuxOS)
if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]] if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]]; then
then
echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko" echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko"
rm -f ${MODDESTDIR}rtl${MODULE_NAME}.ko rm -f ${MODDESTDIR}rtl${MODULE_NAME}.ko
/sbin/depmod -a ${KVER} /sbin/depmod -a ${KVER}
@ -220,8 +207,7 @@ fi
# with compressed module in a unique non-standard location (Armbian) # 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 # Example: /usr/lib/modules/5.15.80-rockchip64/kernel/drivers/net/wireless/rtl8821cu/8821cu.ko.xz
# Dear Armbiam, this is a really bad idea. # Dear Armbiam, this is a really bad idea.
if [[ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]] if [[ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]]; then
then
echo "Removing a non-dkms installation: /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" 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 rm -f /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz
/sbin/depmod -a ${KVER} /sbin/depmod -a ${KVER}
@ -233,10 +219,8 @@ then
fi fi
# check for and remove dkms installations # check for and remove dkms installations
if command -v dkms >/dev/null 2>&1 if command -v dkms >/dev/null 2>&1; then
then if dkms status | grep -i ${DRV_NAME}; then
if dkms status | grep -i ${DRV_NAME}
then
echo "Removing a dkms installation: ${DRV_NAME}" echo "Removing a dkms installation: ${DRV_NAME}"
dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all
echo "Removing ${OPTIONS_FILE} from /etc/modprobe.d" 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 cp -f ${OPTIONS_FILE} /etc/modprobe.d
# determine if dkms is installed and run the appropriate routines # determine if dkms is installed and run the appropriate routines
if ! command -v dkms >/dev/null 2>&1 if ! command -v dkms >/dev/null 2>&1; then
then
echo "The non-dkms installation routines are in use." echo "The non-dkms installation routines are in use."
make clean >/dev/null 2>&1 make clean >/dev/null 2>&1
@ -260,8 +243,7 @@ then
make -j$(nproc) make -j$(nproc)
RESULT=$? RESULT=$?
if [[ "$RESULT" != "0" ]] if [[ "$RESULT" != "0" ]]; then
then
echo "An error occurred: ${RESULT}" echo "An error occurred: ${RESULT}"
echo "Please report this error." echo "Please report this error."
echo "Please copy all screen output and paste it into the problem report." echo "Please copy all screen output and paste it into the problem report."
@ -277,8 +259,7 @@ then
make install make install
RESULT=$? RESULT=$?
if [[ "$RESULT" = "0" ]] if [[ "$RESULT" = "0" ]]; then
then
make clean >/dev/null 2>&1 make clean >/dev/null 2>&1
echo "The driver was installed successfully." echo "The driver was installed successfully."
else else
@ -301,10 +282,8 @@ else
# RESULT will be 3 if the DKMS tree already contains the same module/version # 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. # combo. You cannot add the same module/version combo more than once.
if [[ "$RESULT" != "0" ]] if [[ "$RESULT" != "0" ]]; then
then if [[ "$RESULT" = "3" ]]; then
if [[ "$RESULT" = "3" ]]
then
echo "This driver may already be installed." echo "This driver may already be installed."
echo "Run the following and then reattempt installation." echo "Run the following and then reattempt installation."
echo "$ sudo ./remove-driver.sh" echo "$ sudo ./remove-driver.sh"
@ -321,16 +300,14 @@ else
echo "The driver was added to dkms successfully." echo "The driver was added to dkms successfully."
fi fi
if command -v /usr/bin/time >/dev/null 2>&1 if command -v /usr/bin/time >/dev/null 2>&1; then
then
/usr/bin/time -f "Compile time: %U seconds" dkms build -m ${DRV_NAME} -v ${DRV_VERSION} /usr/bin/time -f "Compile time: %U seconds" dkms build -m ${DRV_NAME} -v ${DRV_VERSION}
else else
dkms build -m ${DRV_NAME} -v ${DRV_VERSION} dkms build -m ${DRV_NAME} -v ${DRV_VERSION}
fi fi
RESULT=$? RESULT=$?
if [[ "$RESULT" != "0" ]] if [[ "$RESULT" != "0" ]]; then
then
echo "An error occurred. dkms build error: ${RESULT}" echo "An error occurred. dkms build error: ${RESULT}"
echo "Please report this error." echo "Please report this error."
echo "Please copy all screen output and paste it into the problem report." 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} dkms install -m ${DRV_NAME} -v ${DRV_VERSION}
RESULT=$? RESULT=$?
if [[ "$RESULT" != "0" ]] if [[ "$RESULT" != "0" ]]; then
then
echo "An error occurred. dkms install error: ${RESULT}" echo "An error occurred. dkms install error: ${RESULT}"
echo "Please report this error." echo "Please report this error."
echo "Please copy all screen output and paste it into the problem report." echo "Please copy all screen output and paste it into the problem report."
@ -358,27 +334,23 @@ else
fi fi
# unblock wifi # unblock wifi
if command -v rfkill >/dev/null 2>&1 if command -v rfkill >/dev/null 2>&1; then
then
rfkill unblock wlan rfkill unblock wlan
else else
echo "Unable to run $ rfkill unblock wlan" echo "Unable to run $ rfkill unblock wlan"
fi fi
# if NoPrompt is not used, ask user some questions # if NoPrompt is not used, ask user some questions
if [ $NO_PROMPT -ne 1 ] if [ $NO_PROMPT -ne 1 ]; then
then
read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY =~ ^[Yy]$ ]]; then
then
${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE} ${TEXT_EDITOR} /etc/modprobe.d/${OPTIONS_FILE}
fi fi
read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY =~ ^[Yy]$ ]]; then
then
reboot reboot
fi fi
fi fi

View File

@ -37,8 +37,7 @@ DRV_DIR="$(pwd)"
OPTIONS_FILE="${MODULE_NAME}.conf" OPTIONS_FILE="${MODULE_NAME}.conf"
# check to ensure sudo was used # check to ensure sudo was used
if [[ $EUID -ne 0 ]] if [[ $EUID -ne 0 ]]; then
then
echo "You must run this script with superuser (root) privileges." echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\"" echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1 exit 1
@ -48,8 +47,7 @@ fi
NO_PROMPT=0 NO_PROMPT=0
# get the script options # get the script options
while [ $# -gt 0 ] while [ $# -gt 0 ]; do
do
case $1 in case $1 in
NoPrompt) NoPrompt)
NO_PROMPT=1 ;; NO_PROMPT=1 ;;
@ -68,8 +66,7 @@ echo ": ${SCRIPT_NAME} v${SCRIPT_VERSION}"
# check for and remove non-dkms installations # check for and remove non-dkms installations
# standard naming # standard naming
if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]] if [[ -f "${MODDESTDIR}${MODULE_NAME}.ko" ]]; then
then
echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko" echo "Removing a non-dkms installation: ${MODDESTDIR}${MODULE_NAME}.ko"
rm -f ${MODDESTDIR}${MODULE_NAME}.ko rm -f ${MODDESTDIR}${MODULE_NAME}.ko
/sbin/depmod -a ${KVER} /sbin/depmod -a ${KVER}
@ -77,8 +74,7 @@ fi
# check for and remove non-dkms installations # check for and remove non-dkms installations
# with rtl added to module name (PClinuxOS) # with rtl added to module name (PClinuxOS)
if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]] if [[ -f "${MODDESTDIR}rtl${MODULE_NAME}.ko" ]]; then
then
echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko" echo "Removing a non-dkms installation: ${MODDESTDIR}rtl${MODULE_NAME}.ko"
rm -f ${MODDESTDIR}rtl${MODULE_NAME}.ko rm -f ${MODDESTDIR}rtl${MODULE_NAME}.ko
/sbin/depmod -a ${KVER} /sbin/depmod -a ${KVER}
@ -88,8 +84,7 @@ fi
# with compressed module in a unique non-standard location (Armbian) # 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 # Example: /usr/lib/modules/5.15.80-rockchip64/kernel/drivers/net/wireless/rtl8821cu/8821cu.ko.xz
# Dear Armbiam, this is a really bad idea. # Dear Armbiam, this is a really bad idea.
if [[ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]] if [[ -f "/usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" ]]; then
then
echo "Removing a non-dkms installation: /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz" 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 rm -f /usr/lib/modules/${KVER}/kernel/drivers/net/wireless/${DRV_NAME}/${MODULE_NAME}.ko.xz
/sbin/depmod -a ${KVER} /sbin/depmod -a ${KVER}
@ -104,8 +99,7 @@ echo ": ${KVER}"
echo ": ${KARCH}" echo ": ${KARCH}"
# determine if dkms is installed and run the appropriate routines # determine if dkms is installed and run the appropriate routines
if command -v dkms >/dev/null 2>&1 if command -v dkms >/dev/null 2>&1; then
then
echo "Removing a dkms installation." echo "Removing a dkms installation."
# 2>/dev/null suppresses the output of dkms # 2>/dev/null suppresses the output of dkms
dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all 2>/dev/null 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 # 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 # however we still need to remove various files or the install script
# may complain. # may complain.
if [[ ("$RESULT" = "0")||("$RESULT" = "3") ]] if [[ ("$RESULT" = "0")||("$RESULT" = "3") ]]; then
then if [[ ("$RESULT" = "0") ]]; then
if [[ ("$RESULT" = "0") ]]
then
echo "${DRV_NAME}/${DRV_VERSION} has been removed" echo "${DRV_NAME}/${DRV_VERSION} has been removed"
fi fi
else else
@ -137,12 +129,10 @@ echo "The driver was removed successfully."
echo "You may now delete the driver directory if desired." echo "You may now delete the driver directory if desired."
# if NoPrompt is not used, ask user some questions # if NoPrompt is not used, ask user some questions
if [ $NO_PROMPT -ne 1 ] if [ $NO_PROMPT -ne 1 ]; then
then
read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY =~ ^[Yy]$ ]]; then
then
reboot reboot
fi fi
fi fi