From 0e382508fca98fea1dec41b157f3776e659e89cb Mon Sep 17 00:00:00 2001
From: N <noel.mcloughlin@gmail.com>
Date: Tue, 2 Oct 2018 13:19:57 +0100
Subject: [PATCH] MacOS Desktop shortcut handling
---
README.rst | 2 +-
mysql/defaults.yaml | 28 +++++++-------
mysql/files/mac_shortcut.sh | 10 +++++
mysql/macos/install.sls | 75 ++++++++++++++++++++++++-------------
mysql/macos/remove.sls | 24 ++++++++++--
5 files changed, 97 insertions(+), 42 deletions(-)
create mode 100755 mysql/files/mac_shortcut.sh
diff --git a/README.rst b/README.rst
index d1e4f88..fb81acb 100644
--- a/README.rst
+++ b/README.rst
@@ -23,7 +23,7 @@ Meta-state including all server packages in correct order. This meta-state does
``mysql.macos``
----------------
-Install "MySQL Community Server", "MySQL Workbench", and any other enabled products on MacOS.
+Install "MySQL Community Server", "MySQL Workbench", and other related mysql products on MacOS (and create Desktop shortcuts).
``mysql.macos.remove``
----------------
diff --git a/mysql/defaults.yaml b/mysql/defaults.yaml
index 807c17b..1c46974 100644
--- a/mysql/defaults.yaml
+++ b/mysql/defaults.yaml
@@ -27,7 +27,7 @@ mysql:
group:
dl:
tmpdir: /tmp/mysqltmp
- bindir: /usr/local/bin
+ prefix: /usr/local
opts: -s -L
interval: 60
retries: 2
@@ -36,58 +36,60 @@ mysql:
enabled: True
url: https://downloads.mysql.com/archives/get/file/mysql-8.0.11-macos10.13-x86_64.dmg
sum: 'md5=602a84390ecf3d82025b1d99fc594124'
- dest: /Applications/MySQL.app
isapp: False
+ path: /usr/local/mysql
+ app: mysql
workbench:
enabled: True
url: https://downloads.mysql.com/archives/get/file/mysql-workbench-community-8.0.11-rc-macos-x86_64.dmg
sum: 'md5=37c5ae5bd75a4e1804ae6e0127d68611'
- dest: /Applications/MySQLWorkbench.app
+ isapp: True
+ path: /Applications/MySQLWorkbench/Contents/Versions/latest
+ app: MySQLWorkbench
cluster:
enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-cluster-gpl-7.6.6-macos10.13-x86_64.dmg
sum: 'md5=0df975908e7d8e4e8c1003d95edf4721'
- dest: /Applications/MySQLCluster.app
+ isapp: False
+ path: /usr/local/mysqlcluster
+ app: MySQLCluster
router:
enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-router-8.0.11-macos10.13-x86-64bit.dmg
sum: 'md5=8dd536f2f223933ecbfb8b19e54ee2f6'
- dest: /Applications/MySQLRouter.app
+ isapp: False
+ app: MySQLRouter
utilities:
enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-utilities-1.6.5-macos10.12.dmg
sum: 'md5=4c8e75bb217b8293dcdeb915b649c2c8'
- dest: /Applications/MySQLUtilities.app
+ isapp: True ## ??
+ app: MySQLUtilties
shell:
enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-shell-8.0.11-macos10.13-x86-64bit.dmg
sum: 'md5=43db4f0fc39f88c1d7be4a4f52cec363'
- dest: /Applications/MySQLShell.app
+ isapp: True ## ??
+ app: MySQLShell
proxy:
enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-proxy-0.8.5-osx10.7-x86-32bit.tar.gz
sum: 'md5=107df22412aa8c483d2021e1af24ee22'
- dest: /opt/mysql/proxy
connnector:
- enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-connector-nodejs-8.0.11.tar.gz
sum: 'md5=dece7fe5607918ba68499ef07c31508d'
- dest: /opt/mysql/connector/nodejs
forvisualstudio:
enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-for-visualstudio-2.0.4-src.zip
sum: 'md5=fcf39316505ee2921e31a431eae77a9c'
- dest: /opt/mysql/visualstudio
forexcel:
enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-for-excel-1.3.6-src.zip
sum: 'md5=2cc8b65eb72a1b07a6e4e2665e2a29e3'
- dest: /opt/mysql/excel
notifier:
enabled: False
url: https://downloads.mysql.com/archives/get/file/mysql-notifier-1.1.6-src.zip
sum: 'md5=349f1994681763fd6626a8ddf6be5363'
- dest: /opt/mysql/notifier
#The following dict names are reserved for pillar data (see pillar.example)
global: {}
diff --git a/mysql/files/mac_shortcut.sh b/mysql/files/mac_shortcut.sh
new file mode 100755
index 0000000..f768592
--- /dev/null
+++ b/mysql/files/mac_shortcut.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+CMD='/usr/bin/osascript -e'
+if [[ -f "{{ home }}/{{ user }}/Desktop/{{ app }}" ]] && [[ "${1}" -eq "remove" ]]
+then
+ ${CMD} "tell application \"Finder\" to delete file \"{{home}}/{{user}}/Desktop/{{ app }}\""
+elif [[ -d "{{ dir }}/{{ app }}" ]] && [[ "${1}" -eq "add" ]]
+then
+ ${CMD} "tell application \"Finder\" to make new Alias at (path to desktop folder) to POSIX file \"{{ dir }}/{{ app }}\""
+fi
diff --git a/mysql/macos/install.sls b/mysql/macos/install.sls
index 8f1e163..024b4f5 100644
--- a/mysql/macos/install.sls
+++ b/mysql/macos/install.sls
@@ -1,9 +1,9 @@
### mysql/macos/install.sls
# -*- coding: utf-8 -*-
# vim: ft=yaml
-{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import mysql with context -%}
+{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import mysql with context %}
- {%- set dl = mysql.macos.dl %}
+ {%- set dl = mysql.macos.dl %}
mysql-macos-extract-dirs:
file.directory:
@@ -11,13 +11,14 @@ mysql-macos-extract-dirs:
- makedirs: True
- clean: True
- {%- for product, data in mysql.macos.products.items() if data.enabled %}
- {%- set archivename = data.url.split('/')[-1]|quote %}
- {%- set archiveformat = archivename.split('.')[-1] %}
+ {%- 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-remove-previous-{{ product }}-download-archive:
file.absent:
- - name: {{ dl.tmpdir }}/{{ archivename }}
+ - name: {{ dl.tmpdir }}/{{ archivefile }}
- require_in:
- mysql-macos-download-{{ product }}-archive
@@ -25,7 +26,7 @@ mysql-macos-download-{{ product }}-archive:
pkg.installed:
- name: curl
cmd.run:
- - name: curl {{ dl.opts }} -o {{ dl.tmpdir }}/{{ archivename }} {{ data.url }}
+ - name: curl {{ dl.opts }} -o {{ dl.tmpdir }}/{{ archivefile }} {{ data.url }}
{% if grains['saltversioninfo'] >= [2017, 7, 0] %}
- retry:
attempts: {{ dl.retries }}
@@ -34,52 +35,76 @@ mysql-macos-download-{{ product }}-archive:
- require:
- mysql-macos-extract-dirs
- {%- if data.sum %}
+ {%- if data.sum %}
mysql-macos-check-{{ product }}-archive-hash:
module.run:
- name: file.check_hash
- - path: {{ dl.tmpdir }}/{{ archivename }}
+ - path: {{ dl.tmpdir }}/{{ archivefile }}
- file_hash: {{ data.sum }}
- onchanges:
- mysql-macos-download-{{ product }}-archive
- require_in:
- mysql-macos-{{ product }}-install
- {%- endif %}
+ {%- endif %}
mysql-macos-{{ product }}-install:
- {%- if archiveformat in ('dmg',) %}
+ {%- if archiveformat in ("dmg",) %}
+
macpackage.installed:
- - name: "{{ dl.tmpdir }}/{{ archivename }}"
+ - 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
- - require_in:
- - mysql-macos-remove-{{ product }}-archive
- file.append:
- - name: {{ mysql.macos.userhomes }}/{{ mysql.macos.user }}/.bash_profile
- - text: 'export PATH=$PATH:{{ data.dest }}/Contents/Versions/latest/bin'
- {%- elif archiveformat in ('gz', 'zip',) %}
+ {%- elif archiveformat in ("gz", "zip",) %}
+
archive.extracted:
- - source: file://{{ dl.tmpdir }}{{ archivename }}
- - name: {{ dl.bindir }}
+ - source: file://{{ dl.tmpdir }}{{ archivefile }}
+ - name: {{ dl.prefix }}/{{ archivename }}
- trim_output: True
- source_hash: {{ data.sum }}
- onchanges:
- mysql-macos-download-{{ product }}-archive
+
+ {%- endif %}
- require_in:
- - mysql-macos-remove-{{ product }}-archive
+ - mysql-macos-tidyup-{{ product }}
+
+ {%- 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 }}
+ dir: {{'/Applications/' ~ data.app ~ '.app' if "isapp" in data and data.isapp else dl.prefix ~ '/' ~ archivename ~ '/bin'}}
+ app: {{ data.app }}
+ cmd.run:
+ - name: /tmp/mac_shortcut.sh add
+ - runas: {{ mysql.macos.user }}
+ - require:
+ - file: mysql-macos-{{ product }}-desktop-shortcut-add
- {%- endif %}
+ {%- endif %}
-mysql-macos-remove-{{ product }}-archive:
+mysql-macos-tidyup-{{ product }}:
file.absent:
- - name: {{ dl.tmpdir }}/{{ archivename }}
+ - name: {{ dl.tmpdir }}/{{ archivefile }}
- onchanges:
- mysql-macos-download-{{ product }}-archive
- {%- endfor %}
+ {% endfor %}
diff --git a/mysql/macos/remove.sls b/mysql/macos/remove.sls
index 30fcb53..77c7c2e 100644
--- a/mysql/macos/remove.sls
+++ b/mysql/macos/remove.sls
@@ -3,13 +3,31 @@
# vim: ft=yaml
{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import mysql with context -%}
- {%- for product, data in mysql.macos.products.items() if data.enabled %}
- {%- set archivename = data.url.split('/')[-1] %}
+ {%- set dl = mysql.macos.dl %}
+ {%- for product, data in mysql.macos.products.items() if "enabled" in data and data.enabled %}
+ {%- set archivename = data.url.split('/')[-1]|replace('.dmg', '')|replace('.tar.gz', '')|replace('.zip', '') %}
mysql-macos-{{ product }}-remove-destdir:
file.absent:
- names:
- - {{ data.dest }}
+ - {{ data.path }}
+
+mysql-macos-{{ product }}-desktop-shortcut-remove:
+ 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 }}
+ dir: {{'/Applications/' ~ data.app ~ '.app' if "isapp" in data and data.isapp else dl.prefix ~ '/' ~ archivename ~ '/bin'}}
+ app: {{ data.app }}
+ cmd.run:
+ - name: /tmp/mac_shortcut.sh remove
+ - runas: {{ mysql.macos.user }}
+ - require:
+ - file: mysql-macos-{{ product }}-desktop-shortcut-remove
{%- endfor %}
--
GitLab