2020-03-24 13:16:25 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2025-05-09 09:48:03 +02:00
|
|
|
TARGET_KERNEL=
|
2025-05-09 11:29:30 +02:00
|
|
|
VERBOSE=false
|
2025-05-09 09:48:03 +02:00
|
|
|
|
2025-05-07 19:47:24 +02:00
|
|
|
function main() {
|
|
|
|
local VERSION
|
|
|
|
VERSION="$(get_version)"
|
2025-05-09 09:48:03 +02:00
|
|
|
parse-cli-args "$@"
|
2025-05-07 19:47:24 +02:00
|
|
|
ensure_root_permissions
|
|
|
|
put_sources_in_place "$VERSION"
|
|
|
|
deploy_driver "$VERSION"
|
|
|
|
}
|
|
|
|
|
2025-05-09 09:10:26 +02:00
|
|
|
function get_version() {
|
|
|
|
sed -En 's/PACKAGE_VERSION="(.*)"/\1/p' dkms.conf
|
|
|
|
}
|
|
|
|
|
2025-05-09 09:48:03 +02:00
|
|
|
function parse-cli-args() {
|
2025-05-09 11:29:30 +02:00
|
|
|
while [[ $# -gt 0 ]]; do
|
2025-05-09 09:48:03 +02:00
|
|
|
case "$1" in
|
2025-05-09 11:29:30 +02:00
|
|
|
-v | --verbose)
|
|
|
|
VERBOSE=true
|
|
|
|
shift
|
|
|
|
;;
|
2025-05-09 09:48:03 +02:00
|
|
|
-h | --help)
|
2025-05-09 11:29:30 +02:00
|
|
|
print-usage
|
|
|
|
exit 0
|
2025-05-09 09:48:03 +02:00
|
|
|
;;
|
|
|
|
*)
|
2025-05-09 11:29:30 +02:00
|
|
|
if [[ -n "${TARGET_KERNEL}" ]]; then
|
|
|
|
echo "Only one target kernel can be specified!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2025-05-09 09:48:03 +02:00
|
|
|
TARGET_KERNEL="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function print-usage() {
|
|
|
|
cat <<EOF
|
2025-05-09 11:29:30 +02:00
|
|
|
Usage: $0 [-v|--verbose|TARGET_KERNEL]..
|
2025-05-09 09:48:03 +02:00
|
|
|
|
|
|
|
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
|
2025-05-09 11:29:30 +02:00
|
|
|
-v, --verbose Enable verbose output
|
2025-05-09 09:48:03 +02:00
|
|
|
TARGET_KERNEL Specify the target kernel version to deploy the driver to.
|
|
|
|
If not specified, the script will deploy to all available
|
|
|
|
kernels.
|
2025-05-09 11:31:24 +02:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$0
|
|
|
|
$0 -v \$(uname -r)
|
|
|
|
$0 6.12.17-amd64
|
2025-05-09 09:48:03 +02:00
|
|
|
|
|
|
|
This script will ask for root permissions to deploy the driver.
|
|
|
|
EOF
|
2020-03-24 13:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function ensure_root_permissions() {
|
2025-05-07 19:47:24 +02:00
|
|
|
if ! sudo -v; then
|
2020-03-24 13:16:25 +01:00
|
|
|
echo "Root permissions required to deploy the driver!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2025-05-07 19:47:24 +02:00
|
|
|
function put_sources_in_place() {
|
|
|
|
local VERSION="$1"
|
2025-05-09 11:29:30 +02:00
|
|
|
sudo rsync --delete --exclude=.git -rvhP ./ "/usr/src/rtl88x2bu-${VERSION}" >/dev/null
|
|
|
|
log "Sources copied to /usr/src/rtl88x2bu-${VERSION}"
|
2025-05-07 19:47:24 +02:00
|
|
|
}
|
|
|
|
|
2020-03-24 13:16:25 +01:00
|
|
|
function deploy_driver() {
|
2025-05-07 19:47:24 +02:00
|
|
|
local VERSION="$1"
|
2025-05-09 09:48:03 +02:00
|
|
|
sudo dkms "add" -m rtl88x2bu -v "${VERSION}" || true
|
2025-05-09 09:11:54 +02:00
|
|
|
list-kernels |
|
2025-05-07 19:47:24 +02:00
|
|
|
while read -r kernel; do
|
|
|
|
for action in build install; do
|
|
|
|
sudo dkms "${action}" -m rtl88x2bu -v "${VERSION}" -k "${kernel}"
|
|
|
|
done
|
|
|
|
done
|
2020-03-24 13:16:25 +01:00
|
|
|
sudo modprobe 88x2bu
|
|
|
|
}
|
|
|
|
|
2025-05-09 09:11:54 +02:00
|
|
|
function list-kernels() {
|
2025-05-09 09:48:03 +02:00
|
|
|
if [[ -n "${TARGET_KERNEL}" ]]; then
|
2025-05-09 11:31:56 +02:00
|
|
|
echo "${TARGET_KERNEL}"
|
|
|
|
else
|
2025-05-09 09:48:03 +02:00
|
|
|
find /boot -maxdepth 1 -iname "initrd.img*" |
|
2025-06-01 10:24:01 +02:00
|
|
|
cut -d- -f2-
|
2025-05-09 09:48:03 +02:00
|
|
|
echo "${TARGET_KERNEL}"
|
|
|
|
fi
|
2025-05-09 09:11:54 +02:00
|
|
|
}
|
|
|
|
|
2025-05-09 11:29:30 +02:00
|
|
|
function log() {
|
|
|
|
if [[ "$VERBOSE" = "true" ]]; then
|
|
|
|
echo "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2025-05-07 19:47:24 +02:00
|
|
|
main "$@"
|