---
{%- from "sublimetext/map.jinja" import sublimetext with context %}
sublimetext-extract-archive:
  archive.extracted:
    - name: {{ sublimetext.install_dir }}/{{ sublimetext.install_subdir }}_{{ sublimetext.version }}
    - source: {{ sublimetext.fetch_url }}/{{ sublimetext.archive_name|format(sublimetext.version) }}
    - skip_verify: true
    - options: xj --transform 's/^sublime_text//g'
    - enforce_toplevel: false
    - list_options: bzcat
    - user: root
    - group: root
    - mode: 0755
    - if_missing: {{ sublimetext.install_dir }}/{{ sublimetext.install_subdir }}_{{ sublimetext.version }}

sublimetext-install-symlink:
  file.symlink:
    - name: {{ sublimetext.install_dir }}/{{ sublimetext.install_subdir }}
    - target: {{ sublimetext.install_dir }}/{{ sublimetext.install_subdir }}_{{ sublimetext.version }}
    - user: root
    - group: root
    - mode: 0755
    - require:
      - archive: sublimetext-extract-archive

sublimetext-binary-symlink:
  file.symlink:
    - name: /usr/bin/sublime_text
    - target: {{ sublimetext.install_dir }}/{{ sublimetext.install_subdir }}/sublime_text
    - user: root
    - group: root
    - mode: 0755
    - require:
      - archive: sublimetext-extract-archive

sublimetext-licence-key:
  file.managed:
    - name: {{ sublimetext.install_dir }}/{{ sublimetext.install_subdir }}_{{ sublimetext.version }}/{{ sublimetext.keys_file }}
    - source: salt://sublimetext/{{ sublimetext.keys_file }}.j2
    - template: jinja
    - user: root
    - group: root
    - mode: 0644
    - require:
      - archive: sublimetext-extract-archive

sublimetext-desktop-entry:
  file.managed:
    - name: /usr/share/applications/sublime_text.desktop
    - source: salt://sublimetext/sublime_text.desktop.j2
    - template: jinja
    - user: root
    - group: root
    - mode: 0644
    - require:
      - archive: sublimetext-extract-archive