---
{%- from "lego/map.jinja" import lego with context %}
lego-archive-extract:
  archive.extracted:
    - name: {{ lego.release_dir }}/lego-{{ lego.version }}
    - source: {{ lego.mirror }}/v{{ lego.version }}/lego_v{{ lego.version }}_{{ lego.os }}_{{ lego.arch }}.tar.gz
    - skip_verify: true
    - enforce_toplevel: false
    - if_missing: {{ lego.release_dir }}/lego-{{ lego.version }}

lego-binary-symlink:
  file.symlink:
    - name: /usr/local/bin/lego
    - target: {{ lego.release_dir }}/lego-{{ lego.version }}/lego
    - force: true
    - require:
      - archive: lego-archive-extract

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