2
0
mirror of https://github.com/cilynx/rtl88x2bu synced 2025-08-22 18:19:43 +00:00
rtl88x2bu/deploy.sh

110 lines
2.5 KiB
Bash
Raw Permalink Normal View History

#!/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
function main() {
local VERSION
VERSION="$(get_version)"
2025-05-09 09:48:03 +02:00
parse-cli-args "$@"
ensure_root_permissions
put_sources_in_place "$VERSION"
deploy_driver "$VERSION"
}
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
}
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"
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}"
}
function deploy_driver() {
local VERSION="$1"
2025-05-09 09:48:03 +02:00
sudo dkms "add" -m rtl88x2bu -v "${VERSION}" || true
list-kernels |
while read -r kernel; do
for action in build install; do
sudo dkms "${action}" -m rtl88x2bu -v "${VERSION}" -k "${kernel}"
done
done
sudo modprobe 88x2bu
}
function list-kernels() {
2025-05-09 09:48:03 +02:00
if [[ -n "${TARGET_KERNEL}" ]]; then
echo "${TARGET_KERNEL}"
else
2025-05-09 09:48:03 +02:00
find /boot -maxdepth 1 -iname "initrd.img*" |
cut -d- -f2-
2025-05-09 09:48:03 +02:00
echo "${TARGET_KERNEL}"
fi
}
2025-05-09 11:29:30 +02:00
function log() {
if [[ "$VERBOSE" = "true" ]]; then
echo "$1"
fi
}
main "$@"