---
- name: Create greenfoot/bluej version strings w/o points
  set_fact:
    bluejVersion: "{{ bluej_target_version  | replace('.','') }}"
    greenfootVersion: "{{ greenfoot_target_version  | replace('.','') }}"

- name: Get download URIs
  set_fact:
    bluejURI: "{{ bluej_src_uri | replace ('VERSION', bluejVersion) }}"
    greenfootURI: "{{ greenfoot_src_uri | replace ('VERSION', greenfootVersion) }}"

- name: Create target filenames
  set_fact:
    bluejTargetFile: /var/www/html/javadev/bluej-{{ bluej_target_version }}.deb
    greenfootTargetFile: /var/www/html/javadev/greenfoot-{{ greenfoot_target_version }}.deb

- name: Check if greenfoot target-file exists
  delegate_to: localhost
  stat:
    path: "{{ greenfootTargetFile }}"
  register: gftf

- name: Check if bluej target-file exists
  delegate_to: localhost
  stat:
    path: "{{ bluejTargetFile }}"
  register: bjtf

- name: Download Greenfoot
  delegate_to: localhost
  command: wget {{ greenfootURI }} -O {{ greenfootTargetFile }}
  when: not gftf.stat.exists

- name: Download Greenfoot
  delegate_to: localhost
  command: wget {{ greenfootURI }} -O {{ greenfootTargetFile }}
  when: not gftf.stat.exists

#### Freecad

- name: Check if freecad target-file exists
  delegate_to: localhost
  stat:
    path: "{{ freecadTargetFile }}"
  register: fctf

- name: Download FreeCAD AppImage
  delegate_to: localhost
  command: wget {{ freecadFullURI }} -O {{ freecadTargetFile }}
  when: not fctf.stat.exists

#### Logseq

- name: Check if logseq target-file exists
  delegate_to: localhost
  stat:
    path: "{{ logseqTargetFile }}"
  register: lstf

- name: Download logseq AppImage
  delegate_to: localhost
  command: wget {{ logseqFullURI }} -O {{ logseqTargetFile }}
  when: not lstf.stat.exists

### Scratch offline

- name: Download Scratch Offline deb
  delegate_to: localhost
  command: wget {{ scratch_src_uri }} -O /var/www/html/debs/{{ scratch_install_name }}
