---
- name: Clear OPAM directory
  file:
    path: "{{ app_base }}/.opam"
    state: absent

- name: Install Liquidsoap Dependencies
  apt:
    name: "{{ packages }}"
    install_recommends: false
  vars:
    packages:
      - libao-dev
      - libasound2-dev
      - libavcodec-dev
      - libavdevice-dev
      - libavfilter-dev
      - libavformat-dev
      - libavutil-dev
      - libfaad-dev
      - libfdk-aac-dev
      - libflac-dev
      - libfreetype-dev
      - libgd-dev
      - libjack-dev
      - libjpeg-dev
      - liblo-dev
      - libmad0-dev
      - libmagic-dev
      - libmp3lame-dev
      - libopus-dev
      - libpng-dev
      - libportaudio2
      - libpulse-dev
      - libsamplerate0-dev
      - libsdl2-dev
      - libsdl2-ttf-dev
      - libsdl2-image-dev
      - libshine-dev
      - libsoundtouch-dev
      - libspeex-dev
      - libswresample-dev
      - libswscale-dev
      - libtag1-dev
      - libtheora-dev
      - libtiff-dev
      - libx11-dev
      - libxpm-dev
      - bubblewrap
      - ffmpeg

- name: Install Focal Liquidsoap Dependencies (20.04)
  apt:
    name:
      - libsrt-dev
  when: ansible_distribution_release == 'focal'

- name: Install Jammy Liquidsoap Dependencies (22.04)
  apt:
    name:
      - libsrt-openssl-dev
  when: ansible_distribution_release == 'jammy'

- name: Install Optional Audio Plugins
  apt:
    name: "{{ packages }}"
    install_recommends: false
  vars:
    packages:
      - frei0r-plugins-dev
      - ladspa-sdk
      - multimedia-audio-plugins
      - swh-plugins
      - tap-plugins
      - lsp-plugins-ladspa

- name: Get the DPKG Architecture
  shell: dpkg --print-architecture
  register: dpkg_arch
  ignore_errors: true

- name: Remove Existing Liquidsoap Packages
  apt:
    name: "{{ packages }}"
    state: absent
  vars:
    packages:
      - liquidsoap
      - liquidsoap-snapshot
  ignore_errors: true

- name: Install Liquidsoap
  apt:
    deb: "https://github.com/savonet/liquidsoap/releases/download/v2.1.3/liquidsoap_2.1.3-ubuntu-{{ ansible_distribution_release }}-1_{{ dpkg_arch.stdout_lines[0] | default('amd64') }}.deb"

- name: Link Liquidsoap binary
  file:
    src: "/usr/bin/liquidsoap"
    dest: /usr/local/bin/liquidsoap
    state: link
    force: true
