Add xremap role for macOS bindings on Linux

This commit is contained in:
Kenneth Benzie 2023-06-08 23:41:06 +01:00
parent 49b292126e
commit 878db362cd
4 changed files with 141 additions and 0 deletions

View File

@ -4,3 +4,4 @@
- hosts: localhost - hosts: localhost
roles: roles:
- role: kitty - role: kitty
- role: xremap

View File

@ -0,0 +1,7 @@
---
- name: restart xremap
systemd:
name: xremap
scope: user
daemon_reload: true
state: restarted

View File

@ -0,0 +1,123 @@
---
- assert:
that: ansible_env.XDG_CURRENT_DESKTOP == "GNOME" and
ansible_env.XDG_SESSION_TYPE == "wayland"
- set_fact:
install_dir: '{{ansible_env.HOME}}/.local/bin'
config_dir: '{{ansible_env.HOME}}/.config/xremap'
- set_fact:
executable_path: '{{install_dir}}/xremap'
- name: stat executable
stat:
path: '{{executable_path}}'
register: executable
- name: get installed version
when: executable.stat.exists
command: '{{executable_path}} --version'
register: version_command
changed_when: false
- name: extract version from command output
when: executable.stat.exists
set_fact:
installed_version:
'v{{version_command.stdout.strip() | regex_replace("^.*(\d+\.\d+\.\d+).*$", "\1")}}'
- name: get latest release
uri:
url: https://api.github.com/repos/k0kubun/xremap/releases/latest
register: latest
- name: determine if install needed
set_fact:
needs_installed:
'{{not executable.stat.exists or installed_version != latest.json.name}}'
- name: construct asset query
set_fact:
asset_query: >
[?contains(name, `xremap-linux-{{ansible_architecture}}-{{
ansible_env.XDG_CURRENT_DESKTOP | lower}}.zip`)] | [0]
- name: get release asset
set_fact:
asset: '{{latest.json.assets | to_json | from_json | json_query(asset_query)}}'
- name: create directories
file:
path: '{{item}}'
state: directory
with_items:
- '{{install_dir}}'
- '{{config_dir}}'
- name: download release archive
when: needs_installed
become: true
get_url:
url: '{{asset.browser_download_url}}'
dest: '{{install_dir}}/xremap.zip'
- name: extract release archive
when: needs_installed
become: true
unarchive:
src: '{{install_dir}}/xremap.zip'
dest: '{{install_dir}}'
- name: remove release archive
when: needs_installed
become: true
file:
path: '{{install_dir}}/xremap.zip'
state: absent
- name: add user to input group
become: true
user:
name: '{{ansible_user_id}}'
append: true
groups: input
# TODO: This works for on Fedora, author uses it on Ubuntu so I assume Debian
# will work too. Arch and other distros are potentially different see the docs
# https://github.com/k0kubun/xremap
- name: add udev rule for input access
become: true
copy:
content: |
KERNEL=="uinput", GROUP="input", TAG+="uaccess"
dest: /etc/udev/rules.d/input.rules
- name: clone config repo
git:
repo: git@code.infektor.net:config/xremap.git
dest: '{{config_dir}}'
notify: restart xremap
- name: install xremap systemd unit
template:
src: xremap.service.j2
dest: ~/.config/systemd/user/xremap.service
notify: restart xremap
- name: enable xremap service
systemd:
name: xremap
scope: user
enabled: true
state: started
- name: check if extension is installed
command: gnome-extensions show xremap@k0kubun.com
changed_when: false
failed_when: false
register: extension
- when: extension.rc != 0
debug:
msg: 'install gnome extension then reboot:
https://extensions.gnome.org/extension/5060/xremap'
changed_when: true

View File

@ -0,0 +1,10 @@
[Unit]
Description=macOS Key Remapping
[Service]
Type=simple
ExecStart={{executable_path}} {{config_dir}}/macOS.yaml
Restart=on-failure
[Install]
WantedBy=default.target