Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scripts/copy-to-tmp-folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions scripts/release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
62 changes: 62 additions & 0 deletions uhk-usb-service/manual-install.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions uhk-usb-service/usr/lib/systemd/system/uhk-usb-rebind.service
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions uhk-usb-service/usr/local/bin/uhk-usb-rebind.sh
Original file line number Diff line number Diff line change
@@ -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
Loading