---

- name: cewe fotobuch installation user
  user:
    name: cewe-fotobuch-setup
    system: yes
    shell: /usr/bin/fish
    home: /opt/cewe-fotobuch

- name: download cewe fotobuch archive
  get_url:
    url: https://dls.photoprintit.com/api/getClient/24441-de_DE/hps/om_seo_goo_x_24441_x_24441-UehoUbeYPPMDm/linux
    dest: /opt/cewe-fotobuch/setup_Mein_CEWE_FOTOBUCH.tgz
    checksum: sha256:c556db58f409c7d3d615d95295edac0263d1490bffd0da2a06e5ddb2517b7ec5
    owner: cewe-fotobuch-setup
    group: cewe-fotobuch-setup

- name: extract cewe fotobuch archive
  unarchive:
    src: /opt/cewe-fotobuch/setup_Mein_CEWE_FOTOBUCH.tgz
    remote_src: yes
    dest: /opt/cewe-fotobuch
    owner: cewe-fotobuch-setup
    group: cewe-fotobuch-setup

- name: cewe fotobuch temp dir
  file:
    path: /opt/cewe-fotobuch/tmp
    state: directory
    owner: cewe-fotobuch-setup
    group: cewe-fotobuch-setup

- name: install cewe fotobuch
  shell: yes ja | ./install.pl -i /opt/cewe-fotobuch -w /opt/cewe-fotobuch/tmp/ -k -v
  args:
    chdir: /opt/cewe-fotobuch
    creates: /opt/cewe-fotobuch/hps-16523-6.3.4.desktop
  become: true
  become_user: cewe-fotobuch-setup
  become_method: su

- name: find desktop file
  find:
    paths: /opt/cewe-fotobuch/.local/share/applications/
    excludes:
      - defaults.list
    recurse: yes
    file_type: file
  register: _find_cewe_fotobuch_shares

- name: copy desktop file
  copy:
    src: "{{_find_cewe_fotobuch_shares|json_query('files[].path')|first}}"
    remote_src: yes
    dest: "/usr/share/applications/cewe-fotobuch.desktop"
    mode: 0644

- name: find all icon files
  find:
    paths: /opt/cewe-fotobuch/.local/share/icons/
    recurse: yes
    file_type: file
  register: _find_cewe_fotobuch_shares

- name: copy icon files
  copy:
    src: "/opt/cewe-fotobuch/.local/share/{{item}}"
    remote_src: yes
    dest: "/usr/share/{{item}}"
    mode: 0644
  with_items: "{{_find_cewe_fotobuch_shares|json_query('files[].path')|map('relpath','/opt/cewe-fotobuch/.local/share/')|list}}"
