diff --git a/scripts/copy-to-tmp-folder.js b/scripts/copy-to-tmp-folder.js index d79c3ed49d3..3ec264bf4a8 100644 --- a/scripts/copy-to-tmp-folder.js +++ b/scripts/copy-to-tmp-folder.js @@ -20,6 +20,12 @@ promises.push( path.join(__dirname, '../tmp/smart-macro-docs'), copyOptions) ); +promises.push( + fse.copy( + path.join(__dirname, '../uhk-usb-service'), + path.join(__dirname, '../tmp/uhk-usb-service'), + copyOptions) +); Promise .all(promises) diff --git a/scripts/release.mjs b/scripts/release.mjs index 7fccc45b394..537c3913d04 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -54,6 +54,9 @@ if (process.platform === 'darwin') { artifactName += '-${arch}.${ext}'; extraResources.push('rules/setup-rules.sh'); extraResources.push('rules/50-uhk60.rules'); + extraResources.push('uhk-usb-service/manual-install.sh'); + extraResources.push('uhk-usb-service/usr/lib/systemd/system/uhk-usb-rebind.service'); + extraResources.push('uhk-usb-service/usr/local/bin/uhk-usb-rebind.sh'); } else { console.error(`I dunno how to publish a release for ${process.platform} :(`); process.exit(1); diff --git a/uhk-usb-service/manual-install.sh b/uhk-usb-service/manual-install.sh new file mode 100755 index 00000000000..6d8f731839b --- /dev/null +++ b/uhk-usb-service/manual-install.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# Manual installer for systems without package manager support +# Usage: sudo ./manual-install.sh install|uninstall + +set -euo pipefail + +SCRIPT_SRC="usr/local/bin/uhk-usb-rebind.sh" +UNIT_SRC="usr/lib/systemd/system/uhk-usb-rebind.service" + +SCRIPT_DST="/usr/local/bin/uhk-usb-rebind.sh" +UNIT_DST="/usr/local/lib/systemd/system/uhk-usb-rebind.service" + +usage() { + echo "Usage: $0 install|uninstall" + exit 2 +} + +if [[ $(id -u) -ne 0 ]]; then + echo "This script must be run as root (sudo)" + exit 1 +fi + +if [[ $# -ne 1 ]]; then + usage +fi + +action="$1" + +case "$action" in + install) + echo "Installing UHK USB rebind script and systemd unit to /usr/local..." + mkdir -p "$(dirname "$SCRIPT_DST")" "$(dirname "$UNIT_DST")" + cp -a "$SCRIPT_SRC" "$SCRIPT_DST" + chmod 755 "$SCRIPT_DST" + cp -a "$UNIT_SRC" "$UNIT_DST" + chmod 644 "$UNIT_DST" + if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload || true + systemctl enable --now uhk-usb-rebind.service || true + echo "Service enabled and started (if systemd present)." + else + echo "systemctl not found; unit installed at $UNIT_DST. Enable it manually if desired." + fi + echo "Install complete." + ;; + uninstall) + echo "Uninstalling UHK USB rebind script and systemd unit from /usr/local..." + if command -v systemctl >/dev/null 2>&1; then + systemctl stop uhk-usb-rebind.service || true + systemctl disable uhk-usb-rebind.service || true + systemctl daemon-reload || true + fi + rm -f "$SCRIPT_DST" || true + rm -f "$UNIT_DST" || true + echo "Uninstall complete." + ;; + *) + usage + ;; +esac + +exit 0 diff --git a/uhk-usb-service/usr/lib/systemd/system/uhk-usb-rebind.service b/uhk-usb-service/usr/lib/systemd/system/uhk-usb-rebind.service new file mode 100644 index 00000000000..8b8cb1de51c --- /dev/null +++ b/uhk-usb-service/usr/lib/systemd/system/uhk-usb-rebind.service @@ -0,0 +1,10 @@ +[Unit] +Description=UHK USB reset after resume +After=suspend.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/uhk-usb-rebind.sh + +[Install] +WantedBy=suspend.target diff --git a/uhk-usb-service/usr/local/bin/uhk-usb-rebind.sh b/uhk-usb-service/usr/local/bin/uhk-usb-rebind.sh new file mode 100755 index 00000000000..951b22cd9fb --- /dev/null +++ b/uhk-usb-service/usr/local/bin/uhk-usb-rebind.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +declare -a uhk_devices=( + "37a8:0001" + "37a8:0003" + "37a8:0005" + "37a8:0007" + "37a8:0009" +) + +USB_DRIVER_PATH="/sys/bus/usb/drivers/usb" + +for dev in /sys/bus/usb/devices/*; do + if [[ -f "$dev/idVendor" && -f "$dev/idProduct" ]]; then + VID=$(cat "$dev/idVendor") + PID=$(cat "$dev/idProduct") + MATCH="${VID}:${PID}" + + for target in "${uhk_devices[@]}"; do + if [[ "$MATCH" == "$target" ]]; then + DEVNAME=$(basename "$dev") + + if [[ -e "$USB_DRIVER_PATH/unbind" ]]; then + echo "$DEVNAME" | sudo tee "$USB_DRIVER_PATH/unbind" + sleep 1.5 + echo "$DEVNAME" | sudo tee "$USB_DRIVER_PATH/bind" + echo "Rebound device: $dev" + fi + fi + done + fi +done