2
0
mirror of https://github.com/cilynx/rtl88x2bu synced 2025-08-22 10:10:08 +00:00

feat: Extend deploy.sh script

The deploy.sh script now allows to install the driver for either

    * all available kernels,
    * a specific kernel, or
    * the currently active kernel

In order to do so it got a small CLI that even prints a help text on
`--help`.
This commit is contained in:
Max Görner 2025-05-12 22:08:26 +02:00
commit 2e7d1f52d9
2 changed files with 105 additions and 25 deletions

View File

@ -42,9 +42,17 @@ important work by saving and such beforehand.
### DKMS installation ### DKMS installation
If you want to have the driver available at startup, it will be convenient to If you want to have the driver available at startup, it will be convenient to
register it in DKMS. An executable explanation of how to do so can be found in register it in DKMS. This can be done using the script `deploy.sh`, for either
the script `deploy.sh`. Since registering a kernel module in DKMS is a major
intervention, only execute it if you understand what the script does. * all kernels,
* a specific kernel, or
* the currently active kernel.
Please consult `--help` for more information and consider reading the script
before executing it.
Since registering a kernel module in DKMS is a major intervention, only execute
it if you understand what the script does.
### Unknown Symbol Errors ### Unknown Symbol Errors

114
deploy.sh
View File

@ -2,36 +2,108 @@
set -euo pipefail set -euo pipefail
function ensure_no_cli_args() { TARGET_KERNEL=
if [ $# -ne 0 ] VERBOSE=false
then
echo "No command line arguments accepted!" >&2
exit 1
fi
}
function ensure_root_permissions() { function main() {
if ! sudo -v local VERSION
then VERSION="$(get_version)"
echo "Root permissions required to deploy the driver!" >&2 parse-cli-args "$@"
exit 1 ensure_root_permissions
fi put_sources_in_place "$VERSION"
deploy_driver "$VERSION"
} }
function get_version() { function get_version() {
sed -En 's/PACKAGE_VERSION="(.*)"/\1/p' dkms.conf sed -En 's/PACKAGE_VERSION="(.*)"/\1/p' dkms.conf
} }
function parse-cli-args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-v | --verbose)
VERBOSE=true
shift
;;
-h | --help)
print-usage
exit 0
;;
*)
if [[ -n "${TARGET_KERNEL}" ]]; then
echo "Only one target kernel can be specified!" >&2
exit 1
fi
TARGET_KERNEL="$1"
shift
;;
esac
done
}
function print-usage() {
cat <<EOF
Usage: $0 [-v|--verbose|TARGET_KERNEL]..
Deploy the rtl88x2bu driver to the system. If TARGET_KERNEL is not specified,
the driver will be deployed to all available kernels.
Options:
-h, --help Show this help message and exit
-v, --verbose Enable verbose output
TARGET_KERNEL Specify the target kernel version to deploy the driver to.
If not specified, the script will deploy to all available
kernels.
Examples:
$0
$0 -v \$(uname -r)
$0 6.12.17-amd64
This script will ask for root permissions to deploy the driver.
EOF
}
function ensure_root_permissions() {
if ! sudo -v; then
echo "Root permissions required to deploy the driver!" >&2
exit 1
fi
}
function put_sources_in_place() {
local VERSION="$1"
sudo rsync --delete --exclude=.git -rvhP ./ "/usr/src/rtl88x2bu-${VERSION}" >/dev/null
log "Sources copied to /usr/src/rtl88x2bu-${VERSION}"
}
function deploy_driver() { function deploy_driver() {
VER=$(get_version) local VERSION="$1"
sudo rsync --delete --exclude=.git -rvhP ./ "/usr/src/rtl88x2bu-${VER}" sudo dkms "add" -m rtl88x2bu -v "${VERSION}" || true
for action in add build install list-kernels |
do while read -r kernel; do
sudo dkms "${action}" -m rtl88x2bu -v "${VER}" for action in build install; do
sudo dkms "${action}" -m rtl88x2bu -v "${VERSION}" -k "${kernel}"
done
done done
sudo modprobe 88x2bu sudo modprobe 88x2bu
} }
ensure_no_cli_args "$@" function list-kernels() {
ensure_root_permissions if [[ -n "${TARGET_KERNEL}" ]]; then
deploy_driver echo "${TARGET_KERNEL}"
else
find /boot -maxdepth 1 -iname "initrd.img*" |
cut -d- -f2
echo "${TARGET_KERNEL}"
fi
}
function log() {
if [[ "$VERBOSE" = "true" ]]; then
echo "$1"
fi
}
main "$@"