Skip to content

SwagDevOps/ir-proxy

Repository files navigation

Proxy for ir-keytable

ir-proxy can be used on a pipeline to process ir-keytable output and propagate key events. ir-proxy uses adapters (xdotool) to send key events to the display server. ir-proxy conforms to the XDG Base Directory. As a result, configuration file file is located:

${XDG_CONFIG_HOME:-~/.config}/ir-proxy/config.yml

Synopsys

Commands:
  ir-proxy config          # Display config
  ir-proxy help [COMMAND]  # Describe available commands or one specific command
  ir-proxy pipe            # React to STDIN events
  ir-proxy sample          # Print samples on STDOUT

Sample commands

sudo socat - EXEC:'ir-keytable -tc -D 850 -P 250',pty,setsid,ctty | sudo -u $(whoami) ir-proxy pipe
sudo socat - EXEC:'ir-keytable -tc',pty | sudo -u $(whoami) ir-proxy pipe
sudo socat - EXEC:'ir-keytable -tc',pty | sudo -u $(whoami) ir-proxy pipe --config /etc/ir-proxy/config.yml

Testing

bundle install --standalone
sudo socat - EXEC:'ir-keytable -tc',pty | ruby bin/ir-proxy pipe --config config.sample.yml

Install production only

bundle install --standalone --without development test doc repl

Sample systemd service

# /lib/systemd/system/ir-proxy.service
[Unit]
Description=Remote support service
PartOf=graphical-session.target
ConditionPathExists=/dev/tty20

[Service]
Type=simple
ExecStart=/usr/local/bin/_ir-proxy user
StandardInput=tty-fail
StandardOutput=tty
User=root
TTYVHangup=yes
TTYPath=/dev/tty20
TTYReset=yes
RemainAfterExit=false
Restart=always
RestartSec=1s

[Install]
WantedBy=default.target
#!/usr/bin/env sh
# /usr/local/bin/_ir-proxy

export DISPLAY=${2:-:0}
set -eu
X_USER=${1}
LOGFILE=/var/log/ir-proxy.log
CONFIG=/etc/ir-proxy/config.yml
export XAUTHORITY=$(getent passwd "${X_USER}" | cut -d: -f6)/.Xauthority

touch "${LOGFILE}"
chown "${X_USER}" "${LOGFILE}"
(socat - EXEC:'ir-keytable -tc',pty,setsid,ctty | gosu "${X_USER}" -- ir-proxy pipe --config "${CONFIG}") > "${LOGFILE}" 2>&1
sudo systemctl enable ir-proxy.service

Sample kodi keymap

<!-- ~/.kodi/userdata/keymaps/ir-proxy.xml -->
<keymap>
  <global>
    <keyboard>
      <f12>ActivateWindow(Home)</f12>
      <power>ActivateWindow(ShutdownMenu)</power>
    </keyboard>
  </global>
</keymap>

Disable poweroff button

Disable poweroff button (power-key is handled by kodi)
edit /etc/systemd/logind.conf file

HandlePowerKey=ignore

Extract available keys to a YAML syntax

grep -Eo 'KEY_.*' /lib/udev/rc_keymaps/rc6_mce.toml | perl -pe 's/\s+=\s+/: /g' | perl -pe 's/:\s+"KEY_/: "/'

Resources