---
## Temporary fixes and quirks:
- name: Remove disturbing NetworkManager connection
  ansible.builtin.file:
    path: "/etc/NetworkManager/system-connections/Wired connection 1"
    state: absent
  when: ansible_interfaces | select('search', '^en[pso].+') | length > 1

- name: Fix 8086:4909 external graphics card
  ansible.builtin.replace:
    dest: "/etc/default/grub"
    regexp: 'GRUB_CMDLINE_LINUX=""$'
    replace: 'GRUB_CMDLINE_LINUX="i915.force_probe=4909"'
  notify: Run update-grub
  when: ansible_board_vendor == "LENOVO" and ansible_board_name == "32CB"

- name: Fix sound on 312A
  ansible.builtin.replace:
    dest: "/etc/default/grub"
    regexp: 'GRUB_CMDLINE_LINUX="snd-intel-dspcfg.dsp_driver=1"$'
    replace: 'GRUB_CMDLINE_LINUX=""'
  notify: Run update-grub
  when: ansible_board_vendor == "LENOVO" and ansible_board_name == "312A"

- name: Fix sound on 312A and 312D
  ansible.builtin.apt:
    name: firmware-sof-signed
    state: latest
  when: >
    ansible_board_vendor == "LENOVO" and
    (ansible_board_name == "312D" or ansible_board_name == "312A")

- name: Install customized CodeBlocks packages
  when: "'PCroom' in group_names"
  block:
    - name: Check for old CodeBlocks
      ansible.builtin.command:
        cmd: dpkg -l codeblocks
      register: codeblocks_version
      changed_when: false

    - name: Download codeblocks zip archive
      ansible.builtin.get_url:
        url: "http://livebox.pn.steinbeis.schule/codeblocks/CodeBlocks.zip"
        dest: /tmp/CodeBlocks.zip
        mode: '0644'
        use_proxy: false
      register: new_codeblocks
      when: codeblocks_version.stdout is not search('svn13544')

    - name: Unpack zip archive and install packages manually
      ansible.builtin.shell:
        cmd: unzip -d /tmp/cb/ CodeBlocks.zip && dpkg -i cb/*.deb
        chdir: /tmp/
      when: new_codeblocks.changed | default(false)

- name: Work around sddm hang on shutdown
  ansible.builtin.lineinfile:
    path: /etc/systemd/system.conf
    line: DefaultTimeoutStopSec=5s
    insertafter: '^#DefaultTimeoutStopSec=.*'

- name: Patch spyder to fix 'file-has-changed' issues on CIFS
  ansible.posix.patch:
    src: spyder.patch
    dest: /usr/lib/python3/dist-packages/spyder/plugins/editor/widgets/editor.py
