- name: software | vscodium | add repository key
  shell: sudo wget https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg -O /usr/share/keyrings/vscodium-archive-keyring.asc
  when: ansible_distribution in ["Debian", "Pop!_OS", "Ubuntu"]

- name: software | vscodium | add repository
  apt_repository:
    repo: "deb [ signed-by=/usr/share/keyrings/vscodium-archive-keyring.asc ] https://paulcarroty.gitlab.io/vscodium-deb-rpm-repo/debs vscodium main"
    filename: vscodium
  register: vscodium
  when: ansible_distribution in ["Debian", "Pop!_OS", "Ubuntu"]

- name: software | vscodium | update sources (repo added or changed)
  apt:
    update_cache: yes
  changed_when: False
  when: vscodium.changed

- name: software | vscodium | install package
  apt:
    name: codium
  when: ansible_distribution in ["Debian", "Pop!_OS", "Ubuntu"]

- name: software | vscodium | add repository
  shell: printf "[gitlab.com_paulcarroty_vscodium_repo]\nname=gitlab.com_paulcarroty_vscodium_repo\nbaseurl=https://download.vscodium.com/rpms/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/-/raw/master/pub.gpg\nmetadata_expire=1h" | sudo tee -a /etc/zypp/repos.d/vscodium.repo
  args:
    creates: /etc/zypp/repos.d/vscodium.repo 
  when: ansible_distribution in ["openSUSE Tumbleweed-Slowroll", "openSUSE Leap"]

- name: software | vscodium | add repository
  shell: printf "[gitlab.com_paulcarroty_vscodium_repo]\nname=download.vscodium.com\nbaseurl=https://download.vscodium.com/rpms/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/-/raw/master/pub.gpg\nmetadata_expire=1h" | sudo tee -a /etc/yum.repos.d/vscodium.repo
  args:
    creates: /etc/yum.repos.d/vscodium.repo 
  when: ansible_distribution in ["Fedora"]

- name: software | vscodium | add repo key
  shell: sudo rpmkeys --import https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/-/raw/master/pub.gpg
  when: ansible_distribution in ["Fedora", "openSUSE Leap", "openSUSE Tumbleweed-Slowroll"]

- name: software | vscodium | install 
  tags: packages,system,system-packages,workstation-packages
  package:
    name:
      - codium
  when: ansible_distribution in ["Fedora", "openSUSE Leap", "openSUSE Tumbleweed-Slowroll"]