This commit is contained in:
2026-10-27 18:57:14 +01:00
parent f45596a7e3
commit 5410ed2ae5
9 changed files with 258 additions and 178 deletions

0
scripts/i18n.sh Normal file → Executable file
View File

80
scripts/make-deb.sh Normal file → Executable file
View File

@@ -3,7 +3,7 @@
# Usage: scripts/make-deb.sh [version] [arch]
set -e
VERSION="${1:-0.1.1}"
VERSION="${1:-0.1.2}"
ARCH="${2:-$(dpkg --print-architecture 2>/dev/null || echo amd64)}"
PACKAGE="gkeymapper"
STAGING="build/deb"
@@ -29,7 +29,7 @@ Section: utils
Installed-Size: $INSTALLED_SIZE
Priority: optional
Architecture: $ARCH
Depends: libc6, libgtk-4-1, libusb-1.0-0, libxkbcommon0, libglib2.0-0, systemd, udev
Depends: libc6, libgtk-4-1, libxkbcommon0, libglib2.0-0, systemd, udev
Maintainer: gKeyMapper <gkeymapper@rager.dev>
Description: Remap G1-G9 keys of the Logitech G910
A GTK4 GUI plus a background daemon for remapping the G1-G9 keys
@@ -48,6 +48,32 @@ case "$1" in
udevadm trigger --subsystem-match=input 2>/dev/null || true
fi
# Re-attach the kernel driver to interface 1 if it was detached by an
# older (libusb-based) daemon. Without this the new (hidraw-based)
# daemon cannot find /dev/hidraw for interface 1.
for _dev in /sys/bus/usb/devices/*; do
_vendor=$(cat "$_dev/idVendor" 2>/dev/null) || continue
_product=$(cat "$_dev/idProduct" 2>/dev/null) || continue
case "$_vendor" in
046d)
case "$_product" in
c32b|c335)
for _iface in "$_dev"/*:*; do
case "$_iface" in
*:1.*)
_name=$(basename "$_iface")
if [ -w /sys/bus/usb/drivers/usbhid/bind ]; then
echo "$_name" > /sys/bus/usb/drivers/usbhid/bind 2>/dev/null || true
fi
;;
esac
done
;;
esac
;;
esac
done
# Helper: run a command as a given user with the D-Bus session bus
# available. "systemctl --user" needs DBUS_SESSION_BUS_ADDRESS, which
# is not set in a plain "su -" login shell.
@@ -95,6 +121,56 @@ EOF
chmod 755 "$STAGING/DEBIAN/postinst"
# prerm: stop the daemon and re-attach the kernel driver before upgrading.
# The old (libusb-based) daemon detached the kernel driver from interface 1;
# if it was not stopped gracefully, the driver stays detached and the new
# (hidraw-based) daemon cannot find the device.
cat > "$STAGING/DEBIAN/prerm" <<'EOF'
#!/bin/sh
set -e
case "$1" in
remove|upgrade|deconfigure)
# Stop the daemon if running.
if [ -n "$SUDO_USER" ]; then
runuser -u "$SUDO_USER" -- systemctl --user stop gkeymapper-daemon >/dev/null 2>&1 || true
runuser -u "$SUDO_USER" -- systemctl --user daemon-reload >/dev/null 2>&1 || true
else
for _user in $(loginctl list-users --no-legend 2>/dev/null | awk '{print $2}'); do
runuser -u "$_user" -- systemctl --user stop gkeymapper-daemon >/dev/null 2>&1 || true
done
fi
# Re-attach the kernel driver to interface 1 if it was detached by
# an older (libusb-based) daemon. Without this, the new daemon
# (hidraw-based) cannot find /dev/hidraw for interface 1.
for _dev in /sys/bus/usb/devices/*; do
_vendor=$(cat "$_dev/idVendor" 2>/dev/null) || continue
_product=$(cat "$_dev/idProduct" 2>/dev/null) || continue
case "$_vendor" in
046d)
case "$_product" in
c32b|c335)
for _iface in "$_dev"/*:*; do
case "$_iface" in
*:1.*)
_name=$(basename "$_iface")
if [ -w /sys/bus/usb/drivers/usbhid/bind ]; then
echo "$_name" > /sys/bus/usb/drivers/usbhid/bind 2>/dev/null || true
fi
;;
esac
done
;;
esac
;;
esac
done
;;
esac
exit 0
EOF
chmod 755 "$STAGING/DEBIAN/prerm"
# postrm: disable the user daemon on removal.
cat > "$STAGING/DEBIAN/postrm" <<'EOF'
#!/bin/sh