---
{%- from "syncthing/map.jinja" import syncthing with context %}
syncthing-archive-extract:
  archive.extracted:
    - name: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
    - source: {{ syncthing.mirror }}/v{{ syncthing.version }}/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}.tar.gz
    - enforce_toplevel: false
    - skip_verify: true
    - archive_format: tar
    - options: --transform 's/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}/syncthing-{{ syncthing.version }}/g' --strip 1
    - if_missing: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
    - watch_in:
      - service: syncthing-service

syncthing-bin-symlink:
  file.symlink:
    - name: {{ syncthing.install_dir }}/syncthing
    - target: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
    - watch_in:
      - service: syncthing-service

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