From 90ed47945f31ae5b8f412e9609f7e250ceecd0d9 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 22 May 2025 20:07:54 +1000 Subject: [PATCH] Add `udev` rule installation support. --- docs/driver_installation_zadig.md | 2 +- util/env-bootstrap.sh | 34 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/driver_installation_zadig.md b/docs/driver_installation_zadig.md index 78b631e6469..b1d729d9fe8 100644 --- a/docs/driver_installation_zadig.md +++ b/docs/driver_installation_zadig.md @@ -4,7 +4,7 @@ QMK presents itself to the host as a regular HID keyboard device, and as such re There are two notable exceptions: the Caterina bootloader, usually seen on Pro Micros, and the HalfKay bootloader shipped with PJRC Teensys, appear as a serial port and a generic HID device respectively, and so do not require a driver. -We recommend the use of the [Zadig](https://zadig.akeo.ie/) utility. If you have set up the development environment with MSYS2, the QMK CLI instalation script will have already installed the drivers for you. +We recommend the use of the [Zadig](https://zadig.akeo.ie/) utility. If you have set up the development environment with MSYS2, the QMK CLI installation script will have already installed the drivers for you. ## Installation diff --git a/util/env-bootstrap.sh b/util/env-bootstrap.sh index fde1a955f4a..dfacd693f50 100755 --- a/util/env-bootstrap.sh +++ b/util/env-bootstrap.sh @@ -16,6 +16,7 @@ # SKIP_QMK_CLI: Skip installing the QMK CLI. (or: --skip-qmk-cli) # SKIP_QMK_TOOLCHAINS: Skip installing the QMK toolchains. (or: --skip-qmk-toolchains) # SKIP_QMK_FLASHUTILS: Skip installing the QMK flashing utilities. (or: --skip-qmk-flashutils) +# SKIP_UDEV_RULES: Skip installing the udev rules for Linux. (or: --skip-udev-rules) # SKIP_WINDOWS_DRIVERS: Skip installing the Windows drivers for the flashing utilities. (or: --skip-windows-drivers) # # Arguments above may be negated by prefixing with `--no-` instead (e.g. `--no-skip-clean`). @@ -54,6 +55,7 @@ --skip-qmk-cli -- Skip installing the QMK CLI --skip-qmk-toolchains -- Skip installing the QMK toolchains --skip-qmk-flashutils -- Skip installing the QMK flashing utilities + --skip-udev-rules -- Skip installing the udev rules for Linux --skip-windows-drivers -- Skip installing the Windows drivers for the flashing utilities __EOT__ } @@ -387,6 +389,35 @@ __EOT__ tar xf "$target_file" -C "$QMK_DISTRIB_DIR/bin" } + install_linux_udev_rules() { + # Download the udev rules to the toolchains location + echo "Downloading QMK udev rules file..." >&2 + local qmk_rules_target_file="$QMK_DISTRIB_DIR/50-qmk.rules" + download_url "https://raw.githubusercontent.com/qmk/qmk_firmware/refs/heads/master/util/udev/50-qmk.rules" "$qmk_rules_target_file" + + # Install the udev rules -- path list is aligned with qmk doctor's linux.py + local udev_rules_paths=( + /usr/lib/udev/rules.d + /usr/local/lib/udev/rules.d + /run/udev/rules.d + /etc/udev/rules.d + ) + for udev_rules_dir in "${udev_rules_paths[@]}"; do + if [ -d "$udev_rules_dir" ]; then + echo "Installing udev rules to $udev_rules_dir/50-qmk.rules ..." >&2 + $(nsudo) mv "$qmk_rules_target_file" "$udev_rules_dir" + $(nsudo) chown 0:0 "$udev_rules_dir/50-qmk.rules" + $(nsudo) chmod 644 "$udev_rules_dir/50-qmk.rules" + break + fi + done + + # Reload udev rules + echo "Reloading udev rules..." >&2 + $(nsudo) udevadm control --reload-rules + $(nsudo) udevadm trigger + } + install_windows_drivers() { # Get the latest driver installer release from https://github.com/qmk/qmk_driver_installer local latest_driver_installer_release=$(download_url https://api.github.com/repos/qmk/qmk_driver_installer/releases/latest - | grep -oE '"tag_name": "[^"]+' | grep -oE '[^"]+$') @@ -463,6 +494,9 @@ __EOT__ [ -n "${SKIP_QMK_CLI:-}" ] || install_qmk_cli [ -n "${SKIP_QMK_TOOLCHAINS:-}" ] || install_toolchains [ -n "${SKIP_QMK_FLASHUTILS:-}" ] || install_flashing_tools + if [ "$(uname -s 2>/dev/null || true)" = "Linux" ]; then + [ -n "${SKIP_UDEV_RULES:-}" ] || install_linux_udev_rules + fi if [ "$(uname -o 2>/dev/null || true)" = "Msys" ]; then [ -n "${SKIP_WINDOWS_DRIVERS:-}" ] || install_windows_drivers fi