---
# Lutris for running Windows games not in Steam.
#   https://lutris.net/downloads

# Paths

- name: Workstation | Linux | Software | Lutris | Facts
  set_fact:
    lutris_source_list: "/etc/apt/sources.list.d/lutris.list"
    lutris_keyfile: "/usr/share/keyrings/lutris.gpg"
  when: ansible_pkg_mgr == "apt"

# Checks

- name: Workstation | Linux | Software | Lutris | Check PPA
  stat:
    path: "{{ lutris_source_list }}"
  register: lutris_source_exists
  when: ansible_pkg_mgr == "apt"

## Install Repo ##

- name: Workstation | Linux | Software | Lutris | Add PPA (Ubuntu)
  apt_repository:
    repo: ppa:lutris-team/lutris
    update_cache: yes
    state: present
  when: ansible_distribution in ("Ubuntu") and gaming == true
  ignore_errors: yes

- name: Workstation | Linux | Software | Lutris | Add PPA (Debian)
  shell: "{{ item }}"
  loop:
    - "wget -q -O- https://download.opensuse.org/repositories/home:/strycore/Debian_12/Release.key \
      | gpg --dearmor \
      | sudo tee {{ lutris_keyfile }} > /dev/null"
    - "echo 'deb [signed-by={{ lutris_keyfile }}] https://download.opensuse.org/repositories/home:/strycore/Debian_12/ ./' \
      | sudo tee {{ lutris_source_list }} > /dev/null"
    - "sudo apt update"
  when: ansible_distribution in ("Debian") and gaming == true and not lutris_source_exists.stat.exists

## Install Package ##

- name: Workstation | Linux | Software | Lutris | Install (besides ARM)
  package:
    name:
      - lutris
    state: present
  when: ansible_architecture != "aarch64" and gaming == true

## Uninstall Package ##

- name: Workstation | Linux | Software | Lutris | Uninstall (besides ARM)
  package:
    name:
      - lutris
    state: absent
  when: ansible_architecture != "aarch64" and gaming != true

## Uninstall Repo ##

- name: Workstation | Linux | Software | Lutris | Remove PPA (Ubuntu)
  apt_repository:
    repo: ppa:lutris-team/lutris
    update_cache: yes
    state: absent
  when: ansible_distribution in ("Ubuntu") and gaming != true
  ignore_errors: yes

- name: Workstation | Linux | Software | Lutris | Remove PPA (Debian)
  shell: "{{ item }}"
  loop:
    - "mv {{ lutris_source_list }} ~/TRASH/"
    - "mv {{ lutris_keyfile }} ~/TRASH/"
    - "sudo apt update"
  when: ansible_distribution in ("Debian") and gaming != true and lutris_source_exists.stat.exists