Shellcheck compliance; refactor common logic into functions

This commit is contained in:
Martin D Kealey 2022-09-23 22:54:01 +10:00
parent a7e0de2f2f
commit 90fe4c4b8e
11 changed files with 541 additions and 610 deletions

View File

@ -5,23 +5,18 @@
# #
# To make this file executable: # To make this file executable:
# #
# $ chmod +x ARM64_RPI.sh # $ chmod +rx ARM64_RPI.sh
# #
# To execute this file: # To execute this file:
# #
# $ ./ARM64_RPI.sh # $ ./ARM64_RPI.sh
sed -i 's/CONFIG_PLATFORM_I386_PC = y/CONFIG_PLATFORM_I386_PC = n/g' Makefile sed -i '/^CONFIG_PLATFORM_/ s/ *=.*/ = n/
/^CONFIG_PLATFORM_ARM64_RPI *=/ s/ *=.*/ = y/' Makefile || {
status=$?
printf 'An error occurred and Raspberry Pi OS (64 bit) support was not turned on in Makefile.\n'
exit "$status"
}
sed -i 's/CONFIG_PLATFORM_ARM_RPI = y/CONFIG_PLATFORM_ARM_RPI = n/g' Makefile printf 'Raspberry Pi OS (64 bit) support was turned on in Makefile as planned.\n'
sed -i 's/CONFIG_PLATFORM_ARM64_RPI = n/CONFIG_PLATFORM_ARM64_RPI = y/g' Makefile
RESULT=$?
if [[ "$RESULT" != "0" ]]; then
echo "An error occurred and Raspberry Pi OS (64 bit) support was not turned on in Makefile."
exit 1
else
echo "Raspberry Pi OS (64 bit) support was turned on in Makefile as planned."
exit 0 exit 0
fi

View File

@ -13,17 +13,12 @@
# getconf LONG_BIT (need to work on this) # getconf LONG_BIT (need to work on this)
sed -i 's/CONFIG_PLATFORM_I386_PC = y/CONFIG_PLATFORM_I386_PC = n/g' Makefile sed -i '/^CONFIG_PLATFORM_/ s/ *=.*/ = n/
/^CONFIG_PLATFORM_ARM_RPI *=/ s/ *=.*/ = y/' Makefile || {
status=$?
printf 'An error occurred and Raspberry Pi OS (32 bit) support was not turned on in Makefile.\n'
exit "$status"
}
sed -i 's/CONFIG_PLATFORM_ARM_RPI = n/CONFIG_PLATFORM_ARM_RPI = y/g' Makefile printf 'Raspberry Pi OS (32 bit) support was turned on in Makefile as planned.\n'
RESULT=$?
if [[ "$RESULT" != "0" ]]; then
echo "An error occurred and Raspberry Pi OS (32 bit) support was not turned on in Makefile."
exit 1
else
echo "Raspberry Pi OS (32 bit) support was turned on in Makefile as planned."
exit 0 exit 0
fi
sed -i 's/CONFIG_PLATFORM_ARM64_RPI = y/CONFIG_PLATFORM_ARM64_RPI = n/g' Makefile

View File

@ -12,12 +12,11 @@
# #
# $ ./cmode-off.sh # $ ./cmode-off.sh
sed -i 's/CONFIG_CONCURRENT_MODE = y/CONFIG_CONCURRENT_MODE = n/g' Makefile sed -i '/^CONFIG_CONCURRENT_MODE *=/ s/ *=.*/ = n/' Makefile || {
RESULT=$? status=$?
printf 'An error occurred and Concurrent Mode was not turned off in Makefile.\n'
exit "$status"
}
if [[ "$RESULT" != "0" ]]; then printf 'Concurrent Mode was turned off in Makefile as planned.\n'
echo "An error occurred and Concurrent Mode was not turned off in Makefile." exit 0
exit 1
else
echo "Concurrent Mode was turned off in Makefile as planned."
fi

View File

@ -12,12 +12,11 @@
# #
# $ ./cmode-on.sh # $ ./cmode-on.sh
sed -i 's/CONFIG_CONCURRENT_MODE = n/CONFIG_CONCURRENT_MODE = y/g' Makefile sed -i '/^CONFIG_CONCURRENT_MODE *=/ s/ *=.*/ = y/' Makefile || {
RESULT=$? status=$?
printf 'An error occurred and Concurrent Mode was not turned on in Makefile.\n'
exit "$status"
}
if [[ "$RESULT" != "0" ]]; then printf 'Concurrent Mode was turned on in Makefile as planned.\n'
echo "An error occurred and Concurrent Mode was not turned on in Makefile." exit 0
exit 1
else
echo "Concurrent Mode was turned on in Makefile as planned."
fi

View File

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
# #
OPTIONS_FILE="88x2bu.conf"
SCRIPT_NAME="edit-options.sh"
# #
# Purpose: Make it easier to edit the driver options file. # Purpose: Make it easier to edit the driver options file.
# #
@ -13,18 +11,21 @@ SCRIPT_NAME="edit-options.sh"
# #
# $ sudo ./edit-options.sh # $ sudo ./edit-options.sh
# #
if [[ $EUID -ne 0 ]]
options_file=88x2bu.conf
if (( EUID != 0 ))
then then
echo "You must run this script with superuser (root) privileges." printf 'You must run this script with superuser (root) privileges.\n'
echo "Try: \"sudo ./${SCRIPT_NAME}\"" printf 'Try: "sudo %s"\n' "$0"
exit 1 exit 1
fi fi
nano /etc/modprobe.d/${OPTIONS_FILE} ${EDITOR:-nano} "/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 || exit 1
echo # move to a new line printf '\n' # move to a next line
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY = [Yy] ]]
then then
reboot reboot
fi fi

View File

@ -4,42 +4,45 @@
# #
# This version of the installation script does not use dkms. # This version of the installation script does not use dkms.
SCRIPT_NAME="install-driver-no-dkms.sh" SCRIPT_VERSION=20220923
SCRIPT_VERSION="20220821"
OPTIONS_FILE="88x2bu.conf" options_file=88x2bu.conf
BLACKLIST_FILE="rtw88_8822bu.conf" blacklist_file=rtw88_8822bu.conf
# check to ensure sudo was used
if (( EUID != 0 ))
then
printf 'You must run this script with superuser (root) privileges.\n'
printf 'Try: "sudo %s"\n' "$0"
exit 1
fi
# support for NoPrompt allows non-interactive use of this script # support for NoPrompt allows non-interactive use of this script
NO_PROMPT=0 no_prompt=0
# get the options # get the options
while [ $# -gt 0 ] for ((;$#;)) do
do
case $1 in case $1 in
NoPrompt) NoPrompt)
NO_PROMPT=1 ;; no_prompt=1 ;;
*h|*help|*) -h|--help|*)
echo "Syntax $0 <NoPrompt>" cat <<- EndOfHelp
echo " NoPrompt - noninteractive mode" Usage: $0 [NoPrompt]
echo " -h|--help - Show help" $0 --help
exit 1 NoPrompt - noninteractive mode
-h|--help - Show help
EndOfHelp
[[ $1 = -h || $1 = --help ]] # don't use non-zero exit status when help requested
exit
;; ;;
esac esac
shift shift
done done
# check to ensure sudo was used
if [[ $EUID -ne 0 ]]
then
echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1
fi
# information that helps with bug reports # information that helps with bug reports
# displays script name and version # displays script name and version
echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}" printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
# kernel # kernel
uname -r uname -r
@ -47,62 +50,53 @@ uname -r
# architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit # architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit
uname -m uname -m
echo "Starting installation..." printf 'Starting installation...\n'
# sets module parameters (driver options) # sets module parameters (driver options)
echo "Copying ${OPTIONS_FILE} to: /etc/modprobe.d"
cp -f ${OPTIONS_FILE} /etc/modprobe.d
# blacklist the in-kernel module (driver) so that there is no conflict # blacklist the in-kernel module (driver) so that there is no conflict
echo "Copying ${BLACKLIST_FILE} to: /etc/modprobe.d" printf 'Copying options and blacklist files into /etc/modprobe.d\n'
cp -f ${BLACKLIST_FILE} /etc/modprobe.d cp -fv "$options_file" "$blacklist_file" /etc/modprobe.d
make clean make clean
make make || {
RESULT=$? status=$?
printf 'An error occurred. Error = %d\n' "$status"
printf 'Please report this error.\n'
printf 'Please copy all screen output and paste it into the report.\n'
printf 'You will need to run the following before reattempting installation.\n'
printf '$ sudo ./remove-driver-no-dkms.sh\n'
exit "$status"
}
if [[ "$RESULT" != "0" ]] make install || {
then status=$?
echo "An error occurred. Error = ${RESULT}" printf 'An error occurred. Error = %d\n' "$status"
echo "Please report this error." printf 'Please report this error.\n'
echo "Please copy all screen output and paste it into the report." printf 'Please copy all screen output and paste it into the report.\n'
echo "You will need to run the following before reattempting installation." printf 'You will need to run the following before reattempting installation.\n'
echo "$ sudo ./remove-driver-no-dkms.sh" printf '$ sudo %s\n' "${*:0}"
exit $RESULT exit "$status"
fi }
make install printf 'The driver was installed successfully.\n'
RESULT=$?
if [[ "$RESULT" != "0" ]]
then
echo "An error occurred. Error = ${RESULT}"
echo "Please report this error."
echo "Please copy all screen output and paste it into the report."
echo "You will need to run the following before reattempting installation."
echo "$ sudo ./remove-driver-no-dkms.sh"
exit $RESULT
fi
echo "The driver was installed successfully."
# unblock wifi # unblock wifi
rfkill unblock wlan rfkill unblock wlan
# if NoPrompt is not used, ask user some questions to complete installation # if NoPrompt is not used, ask user some questions to complete installation
if [ $NO_PROMPT -ne 1 ] if (( ! no_prompt ))
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 || exit 1
echo printf '\n'
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY = [Yy] ]]
then then
nano /etc/modprobe.d/${OPTIONS_FILE} ${EDITOR:-nano} "/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 || exit 1
echo printf '\n'
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY = [Yy] ]]
then then
reboot reboot
fi fi

View File

@ -4,59 +4,61 @@
# #
# This version of the installation script uses dkms. # This version of the installation script uses dkms.
SCRIPT_NAME="install-driver.sh" SCRIPT_VERSION=20220923
SCRIPT_VERSION="20220821"
OPTIONS_FILE="88x2bu.conf"
BLACKLIST_FILE="rtw88_8822bu.conf"
DRV_NAME="rtl88x2bu" options_file=88x2bu.conf
DRV_VERSION="5.13.1" blacklist_file=rtw88_8822bu.conf
DRV_DIR="$(pwd)" drv_name=rtl88x2bu
KRNL_VERSION="$(uname -r)" drv_version=5.13.1
drv_dir=$PWD
clear clear
# support for NoPrompt allows non-interactive use of this script # support for NoPrompt allows non-interactive use of this script
NO_PROMPT=0 no_prompt=0
# get the options # get the options
while [ $# -gt 0 ] for ((;$#;)) do
do
case $1 in case $1 in
NoPrompt) NoPrompt)
NO_PROMPT=1 ;; no_prompt=1 ;;
*h|*help|*) *h|*help|*)
echo "Syntax $0 <NoPrompt>" cat <<- EndOfHelp
echo " NoPrompt - noninteractive mode" Usage: $0 [NoPrompt]
echo " -h|--help - Show help" $0 --help
exit 1 NoPrompt - noninteractive mode
-h|--help - Show help
EndOfHelp
[[ $1 = -h || $1 = --help ]] # don't use non-zero exit status when help requested
exit
;; ;;
esac esac
shift shift
done done
# check to ensure sudo was used # check to ensure sudo was used
if [[ $EUID -ne 0 ]] if (( EUID != 0 ))
then then
echo "You must run this script with superuser (root) privileges." printf 'You must run this script with superuser (root) privileges.\n'
echo "Try: \"sudo ./${SCRIPT_NAME}\"" printf 'Try: "sudo %s"\n' "$0"
exit 1 exit 1
fi fi
# check for previous installation # check for previous installation
if [[ -d "/usr/src/${DRV_NAME}-${DRV_VERSION}" ]] if [[ -d "/usr/src/$drv_name-$drv_version" ]]
then then
echo "It appears that this driver may already be installed." printf 'It appears that this driver may already be installed.\n'
echo "You will need to run the following before reattempting installation." printf 'You will need to run the following before reattempting installation.\n'
echo "$ sudo ./remove-driver.sh" printf '$ sudo ./remove-driver.sh\n'
exit 1 exit 1
fi fi
# information that helps with bug reports # information that helps with bug reports
# displays script name and version # displays script name and version
echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}" printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
# kernel # kernel
uname -r uname -r
@ -64,77 +66,65 @@ uname -r
# architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit # architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit
uname -m uname -m
echo "Starting installation..." printf 'Starting installation...\n'
# the add command requires source in /usr/src/${DRV_NAME}-${DRV_VERSION} # the add command requires source in "/usr/src/$drv_name-$drv_version"
echo "Copying source files to: /usr/src/${DRV_NAME}-${DRV_VERSION}" printf 'Copying source files to: %s\n' "/usr/src/$drv_name-$drv_version"
cp -rf "${DRV_DIR}" /usr/src/${DRV_NAME}-${DRV_VERSION} cp -rf "$drv_dir" "/usr/src/$drv_name-$drv_version"
# sets module parameters (driver options) # sets module parameters (driver options)
echo "Copying ${OPTIONS_FILE} to: /etc/modprobe.d"
cp -f ${OPTIONS_FILE} /etc/modprobe.d
# blacklist the in-kernel module (driver) so that there is no conflict # blacklist the in-kernel module (driver) so that there is no conflict
echo "Copying ${BLACKLIST_FILE} to: /etc/modprobe.d" printf 'Copying options and blacklist files into: %s\n' "/etc/modprobe.d"
cp -f ${BLACKLIST_FILE} /etc/modprobe.d cp -fv "$options_file" "$blacklist_file" /etc/modprobe.d
dkms add -m ${DRV_NAME} -v ${DRV_VERSION} dkms add -m "$drv_name" -v "$drv_version" || {
RESULT=$? status=$?
printf 'An error occurred. dkms add error = %d\n' "$status"
printf 'Please report this error.\n'
printf 'Please copy all screen output and paste it into the report.\n'
printf 'You will need to run the following before reattempting installation.\n'
printf '$ sudo ./remove-driver.sh\n'
exit "$status"
}
if [[ "$RESULT" != "0" ]] dkms build -m "$drv_name" -v "$drv_version" || {
then status=$?
echo "An error occurred. dkms add error = ${RESULT}" printf 'An error occurred. dkms build error = %d\n' "$status"
echo "Please report this error." printf 'Please report this error.\n'
echo "Please copy all screen output and paste it into the report." printf 'Please copy all screen output and paste it into the report.\n'
echo "You will need to run the following before reattempting installation." printf 'You will need to run the following before reattempting installation.\n'
echo "$ sudo ./remove-driver.sh" printf '$ sudo ./remove-driver.sh\n'
exit $RESULT exit "$status"
fi }
dkms build -m ${DRV_NAME} -v ${DRV_VERSION} dkms install -m "$drv_name" -v "$drv_version" || {
RESULT=$? status=$?
printf 'An error occurred. dkms install error = %d\n' "$status"
printf 'Please report this error.\n'
printf 'Please copy all screen output and paste it into the report.\n'
printf 'You will need to run the following before reattempting installation.\n'
printf '$ sudo ./remove-driver.sh\n'
exit "$status"
}
if [[ "$RESULT" != "0" ]] printf 'The driver was installed successfully.\n'
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 report."
echo "You will need to run the following before reattempting installation."
echo "$ sudo ./remove-driver.sh"
exit $RESULT
fi
dkms install -m ${DRV_NAME} -v ${DRV_VERSION}
RESULT=$?
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 report."
echo "You will need to run the following before reattempting installation."
echo "$ sudo ./remove-driver.sh"
exit $RESULT
fi
echo "The driver was installed successfully."
# unblock wifi # unblock wifi
rfkill unblock wlan rfkill unblock wlan
# if NoPrompt is not used, ask user some questions to complete installation # if NoPrompt is not used, ask user some questions to complete installation
if [ $NO_PROMPT -ne 1 ] if (( ! no_prompt ))
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 || exit 1
echo printf '\n'
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY = [Yy] ]]
then then
nano /etc/modprobe.d/${OPTIONS_FILE} ${EDITOR:-nano} "/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 || exit 1
echo printf '\n'
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY = [Yy] ]]
then then
reboot reboot
fi fi

View File

@ -4,64 +4,63 @@
# #
# This version of the removal script does not use dkms. # This version of the removal script does not use dkms.
SCRIPT_NAME="remove-driver-no-dkms.sh" SCRIPT_VERSION=20220923
SCRIPT_VERSION="20220821"
OPTIONS_FILE="88x2bu.conf"
BLACKLIST_FILE="rtw88_8822bu.conf"
echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}" options_file=88x2bu.conf
blacklist_file=rtw88_8822bu.conf
# check to ensure sudo was used
if (( EUID != 0 ))
then
printf 'You must run this script with superuser (root) privileges.\n'
printf 'Try: "sudo %s"\n' "${*:0}"
exit 1
fi
printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
# support for NoPrompt allows non-interactive use of this script # support for NoPrompt allows non-interactive use of this script
NO_PROMPT=0 no_prompt=0
# get the options # get the options
while [ $# -gt 0 ] for ((;$#;)) do
do
case $1 in case $1 in
NoPrompt) NoPrompt)
NO_PROMPT=1 ;; no_prompt=1 ;;
*h|*help|*) -h|--help|*)
echo "Syntax $0 <NoPrompt>" cat <<- EndOfHelp
echo " NoPrompt - noninteractive mode" Usage: $0 [NoPrompt]
echo " -h|--help - Show help" $0 --help
exit 1 NoPrompt - noninteractive mode
-h|--help - Show help
EndOfHelp
[[ $1 = -h || $1 = --help ]] # don't use non-zero exit status when help requested
exit
;; ;;
esac esac
shift shift
done done
# check to ensure sudo was used printf 'Starting removal...\n'
if [[ $EUID -ne 0 ]]
make uninstall || {
status=$?
printf 'An error occurred. Error = %u\n' "$status"
printf 'Please report this error.\n'
exit "$status"
}
printf 'Deleting options and blacklist files from /etc/modprobe.d'
rm -fv "/etc/modprobe.d/$options_file" "/etc/modprobe.d/$blacklist_file"
printf 'The driver was removed successfully.\n'
printf 'You may now delete the driver directory if desired.\n'
if (( ! no_prompt ))
then then
echo "You must run this script with superuser (root) privileges." read -p 'Do you want to reboot now? (recommended) [y/N] ' -n 1 -r || exit
echo "Try: \"sudo ./${SCRIPT_NAME}\"" printf '\n'
exit 1 if [[ $REPLY = [Yy] ]]
fi
echo "Starting removal..."
make uninstall
RESULT=$?
if [[ ("$RESULT" = "0")]]
then
echo "Deleting ${OPTIONS_FILE} from /etc/modprobe.d"
rm -f /etc/modprobe.d/${OPTIONS_FILE}
echo "Deleting ${BLACKLIST_FILE} from /etc/modprobe.d"
rm -f /etc/modprobe.d/${BLACKLIST_FILE}
echo "The driver was removed successfully."
echo "You may now delete the driver directory if desired."
else
echo "An error occurred. Error = ${RESULT}"
echo "Please report this error."
exit $RESULT
fi
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 then
reboot reboot
fi fi

View File

@ -4,76 +4,78 @@
# #
# This version of the removal script uses dkms. # This version of the removal script uses dkms.
SCRIPT_NAME="remove-driver.sh" SCRIPT_VERSION=20220923
SCRIPT_VERSION="20220821"
OPTIONS_FILE="88x2bu.conf"
BLACKLIST_FILE="rtw88_8822bu.conf"
DRV_NAME="rtl88x2bu" options_file=88x2bu.conf
DRV_VERSION="5.13.1" blacklist_file=rtw88_8822bu.conf
drv_name=rtl88x2bu
drv_version=5.13.1
DRV_DIR="$(pwd)" # check to ensure sudo was used
KRNL_VERSION="$(uname -r)" if (( EUID != 0 ))
then
printf 'You must run this script with superuser (root) privileges.\n'
printf 'Try: "sudo %s"\n' "${*:0}"
exit 1
fi
clear clear
echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}" printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
# support for NoPrompt allows non-interactive use of this script # support for NoPrompt allows non-interactive use of this script
NO_PROMPT=0 no_prompt=0
# get the options # get the options
while [ $# -gt 0 ] for ((;$#;)) do
do
case $1 in case $1 in
NoPrompt) NoPrompt)
NO_PROMPT=1 ;; no_prompt=1 ;;
*h|*help|*) -h|--help|*)
echo "Syntax $0 <NoPrompt>" cat <<- EndOfHelp
echo " NoPrompt - noninteractive mode" Usage: $0 [NoPrompt]
echo " -h|--help - Show help" $0 --help
exit 1 NoPrompt - noninteractive mode
-h|--help - Show help
EndOfHelp
[[ $1 = -h || $1 = --help ]] # don't use non-zero exit status when help requested
exit
;; ;;
esac esac
shift shift
done done
# check to ensure sudo was used ok_if_status_is() {
if [[ $EUID -ne 0 ]] local s=$? x
for x do (( s==x )) && return 0 ; done
return "$s"
}
printf 'Starting removal...\n'
dkms remove -m "$drv_name" -v "$drv_version" --all ||
ok_if_status_is 3 || { # $? == 3 means there are no instances of this
# module to remove, so don't treat this as an
# error.
status=$?
printf 'An error occurred. dkms remove error = %d\n' "$status"
printf 'Please report this error.\n'
exit "$status"
}
printf 'Deleting options and blacklist files from /etc/modprobe.d\n'
rm -fv "/etc/modprobe.d/$options_file" "/etc/modprobe.d/$blacklist_file"
printf 'Deleting source files from %s\n' "/usr/src/$drv_name-$drv_version"
rm -rf "/usr/src/$drv_name-$drv_version"
printf 'The driver was removed successfully.\n'
printf 'You may now delete the driver directory if desired.\n'
if (( ! no_prompt ))
then then
echo "You must run this script with superuser (root) privileges." read -p 'Do you want to reboot now? (recommended) [y/N] ' -n 1 -r || exit
echo "Try: \"sudo ./${SCRIPT_NAME}\"" printf '\n'
exit 1 if [[ $REPLY = [Yy] ]]
fi
echo "Starting removal..."
dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all
RESULT=$?
# RESULT will be 3 if there are no instances of module to remove
# however we still need to remove the files or the install script
# will complain.
if [[ ("$RESULT" = "0")||("$RESULT" = "3") ]]
then
echo "Deleting ${OPTIONS_FILE} from /etc/modprobe.d"
rm -f /etc/modprobe.d/${OPTIONS_FILE}
echo "Deleting ${BLACKLIST_FILE} from /etc/modprobe.d"
rm -f /etc/modprobe.d/${BLACKLIST_FILE}
echo "Deleting source files from /usr/src/${DRV_NAME}-${DRV_VERSION}"
rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION}
echo "The driver was removed successfully."
echo "You may now delete the driver directory if desired."
else
echo "An error occurred. dkms remove error = ${RESULT}"
echo "Please report this error."
exit $RESULT
fi
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 then
reboot reboot
fi fi

View File

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
# #
SCRIPT_NAME="save-log.sh"
#
# Purpose: Save a log file with RTW lines only. # Purpose: Save a log file with RTW lines only.
# #
# To make this file executable: # To make this file executable:
@ -12,23 +10,25 @@ SCRIPT_NAME="save-log.sh"
# #
# $ sudo ./edit-options.sh # $ sudo ./edit-options.sh
# #
if [[ $EUID -ne 0 ]]; then
echo "You must run this script with superuser (root) privileges." if (( EUID != 0 )); then
echo "Try: \"sudo ./${SCRIPT_NAME}\"" printf 'You must run this script with superuser (root) privileges.\n'
printf 'Try: "sudo %s"\n' "${*:0}"
exit 1 exit 1
fi fi
# Deletes existing log # Deletes existing log
rm -f -- rtw.log rm -f -- rtw.log
dmesg | cut -d"]" -f2- | grep "RTW" >> rtw.log dmesg |
RESULT=$? cut -d ']' -f2- |
grep RTW >> rtw.log || {
status=$?
if [[ "$RESULT" != "0" ]]; then printf 'An error occurred while running: %s\n' "${0##*}"
echo "An error occurred while running: ${SCRIPT_NAME}" printf 'Did you set a log level > 0 ?\n'
echo "Did you set a log level > 0 ?" exit "$status"
exit 1 }
else
echo "rtw.log saved successfully." printf 'rtw.log saved successfully.\n'
exit 0 exit 0
fi

View File

@ -1,110 +1,168 @@
#!/bin/bash #!/bin/bash
SCRIPT_NAME="start-mon.sh" SCRIPT_VERSION=20220923
SCRIPT_VERSION="20220408"
# Purpose: Start and configure monitor mode on the provided interface # Purpose: Start and configure monitor mode on the provided interface
# Usage: $ sudo ./start-mon.sh [interface:wlan0] # Usage: $ sudo ./start-mon.sh [interface:wlan0]
# There is no filename globbing in this script, so disable it to stop accidents
set -f
clear clear
# Check that sudo was used to start the script # Check that sudo was used to start the script
if [[ $EUID -ne 0 ]] if (( EUID != 0 ))
then then
echo printf '\n ERROR: You must run this script with superuser (root) privileges.\n'
echo " ERROR: You must run this script with superuser (root) privileges." printf ' Try: "sudo %s"\n\n' "${*:0}"
echo -e " Try: sudo ./${SCRIPT_NAME} [interface:wlan0]"
echo
exit 1 exit 1
fi fi
# Add code to check if iw and ip are installed # Add code to check if iw and ip are installed
# Ensure WiFi radio is not blocked # Ensure WiFi radio is not blocked
sudo rfkill unblock wlan sudo rfkill unblock wlan
# Assign default monitor mode interface name # Assign default monitor mode interface name
iface0mon='wlan0mon' iface0mon=wlan0mon
# Assign default channel # Assign default channel
chan=6 chan=6
# Activate option to set automatic (1) or manual (2) interface mode # Activate option to set automatic (1) or manual (2) interface mode
# #
# Option 1: if you only have one wlan interface (automatic detection) # Option 1: if you only have one wlan interface (automatic detection)
#iface0=`iw dev | grep 'Interface' | sed 's/Interface //'` # iface0=$( iw dev |
# sed -e '/^[[:space:]]*Interface[[:space:]]*/! d' -e 's///' )
# #
# Option 2: if you have more than one wlan interface (default wlan0) # Option 2: if you have more than one wlan interface (default wlan0)
iface0=${1:-wlan0} iface0=${1:-wlan0}
get_if_info() {
local iface=$1 ii ij
# shellcheck ignore=SC1007
iface_name= iface_type= iface_addr= iface_chan= iface_txpw= iface_state=
ii=$( iw dev "$iface" info | tr -s ' \t\\\n\r' ' ' )
ij=${ii#*' Interface '} ; [[ $ij = "$ii" ]] || iface_name=${ij%%' '*}
ij=${ii#*' addr '} ; [[ $ij = "$ii" ]] || iface_type=${ij%%' '*}
ij=${ii#*' type '} ; [[ $ij = "$ii" ]] || iface_addr=${ij%%' '*}
ij=${ii#*' channel '} ; [[ $ij = "$ii" ]] || iface_chan=${ij%%' '*}
ij=${ii#*' txpower '} ; [[ $ij = "$ii" ]] || ij=${ij%%' '*} iface_txpw=${ij%dBm}
ij=' '$( ip addr show "$iface" | tr -s ' \t\\\n\r' ' ' )
ij=${ii#*' state '} ; [[ $ij = "$ii" ]] || iface_state=${ij%%' '*}
}
print_if_info() {
local iface=$1 m n
# Set iface0 down
ip link set dev $iface0 down
# Check if iface0 exists and continue if true
if [ $? -eq 0 ]
then
# Disable interfering processes
PROCESSES="wpa_action\|wpa_supplicant\|wpa_cli\|dhclient\|ifplugd\|dhcdbd\|dhcpcd\|udhcpc\|NetworkManager\|knetworkmanager\|avahi-autoipd\|avahi-daemon\|wlassistant\|wifibox\|net_applet\|wicd-daemon\|wicd-client\|iwd"
unset match
match="$(ps -A -o comm= | grep ${PROCESSES} | grep -v grep | wc -l)"
badProcs=$(ps -A -o pid=PID -o comm=Name | grep "${PROCESSES}\|PID")
for pid in $(ps -A -o pid= -o comm= | grep ${PROCESSES} | awk '{print $1}'); do
command kill -19 "${pid}" # -19 = STOP
done
clear clear
echo printf '\n --------------------------------\n'
echo ' The following processes have been stopped:' printf ' %-20s %s\n' "${0##*/}" "$SCRIPT_VERSION"
echo printf ' --------------------------------\n'
echo "${badProcs}" printf ' WiFi Interface:\n'
echo printf ' %s\n' "$iface"
echo ' Note: The above processes can be returned' printf ' --------------------------------\n'
echo ' to a normal state at the end of this script.' for m in name type state addr chan txpw
echo do
read -p " Press any key to continue... " -n 1 -r n=iface_$m ; n=${!n} ;
[[ -n $n ]] && printf ' %-5.5s - %s\n' "$m" "$n"
done
printf ' --------------------------------\n\n'
}
# str_join
# $1 name of output variable
# $2 joiner
# $3... words to be joined
# puts $3$2$4$2$5$2$6$2$7... into variable $1
str_join() { local IFS="$2" ; printf -v "$1" %s "${*:3}" ; }
# Set $iface0 down
ip link set dev "$iface0" down || {
clear
printf '\n ERROR: Please provide an existing interface as parameter!\n'
printf ' Usage: $ sudo %s [interface:wlan0]\n' "$0"
printf ' Tip: $ iw dev\n\n'
exit 1
}
#Suspend interfering processes
ProcNames=(
autoipd
avahi
avahi
client
daemon
daemon
dhcdbd
dhclient
dhcpcd
ifplugd
iwd
knetworkmanager
net_applet
NetworkManager
udhcpc
wicd
wicd
wifibox
wlassistant
wpa_action
wpa_cli
wpa_supplicant
)
IFS=$' \t\n'
pids=( $(
# pgrep takes a RegEx pattern, which can be a pipe-separated list of alternatives
str_join ProcPattern '|' "${ProcNames[@]}"
pgrep -x "$ProcPattern"
) ) # split output on any whitespace
if (( ${#pids[@]} > 0 ))
then
kill -STOP "${pids[@]}"
clear
printf '\n The following processes have been stopped:\n\n'
# ps -p takes a comma-separated list
str_join pidlist ',' "${pids[@]}"
# pidlist is defined by str_join
# shellcheck disable=SC2154
ps -o pid=PID,state=State,comm=Name -p "$pidlist"
printf '\n (state T means stopped)\n\n'
printf ' Note: The above processes can be returned\n'
printf ' to a normal state at the end of this script.\n\n'
else
clear
printf '\n There are no processes that need stopping.\n\n'
fi
read -p ' Press any key to continue... ' -n 1 -r || exit
# Display interface settings # Display interface settings
clear get_if_info "$iface0"
echo print_if_info "$iface0" 4
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0 info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0 info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0 | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0 info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
echo ' --------------------------------'
echo
# Set addr (has to be done before renaming the interface) # Set addr (has to be done before renaming the interface)
iface_addr_orig=$iface_addr iface_addr_orig=$iface_addr
read -p " Do you want to set a new addr? [y/N] " -n 1 -r read -p ' Do you want to set a new addr? [y/N] ' -n 1 -r || exit
echo printf '\n'
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY = [Yy] ]]
then then
read -p " What addr do you want? ( e.g. 12:34:56:78:90:ab ) " iface_addr read -p ' What addr do you want? ( e.g. 12:34:56:78:90:ab ) ' iface_addr || exit
# need code to ID bad addresses # need code to ID bad addresses
ip link set dev $iface0 address $iface_addr ip link set dev "$iface0" address "$iface_addr"
fi fi
# Set monitor mode # Set monitor mode
#iw dev <devname> set monitor <flag> #iw dev <devname> set monitor <flag>
# Valid monitor flags are: # Valid monitor flags are:
@ -116,189 +174,88 @@ then
# active: use active mode (ACK incoming unicast packets) # active: use active mode (ACK incoming unicast packets)
# mumimo-groupid <GROUP_ID>: use MUMIMO according to a group id # mumimo-groupid <GROUP_ID>: use MUMIMO according to a group id
# mumimo-follow-mac <MAC_ADDRESS>: use MUMIMO according to a MAC address # mumimo-follow-mac <MAC_ADDRESS>: use MUMIMO according to a MAC address
iw dev $iface0 set monitor none iw dev "$iface0" set monitor none
# Rename interface # Rename interface
ip link set dev $iface0 name $iface0mon ip link set dev "$iface0" name "$iface0mon"
# Bring the interface up # Bring the interface up
ip link set dev $iface0mon up ip link set dev "$iface0mon" up
# Display interface settings # Display interface settings
clear get_if_info "$iface0mon"
echo print_if_info "$iface0" 4
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
echo ' --------------------------------'
echo
# Set channel # Set channel
read -p " Do you want to set the channel? [y/N] " -n 1 -r read -p ' Do you want to set the channel? [y/N] ' -n 1 -r || exit
echo printf '\n'
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY = [Yy] ]]
then then
read -p " What channel do you want to set? " chan read -p ' What channel do you want to set? ' chan || exit
# Documentation: # Documentation:
# iw dev <devname> set channel <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] # iw dev "$devname" set channel "$channel" [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]
# iw dev <devname> set freq <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] # iw dev "$devname" set freq "$freq" [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]
# iw dev <devname> set freq <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]] # iw dev "$devname" set freq "$control_freq" [5|10|20|40|80|80+80|160] ["$center1_freq" ["$center2_freq"]]
# Select one or modify as required: # Select one or modify as required:
iw dev $iface0mon set channel $chan iw dev "$iface0mon" set channel "$chan"
# iw dev $iface0mon set channel $chan HT40- # iw dev "$iface0mon" set channel "$chan" HT40-
# iw dev $iface0mon set channel $chan 80MHz # iw dev "$iface0mon" set channel "$chan" 80MHz
# To test if channel was set correctly: # To test if channel was set correctly:
# aireplay-ng --test <wlan0> # aireplay-ng --test <wlan0>
fi fi
# Display interface settings # Display interface settings
clear
echo
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
iface_chan=$(iw dev $iface0mon info | grep 'channel' | sed 's/channel //' | sed -e 's/^[ \t]*//')
echo ' chan - ' $chan
iface_txpw=$(iw dev $iface0mon info | grep 'txpower' | sed 's/txpower //' | sed -e 's/^[ \t]*//')
echo ' txpw - ' $iface_txpw
echo ' --------------------------------'
echo
get_if_info "$iface0mon"
print_if_info "$iface0" 6
# Set txpw # Set txpw
read -p " Do you want to set the txpower? [y/N] " -n 1 -r read -p ' Do you want to set the txpower? [y/N] ' -n 1 -r || exit
echo printf '\n'
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY = [Yy] ]]
then then
echo " Note: Some USB WiFi adapters will not allow the txpw to be set." printf ' Note: Some USB WiFi adapters will not allow the txpw to be set.\n'
read -p " What txpw setting do you want to attempt to set? ( e.g. 2300 = 23 dBm ) " iface_txpw read -p ' What txpw setting do you want to attempt to set? ( e.g. 2300 = 23 dBm ) ' iface_txpw || exit
iw dev $iface0mon set txpower fixed $iface_txpw iw dev "$iface0mon" set txpower fixed "$iface_txpw"
fi fi
# Display interface settings # Display interface settings
clear get_if_info "$iface0mon"
echo print_if_info "$iface0" 6
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
iface_chan=$(iw dev $iface0mon info | grep 'channel' | sed 's/channel //' | sed -e 's/^[ \t]*//')
echo ' chan - ' $chan
iface_txpw=$(iw dev $iface0mon info | grep 'txpower' | sed 's/txpower //' | sed -e 's/^[ \t]*//')
echo ' txpw - ' $iface_txpw
echo ' --------------------------------'
echo
# Interface ready # Interface ready
echo " The Interface is now ready for Monitor Mode use." printf ' The Interface is now ready for Monitor Mode use.\n\n'
echo printf ' You can place this terminal in the background\n'
echo " You can place this terminal in the background" printf ' while you run any applications you wish to run.\n\n'
echo " while you run any applications you wish to run." read -p ' Press any key to continue... ' -n 1 -r || exit
echo printf '\n'
read -p " Press any key to continue... " -n 1 -r
echo
# Return the adapter to original settings or not # Return the adapter to original settings or not
read -p " Do you want to return the adapter to original settings? [Y/n] " -n 1 -r read -p ' Do you want to return the adapter to original settings? [Y/n] ' -n 1 -r || exit
if [[ $REPLY =~ ^[Nn]$ ]] if [[ $REPLY = [Nn] ]]
then then
# Display interface settings # Display interface settings
clear get_if_info "$iface0mon"
echo print_if_info "$iface0" 4
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
echo ' --------------------------------'
echo
exit 0
else else
ip link set dev $iface0mon down ip link set dev "$iface0mon" down
ip link set dev $iface0mon address $iface_addr_orig ip link set dev "$iface0mon" address "$iface_addr_orig"
iw $iface0mon set type managed iw "$iface0mon" set type managed
ip link set dev $iface0mon name $iface0 ip link set dev "$iface0mon" name "$iface0"
ip link set dev $iface0 up ip link set dev "$iface0" up
# Enable interfering processes
for pid in $(ps -A -o pid= -o comm= | grep ${PROCESSES} | awk '{print $1}'); do
command kill -18 "${pid}" # -18 = CONT
done
# Display interface settings # Display interface settings
clear get_if_info "$iface0"
echo print_if_info "$iface0" 4
echo ' --------------------------------' fi
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------' if (( ${#pids[@]} > 0 ))
echo ' WiFi Interface:' then
echo ' '$iface0 read -p ' Do you want to resume the stopped processes? [Y/n] ' -n 1 -r || exit
echo ' --------------------------------' if [[ $REPLY = [Yy] ]]
iface_name=$(iw dev $iface0 info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//') then
echo ' name - ' $iface_name # Enable interfering processes
iface_type=$(iw dev $iface0 info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//') kill -CONT "${pids[@]}"
echo ' type - ' $iface_type fi
iface_state=$(ip addr show $iface0 | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/') fi
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0 info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
echo ' --------------------------------'
echo
exit 0 exit 0
fi
else
clear
echo
echo " ERROR: Please provide an existing interface as parameter!"
echo -e " Usage: $ sudo ./$SCRIPT_NAME [interface:wlan0]"
echo " Tip: $ iw dev"
echo
exit 1
fi