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'
exit 0
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
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=$? exit 0
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
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"
BLACKLIST_FILE="rtw88_8822bu.conf"
# support for NoPrompt allows non-interactive use of this script options_file=88x2bu.conf
NO_PROMPT=0 blacklist_file=rtw88_8822bu.conf
# get the options
while [ $# -gt 0 ]
do
case $1 in
NoPrompt)
NO_PROMPT=1 ;;
*h|*help|*)
echo "Syntax $0 <NoPrompt>"
echo " NoPrompt - noninteractive mode"
echo " -h|--help - Show help"
exit 1
;;
esac
shift
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
# support for NoPrompt allows non-interactive use of this script
no_prompt=0
# get the options
for ((;$#;)) do
case $1 in
NoPrompt)
no_prompt=1 ;;
-h|--help|*)
cat <<- EndOfHelp
Usage: $0 [NoPrompt]
$0 --help
NoPrompt - noninteractive mode
-h|--help - Show help
EndOfHelp
[[ $1 = -h || $1 = --help ]] # don't use non-zero exit status when help requested
exit
;;
esac
shift
done
# 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,65 +50,56 @@ 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
fi fi
exit 0 exit 0

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|*) cat <<- EndOfHelp
echo "Syntax $0 <NoPrompt>" Usage: $0 [NoPrompt]
echo " NoPrompt - noninteractive mode" $0 --help
echo " -h|--help - Show help" NoPrompt - noninteractive mode
exit 1 -h|--help - Show help
;; EndOfHelp
esac [[ $1 = -h || $1 = --help ]] # don't use non-zero exit status when help requested
shift exit
;;
esac
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,80 +66,68 @@ 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
fi fi
exit 0 exit 0

View File

@ -4,67 +4,66 @@
# #
# 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
# support for NoPrompt allows non-interactive use of this script
NO_PROMPT=0
# get the options
while [ $# -gt 0 ]
do
case $1 in
NoPrompt)
NO_PROMPT=1 ;;
*h|*help|*)
echo "Syntax $0 <NoPrompt>"
echo " NoPrompt - noninteractive mode"
echo " -h|--help - Show help"
exit 1
;;
esac
shift
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
echo "Starting removal..." printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
make uninstall # support for NoPrompt allows non-interactive use of this script
RESULT=$? no_prompt=0
if [[ ("$RESULT" = "0")]] # get the options
for ((;$#;)) do
case $1 in
NoPrompt)
no_prompt=1 ;;
-h|--help|*)
cat <<- EndOfHelp
Usage: $0 [NoPrompt]
$0 --help
NoPrompt - noninteractive mode
-h|--help - Show help
EndOfHelp
[[ $1 = -h || $1 = --help ]] # don't use non-zero exit status when help requested
exit
;;
esac
shift
done
printf 'Starting removal...\n'
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 "Deleting ${OPTIONS_FILE} from /etc/modprobe.d" read -p 'Do you want to reboot now? (recommended) [y/N] ' -n 1 -r || exit
rm -f /etc/modprobe.d/${OPTIONS_FILE} printf '\n'
echo "Deleting ${BLACKLIST_FILE} from /etc/modprobe.d" if [[ $REPLY = [Yy] ]]
rm -f /etc/modprobe.d/${BLACKLIST_FILE} then
echo "The driver was removed successfully." reboot
echo "You may now delete the driver directory if desired." fi
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
reboot
fi
fi fi
exit 0 exit 0

View File

@ -4,79 +4,81 @@
# #
# 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_DIR="$(pwd)" drv_version=5.13.1
KRNL_VERSION="$(uname -r)"
clear
echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}"
# support for NoPrompt allows non-interactive use of this script
NO_PROMPT=0
# get the options
while [ $# -gt 0 ]
do
case $1 in
NoPrompt)
NO_PROMPT=1 ;;
*h|*help|*)
echo "Syntax $0 <NoPrompt>"
echo " NoPrompt - noninteractive mode"
echo " -h|--help - Show help"
exit 1
;;
esac
shift
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
echo "Starting removal..." clear
printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all # support for NoPrompt allows non-interactive use of this script
RESULT=$? no_prompt=0
# RESULT will be 3 if there are no instances of module to remove # get the options
# however we still need to remove the files or the install script for ((;$#;)) do
# will complain. case $1 in
if [[ ("$RESULT" = "0")||("$RESULT" = "3") ]] NoPrompt)
no_prompt=1 ;;
-h|--help|*)
cat <<- EndOfHelp
Usage: $0 [NoPrompt]
$0 --help
NoPrompt - noninteractive mode
-h|--help - Show help
EndOfHelp
[[ $1 = -h || $1 = --help ]] # don't use non-zero exit status when help requested
exit
;;
esac
shift
done
ok_if_status_is() {
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 "Deleting ${OPTIONS_FILE} from /etc/modprobe.d" read -p 'Do you want to reboot now? (recommended) [y/N] ' -n 1 -r || exit
rm -f /etc/modprobe.d/${OPTIONS_FILE} printf '\n'
echo "Deleting ${BLACKLIST_FILE} from /etc/modprobe.d" if [[ $REPLY = [Yy] ]]
rm -f /etc/modprobe.d/${BLACKLIST_FILE} then
echo "Deleting source files from /usr/src/${DRV_NAME}-${DRV_VERSION}" reboot
rm -rf /usr/src/${DRV_NAME}-${DRV_VERSION} fi
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
reboot
fi
fi fi
exit 0 exit 0

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'
exit 1 printf 'Try: "sudo %s"\n' "${*:0}"
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,304 +1,261 @@
#!/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]" exit 1
echo
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
# Set iface0 down # shellcheck ignore=SC1007
ip link set dev $iface0 down iface_name= iface_type= iface_addr= iface_chan= iface_txpw= iface_state=
# Check if iface0 exists and continue if true
if [ $? -eq 0 ] 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
clear
printf '\n --------------------------------\n'
printf ' %-20s %s\n' "${0##*/}" "$SCRIPT_VERSION"
printf ' --------------------------------\n'
printf ' WiFi Interface:\n'
printf ' %s\n' "$iface"
printf ' --------------------------------\n'
for m in name type state addr chan txpw
do
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 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
echo
echo ' The following processes have been stopped:'
echo
echo "${badProcs}"
echo
echo ' Note: The above processes can be returned'
echo ' to a normal state at the end of this script.'
echo
read -p " Press any key to continue... " -n 1 -r
# Display interface settings kill -STOP "${pids[@]}"
clear
echo
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
clear
printf '\n The following processes have been stopped:\n\n'
# Set addr (has to be done before renaming the interface) # ps -p takes a comma-separated list
iface_addr_orig=$iface_addr str_join pidlist ',' "${pids[@]}"
read -p " Do you want to set a new addr? [y/N] " -n 1 -r # pidlist is defined by str_join
echo # shellcheck disable=SC2154
if [[ $REPLY =~ ^[Yy]$ ]] ps -o pid=PID,state=State,comm=Name -p "$pidlist"
then
read -p " What addr do you want? ( e.g. 12:34:56:78:90:ab ) " iface_addr
# need code to ID bad addresses
ip link set dev $iface0 address $iface_addr
fi
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'
# Set monitor mode
# iw dev <devname> set monitor <flag>
# Valid monitor flags are:
# none: no special flags
# fcsfail: show frames with FCS errors
# control: show control frames
# otherbss: show frames from other BSSes
# cook: use cooked mode
# active: use active mode (ACK incoming unicast packets)
# mumimo-groupid <GROUP_ID>: use MUMIMO according to a group id
# mumimo-follow-mac <MAC_ADDRESS>: use MUMIMO according to a MAC address
iw dev $iface0 set monitor none
# Rename interface
ip link set dev $iface0 name $iface0mon
# Bring the interface up
ip link set dev $iface0mon up
# 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
echo ' --------------------------------'
echo
# Set channel
read -p " Do you want to set the channel? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p " What channel do you want to set? " chan
# Documentation:
# 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 <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]
# Select one or modify as required:
iw dev $iface0mon set channel $chan
# iw dev $iface0mon set channel $chan HT40-
# iw dev $iface0mon set channel $chan 80MHz
# To test if channel was set correctly:
# aireplay-ng --test <wlan0>
fi
# 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
# Set txpw
read -p " Do you want to set the txpower? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo " Note: Some USB WiFi adapters will not allow the txpw to be set."
read -p " What txpw setting do you want to attempt to set? ( e.g. 2300 = 23 dBm ) " iface_txpw
iw dev $iface0mon set txpower fixed $iface_txpw
fi
# 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
# Interface ready
echo " The Interface is now ready for Monitor Mode use."
echo
echo " You can place this terminal in the background"
echo " while you run any applications you wish to run."
echo
read -p " Press any key to continue... " -n 1 -r
echo
# 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
if [[ $REPLY =~ ^[Nn]$ ]]
then
# 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
echo ' --------------------------------'
echo
exit 0
else
ip link set dev $iface0mon down
ip link set dev $iface0mon address $iface_addr_orig
iw $iface0mon set type managed
ip link set dev $iface0mon name $iface0
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
clear
echo
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
exit 0
fi
else else
clear clear
echo printf '\n There are no processes that need stopping.\n\n'
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 fi
read -p ' Press any key to continue... ' -n 1 -r || exit
# Display interface settings
get_if_info "$iface0"
print_if_info "$iface0" 4
# Set addr (has to be done before renaming the interface)
iface_addr_orig=$iface_addr
read -p ' Do you want to set a new addr? [y/N] ' -n 1 -r || exit
printf '\n'
if [[ $REPLY = [Yy] ]]
then
read -p ' What addr do you want? ( e.g. 12:34:56:78:90:ab ) ' iface_addr || exit
# need code to ID bad addresses
ip link set dev "$iface0" address "$iface_addr"
fi
# Set monitor mode
#iw dev <devname> set monitor <flag>
# Valid monitor flags are:
# none: no special flags
# fcsfail: show frames with FCS errors
# control: show control frames
# otherbss: show frames from other BSSes
# cook: use cooked mode
# active: use active mode (ACK incoming unicast packets)
# mumimo-groupid <GROUP_ID>: use MUMIMO according to a group id
# mumimo-follow-mac <MAC_ADDRESS>: use MUMIMO according to a MAC address
iw dev "$iface0" set monitor none
# Rename interface
ip link set dev "$iface0" name "$iface0mon"
# Bring the interface up
ip link set dev "$iface0mon" up
# Display interface settings
get_if_info "$iface0mon"
print_if_info "$iface0" 4
# Set channel
read -p ' Do you want to set the channel? [y/N] ' -n 1 -r || exit
printf '\n'
if [[ $REPLY = [Yy] ]]
then
read -p ' What channel do you want to set? ' chan || exit
# Documentation:
# 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 "$control_freq" [5|10|20|40|80|80+80|160] ["$center1_freq" ["$center2_freq"]]
# Select one or modify as required:
iw dev "$iface0mon" set channel "$chan"
# iw dev "$iface0mon" set channel "$chan" HT40-
# iw dev "$iface0mon" set channel "$chan" 80MHz
# To test if channel was set correctly:
# aireplay-ng --test <wlan0>
fi
# Display interface settings
get_if_info "$iface0mon"
print_if_info "$iface0" 6
# Set txpw
read -p ' Do you want to set the txpower? [y/N] ' -n 1 -r || exit
printf '\n'
if [[ $REPLY = [Yy] ]]
then
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 || exit
iw dev "$iface0mon" set txpower fixed "$iface_txpw"
fi
# Display interface settings
get_if_info "$iface0mon"
print_if_info "$iface0" 6
# Interface ready
printf ' The Interface is now ready for Monitor Mode use.\n\n'
printf ' You can place this terminal in the background\n'
printf ' while you run any applications you wish to run.\n\n'
read -p ' Press any key to continue... ' -n 1 -r || exit
printf '\n'
# 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 || exit
if [[ $REPLY = [Nn] ]]
then
# Display interface settings
get_if_info "$iface0mon"
print_if_info "$iface0" 4
else
ip link set dev "$iface0mon" down
ip link set dev "$iface0mon" address "$iface_addr_orig"
iw "$iface0mon" set type managed
ip link set dev "$iface0mon" name "$iface0"
ip link set dev "$iface0" up
# Display interface settings
get_if_info "$iface0"
print_if_info "$iface0" 4
fi
if (( ${#pids[@]} > 0 ))
then
read -p ' Do you want to resume the stopped processes? [Y/n] ' -n 1 -r || exit
if [[ $REPLY = [Yy] ]]
then
# Enable interfering processes
kill -CONT "${pids[@]}"
fi
fi
exit 0