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:
#
# $ chmod +x ARM64_RPI.sh
# $ chmod +rx ARM64_RPI.sh
#
# To execute this file:
#
# $ ./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
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
printf 'Raspberry Pi OS (64 bit) support was turned on in Makefile as planned.\n'
exit 0

View File

@ -13,17 +13,12 @@
# 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
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
fi
sed -i 's/CONFIG_PLATFORM_ARM64_RPI = y/CONFIG_PLATFORM_ARM64_RPI = n/g' Makefile
printf 'Raspberry Pi OS (32 bit) support was turned on in Makefile as planned.\n'
exit 0

View File

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

View File

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

View File

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

View File

@ -4,42 +4,45 @@
#
# This version of the installation script does not use dkms.
SCRIPT_NAME="install-driver-no-dkms.sh"
SCRIPT_VERSION="20220821"
OPTIONS_FILE="88x2bu.conf"
BLACKLIST_FILE="rtw88_8822bu.conf"
SCRIPT_VERSION=20220923
# 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
options_file=88x2bu.conf
blacklist_file=rtw88_8822bu.conf
# check to ensure sudo was used
if [[ $EUID -ne 0 ]]
if (( EUID != 0 ))
then
echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1
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
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
# displays script name and version
echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}"
printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
# kernel
uname -r
@ -47,65 +50,56 @@ uname -r
# architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit
uname -m
echo "Starting installation..."
printf 'Starting installation...\n'
# 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
echo "Copying ${BLACKLIST_FILE} to: /etc/modprobe.d"
cp -f ${BLACKLIST_FILE} /etc/modprobe.d
printf 'Copying options and blacklist files into /etc/modprobe.d\n'
cp -fv "$options_file" "$blacklist_file" /etc/modprobe.d
make clean
make
RESULT=$?
make || {
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" ]]
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
make install || {
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 %s\n' "${*:0}"
exit "$status"
}
make install
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."
printf 'The driver was installed successfully.\n'
# unblock wifi
rfkill unblock wlan
# if NoPrompt is not used, ask user some questions to complete installation
if [ $NO_PROMPT -ne 1 ]
if (( ! no_prompt ))
then
read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
nano /etc/modprobe.d/${OPTIONS_FILE}
fi
read -p 'Do you want to edit the driver options file now? [y/N] ' -n 1 -r || exit 1
printf '\n'
if [[ $REPLY = [Yy] ]]
then
${EDITOR:-nano} "/etc/modprobe.d/$options_file"
fi
read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
reboot
fi
read -p 'Do you want to reboot now? (recommended) [y/N] ' -n 1 -r || exit 1
printf '\n'
if [[ $REPLY = [Yy] ]]
then
reboot
fi
fi
exit 0

View File

@ -4,59 +4,61 @@
#
# This version of the installation script uses dkms.
SCRIPT_NAME="install-driver.sh"
SCRIPT_VERSION="20220821"
OPTIONS_FILE="88x2bu.conf"
BLACKLIST_FILE="rtw88_8822bu.conf"
SCRIPT_VERSION=20220923
DRV_NAME="rtl88x2bu"
DRV_VERSION="5.13.1"
options_file=88x2bu.conf
blacklist_file=rtw88_8822bu.conf
DRV_DIR="$(pwd)"
KRNL_VERSION="$(uname -r)"
drv_name=rtl88x2bu
drv_version=5.13.1
drv_dir=$PWD
clear
# support for NoPrompt allows non-interactive use of this script
NO_PROMPT=0
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
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
# check to ensure sudo was used
if [[ $EUID -ne 0 ]]
if (( EUID != 0 ))
then
echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1
printf 'You must run this script with superuser (root) privileges.\n'
printf 'Try: "sudo %s"\n' "$0"
exit 1
fi
# check for previous installation
if [[ -d "/usr/src/${DRV_NAME}-${DRV_VERSION}" ]]
if [[ -d "/usr/src/$drv_name-$drv_version" ]]
then
echo "It appears that this driver may already be installed."
echo "You will need to run the following before reattempting installation."
echo "$ sudo ./remove-driver.sh"
exit 1
printf 'It appears that this driver may already be installed.\n'
printf 'You will need to run the following before reattempting installation.\n'
printf '$ sudo ./remove-driver.sh\n'
exit 1
fi
# information that helps with bug reports
# displays script name and version
echo "Running ${SCRIPT_NAME} version ${SCRIPT_VERSION}"
printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
# kernel
uname -r
@ -64,80 +66,68 @@ uname -r
# architecture - for ARM: aarch64 = 64 bit, armv7l = 32 bit
uname -m
echo "Starting installation..."
printf 'Starting installation...\n'
# the add command requires source in /usr/src/${DRV_NAME}-${DRV_VERSION}
echo "Copying source files to: /usr/src/${DRV_NAME}-${DRV_VERSION}"
cp -rf "${DRV_DIR}" /usr/src/${DRV_NAME}-${DRV_VERSION}
# the add command requires source in "/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"
# 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
echo "Copying ${BLACKLIST_FILE} to: /etc/modprobe.d"
cp -f ${BLACKLIST_FILE} /etc/modprobe.d
printf 'Copying options and blacklist files into: %s\n' "/etc/modprobe.d"
cp -fv "$options_file" "$blacklist_file" /etc/modprobe.d
dkms add -m ${DRV_NAME} -v ${DRV_VERSION}
RESULT=$?
dkms add -m "$drv_name" -v "$drv_version" || {
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" ]]
then
echo "An error occurred. dkms add 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 build -m "$drv_name" -v "$drv_version" || {
status=$?
printf 'An error occurred. dkms build 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"
}
dkms build -m ${DRV_NAME} -v ${DRV_VERSION}
RESULT=$?
dkms install -m "$drv_name" -v "$drv_version" || {
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" ]]
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."
printf 'The driver was installed successfully.\n'
# unblock wifi
rfkill unblock wlan
# if NoPrompt is not used, ask user some questions to complete installation
if [ $NO_PROMPT -ne 1 ]
if (( ! no_prompt ))
then
read -p "Do you want to edit the driver options file now? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
nano /etc/modprobe.d/${OPTIONS_FILE}
fi
read -p 'Do you want to edit the driver options file now? [y/N] ' -n 1 -r || exit 1
printf '\n'
if [[ $REPLY = [Yy] ]]
then
${EDITOR:-nano} "/etc/modprobe.d/$options_file"
fi
read -p "Do you want to reboot now? (recommended) [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
reboot
fi
read -p 'Do you want to reboot now? (recommended) [y/N] ' -n 1 -r || exit 1
printf '\n'
if [[ $REPLY = [Yy] ]]
then
reboot
fi
fi
exit 0

View File

@ -4,67 +4,66 @@
#
# This version of the removal script does not use dkms.
SCRIPT_NAME="remove-driver-no-dkms.sh"
SCRIPT_VERSION="20220821"
OPTIONS_FILE="88x2bu.conf"
BLACKLIST_FILE="rtw88_8822bu.conf"
SCRIPT_VERSION=20220923
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
options_file=88x2bu.conf
blacklist_file=rtw88_8822bu.conf
# check to ensure sudo was used
if [[ $EUID -ne 0 ]]
if (( EUID != 0 ))
then
echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\""
printf 'You must run this script with superuser (root) privileges.\n'
printf 'Try: "sudo %s"\n' "${*:0}"
exit 1
fi
echo "Starting removal..."
printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
make uninstall
RESULT=$?
# support for NoPrompt allows non-interactive use of this script
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
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
reboot
fi
read -p 'Do you want to reboot now? (recommended) [y/N] ' -n 1 -r || exit
printf '\n'
if [[ $REPLY = [Yy] ]]
then
reboot
fi
fi
exit 0

View File

@ -4,79 +4,81 @@
#
# This version of the removal script uses dkms.
SCRIPT_NAME="remove-driver.sh"
SCRIPT_VERSION="20220821"
OPTIONS_FILE="88x2bu.conf"
BLACKLIST_FILE="rtw88_8822bu.conf"
SCRIPT_VERSION=20220923
DRV_NAME="rtl88x2bu"
DRV_VERSION="5.13.1"
DRV_DIR="$(pwd)"
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
options_file=88x2bu.conf
blacklist_file=rtw88_8822bu.conf
drv_name=rtl88x2bu
drv_version=5.13.1
# check to ensure sudo was used
if [[ $EUID -ne 0 ]]
if (( EUID != 0 ))
then
echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1
printf 'You must run this script with superuser (root) privileges.\n'
printf 'Try: "sudo %s"\n' "${*:0}"
exit 1
fi
echo "Starting removal..."
clear
printf 'Running %s version %s\n' "${0##*/}" "$SCRIPT_VERSION"
dkms remove -m ${DRV_NAME} -v ${DRV_VERSION} --all
RESULT=$?
# support for NoPrompt allows non-interactive use of this script
no_prompt=0
# 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") ]]
# 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
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
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
reboot
fi
read -p 'Do you want to reboot now? (recommended) [y/N] ' -n 1 -r || exit
printf '\n'
if [[ $REPLY = [Yy] ]]
then
reboot
fi
fi
exit 0

View File

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

View File

@ -1,304 +1,261 @@
#!/bin/bash
SCRIPT_NAME="start-mon.sh"
SCRIPT_VERSION="20220408"
SCRIPT_VERSION=20220923
# Purpose: Start and configure monitor mode on the provided interface
# Usage: $ sudo ./start-mon.sh [interface:wlan0]
# There is no filename globbing in this script, so disable it to stop accidents
set -f
clear
# Check that sudo was used to start the script
if [[ $EUID -ne 0 ]]
if (( EUID != 0 ))
then
echo
echo " ERROR: You must run this script with superuser (root) privileges."
echo -e " Try: sudo ./${SCRIPT_NAME} [interface:wlan0]"
echo
exit 1
printf '\n ERROR: You must run this script with superuser (root) privileges.\n'
printf ' Try: "sudo %s"\n\n' "${*:0}"
exit 1
fi
# Add code to check if iw and ip are installed
# Ensure WiFi radio is not blocked
sudo rfkill unblock wlan
# Assign default monitor mode interface name
iface0mon='wlan0mon'
iface0mon=wlan0mon
# Assign default channel
chan=6
# Activate option to set automatic (1) or manual (2) interface mode
#
# 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)
iface0=${1:-wlan0}
get_if_info() {
local iface=$1 ii ij
# Set iface0 down
ip link set dev $iface0 down
# Check if iface0 exists and continue if true
if [ $? -eq 0 ]
# 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
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
# 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
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
kill -STOP "${pids[@]}"
clear
printf '\n The following processes have been stopped:\n\n'
# 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
echo
if [[ $REPLY =~ ^[Yy]$ ]]
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
# 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'
# 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
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
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
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