---
- name: Create directory for local .desktop-Files
  ansible.builtin.file:
    path: "{{ item }}"
    state: directory
    mode: '0755'
  loop:
    - /usr/local/share/applications
    - /usr/local/share/desktop-directories
  notify: Run update-desktop-database

- name: Copy fvs.directory
  ansible.builtin.copy:
    src: fvs.directory
    dest: /usr/local/share/desktop-directories/
    mode: '0644'
  notify: Run update-desktop-database

- name: Copy fvs.menu
  ansible.builtin.copy:
    src: fvs.menu
    dest: /etc/xdg/menus/applications-merged/
    mode: '0644'
  notify: Run update-desktop-database

- name: Copy lmn-sync script
  ansible.builtin.copy:
    src: lmn-sync
    dest: /usr/local/sbin/
    mode: '0755'
  register: lmn_sync

- name: Run lmn-sync script
  ansible.builtin.shell: /usr/local/sbin/lmn-sync
  when: lmn_sync.changed # noqa: no-handler

- name: Deploy sudo configurations (lmn-sync for role-teacher)
  ansible.builtin.copy:
    dest: /etc/sudoers.d/90-lmn-sync
    owner: root
    group: root
    mode: '0700'
    content: |
      %role-teacher ALL=(root) NOPASSWD: /usr/local/sbin/lmn-sync

- name: Provide lmn-sync service and timer
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: "/etc/systemd/system/{{ item }}"
    mode: '0644'
  loop:
    - lmn-sync.service
    - lmn-sync.timer

- name: Enable lmn-sync.timer
  ansible.builtin.systemd:
    name: lmn-sync.timer
    enabled: true
