local/roles/xremap/tasks/main.yaml
Kenneth Benzie (Benie) e711b9f3b2 Add optional GitHub API authentication headers
If the `GITHUB_TOKEN` is defined in the Ansible controller's
environment it is used to set the GitHub REST API authentication header.
This is they passed to all `uri` modules tasks which interact with the
GitHub REST API. If the `GITHUB_TOKEN` is not set, the authentication
header is not used.

Fixes #19
2024-04-06 16:35:01 +01:00

136 lines
3.4 KiB
YAML

---
- assert:
that: >
'GNOME' in ansible_env.XDG_CURRENT_DESKTOP 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
headers: '{{github_auth_headers}}'
register: latest
- name: determine if install needed
set_fact:
needs_installed:
'{{not executable.stat.exists or installed_version != latest.json.name}}'
xdg_current_desktop:
"{{ansible_env.XDG_CURRENT_DESKTOP | regex_replace('(.*:)?(.*)', '\\2')}}"
- name: construct asset query
set_fact:
asset_query: >
[?contains(name, `xremap-linux-{{ansible_architecture}}-{{
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
- name: load the uinput kernel module
when: ansible_os_family == 'Debian'
become: true
copy:
content: |
uinput
dest: /etc/modules-load.d/uinput.conf
# 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