---
{%- from "arduino/map.jinja" import arduino with context %}
arduino-archive-extract:
  archive.extracted:
    - name: {{ arduino.release_dir }}
    - source: {{ arduino.mirror }}/arduino-{{ arduino.version }}-{{ arduino.arch }}.tar.xz
    - skip_verify: true
    - archive_format: tar
    - keep: true
    - if_missing: {{ arduino.release_dir }}/arduino-{{ arduino.version }}

arduino-symlink:
  file.symlink:
    - name: {{ arduino.install_dir }}/arduino
    - target: {{ arduino.release_dir }}/arduino-{{ arduino.version }}
    - force: true
    - onchanges:
      - arduino-archive-extract

arduino-bin-symlink:
  file.symlink:
    - name: /usr/bin/arduino
    - target: {{ arduino.install_dir }}/arduino-{{ arduino.version }}/arduino
    - force: true
    - onchanges:
      - arduino-archive-extract

arduino-shortcut:
  file.managed:
    - name: /usr/share/applications/arduino-arduinoide.desktop
    - source: salt://arduino/arduino-arduinoide.desktop.j2
    - template: jinja
    - user: root
    - group: root
    - mode: 644
    - onchanges:
      - arduino-archive-extract
      - arduino-symlink

arduino-cleanup:
  software.cleanup:
    - name: arduino
    - path: {{ arduino.release_dir }}
    - version: "{{ arduino.version }}"