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

Compare commits

...

6 Commits

Author SHA1 Message Date
Max Görner
335a0e2e2b fix: Switch branches, as -n means variable has value 2025-05-09 11:31:56 +02:00
Max Görner
573cd1cb7d chore: Drop leftover comment 2025-05-09 11:31:42 +02:00
Max Görner
1252baad3f docs: Add examples section to --help 2025-05-09 11:31:24 +02:00
Max Görner
6d79a75177 feat: Do not remove driver for all kernels 2025-05-09 11:30:11 +02:00
Max Görner
cbd155ead2 feat: Add verbosity flag to CLI 2025-05-09 11:29:30 +02:00
Max Görner
8f1741badf feat: Add simple command line parsing 2025-05-09 09:48:03 +02:00

View File

@ -2,12 +2,14 @@
set -euo pipefail
TARGET_KERNEL=
VERBOSE=false
function main() {
local VERSION
VERSION="$(get_version)"
ensure_no_cli_args "$@"
parse-cli-args "$@"
ensure_root_permissions
remove_driver
put_sources_in_place "$VERSION"
deploy_driver "$VERSION"
}
@ -16,11 +18,51 @@ function get_version() {
sed -En 's/PACKAGE_VERSION="(.*)"/\1/p' dkms.conf
}
function ensure_no_cli_args() {
if [ $# -ne 0 ]; then
echo "No command line arguments accepted!" >&2
exit 1
fi
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() {
@ -30,21 +72,17 @@ function ensure_root_permissions() {
fi
}
function remove_driver() {
sudo dkms remove rtl88x2bu/5.8.7.1 --all &>/dev/null || true
}
function put_sources_in_place() {
local VERSION="$1"
sudo rsync --delete --exclude=.git -rvhP ./ "/usr/src/rtl88x2bu-${VERSION}"
sudo rsync --delete --exclude=.git -rvhP ./ "/usr/src/rtl88x2bu-${VERSION}" >/dev/null
log "Sources copied to /usr/src/rtl88x2bu-${VERSION}"
}
function deploy_driver() {
local VERSION="$1"
sudo dkms "add" -m rtl88x2bu -v "${VERSION}"
sudo dkms "add" -m rtl88x2bu -v "${VERSION}" || true
list-kernels |
while read -r kernel; do
# xargs -n1 sudo dkms install -m rtl88x2bu -v 5.8.7.1 -k
for action in build install; do
sudo dkms "${action}" -m rtl88x2bu -v "${VERSION}" -k "${kernel}"
done
@ -53,8 +91,19 @@ function deploy_driver() {
}
function list-kernels() {
find /boot -maxdepth 1 -iname "initrd.img*" |
cut -d- -f2
if [[ -n "${TARGET_KERNEL}" ]]; then
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 "$@"