diff --git a/README.md b/README.md index 0a25cc0..8e9ef95 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,17 @@ important work by saving and such beforehand. ### DKMS installation 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 -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. +register it in DKMS. This can be done using the script `deploy.sh`, for either + + * 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 diff --git a/deploy.sh b/deploy.sh index 5a39e4c..3229d2d 100755 --- a/deploy.sh +++ b/deploy.sh @@ -2,36 +2,108 @@ set -euo pipefail -function ensure_no_cli_args() { - if [ $# -ne 0 ] - then - echo "No command line arguments accepted!" >&2 - exit 1 - fi -} +TARGET_KERNEL= +VERBOSE=false -function ensure_root_permissions() { - if ! sudo -v - then - echo "Root permissions required to deploy the driver!" >&2 - exit 1 - fi +function main() { + local VERSION + VERSION="$(get_version)" + 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 } -function deploy_driver() { - VER=$(get_version) - sudo rsync --delete --exclude=.git -rvhP ./ "/usr/src/rtl88x2bu-${VER}" - for action in add build install - do - sudo dkms "${action}" -m rtl88x2bu -v "${VER}" +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 <&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() { + local VERSION="$1" + 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 } -ensure_no_cli_args "$@" -ensure_root_permissions -deploy_driver +function list-kernels() { + 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 "$@"