Skip to content
Snippets Groups Projects
install.sls 3 KiB
Newer Older
  • Learn to ignore specific revisions
  • ###  mysql/macos/install.sls
    # -*- coding: utf-8 -*-
    # vim: ft=yaml
    
    N's avatar
    N committed
    {%- from salt.file.dirname(tpldir) ~ "/map.jinja" import mysql with context %}
    
    N's avatar
    N committed
      {%- set dl = mysql.macos.dl %}
    
    
    mysql-macos-extract-dirs:
      file.directory:
        - name: {{ dl.tmpdir }}
        - makedirs: True
    
    
    N's avatar
    N committed
      {%- for product, data in mysql.macos.products.items() if "enabled" in data and data.enabled %}
          {%- set archivefile = data.url.split('/')[-1] %}
          {%- set archiveformat = archivefile.split('.')[-1] %}
          {%- set archivename = archivefile|replace('.dmg', '')|replace('.tar.gz', '')|replace('.zip', '') %}
    
    
    mysql-macos-download-{{ product }}-archive:
      pkg.installed:
        - name: curl
      cmd.run:
    
    N's avatar
    N committed
        - name: curl {{ dl.opts }} -o {{ dl.tmpdir }}/{{ archivefile }} {{ data.url }}
    
    N's avatar
    N committed
        - unless: test -f {{ dl.tmpdir }}/{{ archivefile }}
    
          {%- if grains['saltversioninfo'] >= [2017, 7, 0] %}
    
        - retry:
            attempts: {{ dl.retries }}
            interval: {{ dl.interval }}
    
    N's avatar
    N committed
            until: True
            splay: 10
    
        - require:
          - mysql-macos-extract-dirs
    
    
    N's avatar
    N committed
        {%- if data.sum %}
    
    mysql-macos-check-{{ product }}-archive-hash:
       module.run:
         - name: file.check_hash
    
    N's avatar
    N committed
         - path: {{ dl.tmpdir }}/{{ archivefile }}
    
         - file_hash: {{ data.sum }}
    
    N's avatar
    N committed
         - require:
           - cmd: mysql-macos-download-{{ product }}-archive
    
         - require_in:
           - mysql-macos-{{ product }}-install
    
    N's avatar
    N committed
        {%- endif %}
    
    
    mysql-macos-{{ product }}-install:
    
    N's avatar
    N committed
        {%- if archiveformat in ("dmg",) %}
    
    
      macpackage.installed:
    
    N's avatar
    N committed
        - name: "{{ dl.tmpdir }}/{{ archivefile }}"
    
        - dmg: True
        - app: {{ 'True' if "isapp" not in data else data.isapp }}
        - force: True
        - allow_untrusted: True
        - onchanges:
          - mysql-macos-download-{{ product }}-archive
    
    
    N's avatar
    N committed
        {%- elif archiveformat in ("gz", "zip",) %}
    
    
      archive.extracted:
    
    N's avatar
    N committed
        - source: file://{{ dl.tmpdir }}{{ archivefile }}
        - name: {{ dl.prefix }}/{{ archivename }}
    
        - trim_output: True
        - source_hash: {{ data.sum }}
        - onchanges:
          - mysql-macos-download-{{ product }}-archive
    
    N's avatar
    N committed
        {%- endif %}
    
          {%- if "path" in data and data.path and "app" in data and data.app %}
    
    mysql-macos-append-{{ product }}-path-to-bash-profile:
      file.append:
        - name: {{ mysql.macos.userhomes }}/{{ mysql.macos.user }}/.bash_profile
        - text: 'export PATH=$PATH:{{ data.path }}/bin'
        - onlyif: test -d {{ data.path }}/bin
    
    mysql-macos-{{ product }}-desktop-shortcut-add:
      file.managed:
        - name: /tmp/mac_shortcut.sh
        - source: salt://mysql/files/mac_shortcut.sh
        - mode: 755
        - template: jinja
        - context:
    
            user: {{ mysql.macos.user }}
            home: {{ mysql.macos.userhomes }}
            app: {{ data.app }}
            dir: {{ '/Applications' if "isapp" in data and data.isapp else dl.prefix ~ '/' ~ archivename ~ '/bin' }}
            suffix: {{ '.app' if "isapp" in data and data.isapp else '' }}
    
    N's avatar
    N committed
      cmd.run:
        - name: /tmp/mac_shortcut.sh add
        - runas: {{ mysql.macos.user }}
        - require:
          - file: mysql-macos-{{ product }}-desktop-shortcut-add
    
    N's avatar
    N committed
        {%- endif %}