diff --git a/README.rst b/README.rst index 111bf10..fb81acb 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ mysql ===== -Install the MySQL client and/or server. +Install the MySQL client and/or server on Linux and MacOS. .. note:: @@ -18,23 +18,29 @@ Available states ``mysql`` --------- -Meta-state that includes all server packages in the correct order. +Meta-state including all server packages in correct order. This meta-state does **not** include ``mysql.remove_test_database``. -This meta-state does **not** include ``mysql.remove_test_database``; see -below for details. +``mysql.macos`` +---------------- + +Install "MySQL Community Server", "MySQL Workbench", and other related mysql products on MacOS (and create Desktop shortcuts). + +``mysql.macos.remove`` +---------------- + +Remove "MySQL Community Server", "MySQL Workbench", and any other enabled products from MacOS. ``mysql.client`` ---------------- -Install the MySQL client package. +Install the MySQL client package on Linux. ``mysql.server`` ---------------- Install the MySQL server package and start the service. -Debian OS family supports setting MySQL root password during install via -debconf. +Debian OS family supports setting MySQL root password during install via debconf. .. note:: diff --git a/mysql/defaults.yaml b/mysql/defaults.yaml index d189904..1c46974 100644 --- a/mysql/defaults.yaml +++ b/mysql/defaults.yaml @@ -21,6 +21,76 @@ mysql: port: 3306 datadir: /var/lib/mysql + macos: + userhomes: /Users + user: + group: + dl: + tmpdir: /tmp/mysqltmp + prefix: /usr/local + opts: -s -L + interval: 60 + retries: 2 + products: + community_server: + enabled: True + url: https://downloads.mysql.com/archives/get/file/mysql-8.0.11-macos10.13-x86_64.dmg + sum: 'md5=602a84390ecf3d82025b1d99fc594124' + 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' + 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' + 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' + 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' + 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' + 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' + connnector: + url: https://downloads.mysql.com/archives/get/file/mysql-connector-nodejs-8.0.11.tar.gz + sum: 'md5=dece7fe5607918ba68499ef07c31508d' + forvisualstudio: + enabled: False + url: https://downloads.mysql.com/archives/get/file/mysql-for-visualstudio-2.0.4-src.zip + sum: 'md5=fcf39316505ee2921e31a431eae77a9c' + forexcel: + enabled: False + url: https://downloads.mysql.com/archives/get/file/mysql-for-excel-1.3.6-src.zip + sum: 'md5=2cc8b65eb72a1b07a6e4e2665e2a29e3' + notifier: + enabled: False + url: https://downloads.mysql.com/archives/get/file/mysql-notifier-1.1.6-src.zip + sum: 'md5=349f1994681763fd6626a8ddf6be5363' + #The following dict names are reserved for pillar data (see pillar.example) global: {} clients: {} 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/init.sls b/mysql/macos/init.sls new file mode 100644 index 0000000..dbe2ee1 --- /dev/null +++ b/mysql/macos/init.sls @@ -0,0 +1,3 @@ + +include: + - mysql.macos.install diff --git a/mysql/macos/install.sls b/mysql/macos/install.sls new file mode 100644 index 0000000..024b4f5 --- /dev/null +++ b/mysql/macos/install.sls @@ -0,0 +1,110 @@ +### mysql/macos/install.sls +# -*- coding: utf-8 -*- +# vim: ft=yaml +{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import mysql with context %} + + {%- set dl = mysql.macos.dl %} + +mysql-macos-extract-dirs: + file.directory: + - name: {{ dl.tmpdir }} + - makedirs: True + - clean: True + + {%- 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 }}/{{ archivefile }} + - require_in: + - mysql-macos-download-{{ product }}-archive + +mysql-macos-download-{{ product }}-archive: + pkg.installed: + - name: curl + cmd.run: + - name: curl {{ dl.opts }} -o {{ dl.tmpdir }}/{{ archivefile }} {{ data.url }} + {% if grains['saltversioninfo'] >= [2017, 7, 0] %} + - retry: + attempts: {{ dl.retries }} + interval: {{ dl.interval }} + {% endif %} + - require: + - mysql-macos-extract-dirs + + {%- if data.sum %} +mysql-macos-check-{{ product }}-archive-hash: + module.run: + - name: file.check_hash + - path: {{ dl.tmpdir }}/{{ archivefile }} + - file_hash: {{ data.sum }} + - onchanges: + - mysql-macos-download-{{ product }}-archive + - require_in: + - mysql-macos-{{ product }}-install + {%- endif %} + +mysql-macos-{{ product }}-install: + {%- if archiveformat in ("dmg",) %} + + macpackage.installed: + - 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 + + {%- elif archiveformat in ("gz", "zip",) %} + + archive.extracted: + - 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-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 %} + +mysql-macos-tidyup-{{ product }}: + file.absent: + - name: {{ dl.tmpdir }}/{{ archivefile }} + - onchanges: + - mysql-macos-download-{{ product }}-archive + + {% endfor %} + diff --git a/mysql/macos/remove.sls b/mysql/macos/remove.sls new file mode 100644 index 0000000..77c7c2e --- /dev/null +++ b/mysql/macos/remove.sls @@ -0,0 +1,54 @@ +### mysql/macos/remove.sls +# -*- coding: utf-8 -*- +# vim: ft=yaml +{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import mysql with context -%} + + {%- 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.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 %} + +##https://apple.stackexchange.com/questions/230333/how-could-i-remove-mysql-from-manually-installation-version +##https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x +mysql-macos-remove-entry-in-/etc/hostconfig: + file.line: + - name: /etc/hostconfig + - mode: delete + - content: MYSQLCOM=-YES- + - onlyif: test -f /etc/hostconfig + +mysql-macos-remove-mysql-fully: + file.absent: + - names: + - {{ mysql.macos.dl.tmpdir }} + - /usr/local/mysql* + - /Library/PreferencePanes/MySQL.prefPane + - /Library/StartupItems/MySQLCOM + - /Library/Receipts/mysql* + - /Library/Receipts/MySQL* + - /private/var/db/receipts/*mysql* + - /Library/LaunchDaemons/com.oracle.oss.mysql.* + diff --git a/mysql/osmap.yaml b/mysql/osmap.yaml index 29fd16f..37e7d8c 100644 --- a/mysql/osmap.yaml +++ b/mysql/osmap.yaml @@ -1,6 +1,16 @@ # vim: ft=sls # vim: sts=2 ts=2 sw=2 et ai + {% if grains.os == 'MacOS' %} +MacOS: + macos: + user: {{ salt['pillar.get']('mysql:user', salt['cmd.run']("stat -f '%Su' /dev/console")) }} + group: {{ salt['pillar.get']('mysql:group', salt['cmd.run']("stat -f '%Sg' /dev/console")) }} + {% endif %} + +Debian: + service: mysql + Ubuntu: service: mysql devpkg: libmysqlclient-dev diff --git a/mysql/server.sls b/mysql/server.sls index a559a8f..62ef0a0 100644 --- a/mysql/server.sls +++ b/mysql/server.sls @@ -156,6 +156,13 @@ mysqld: - file: mysql_server_config {% endif %} +mysql_what_is_status_of_{{ mysql.service }}: + cmd.run: + - names: + - service {{ mysql.service }} status + - onfail: + - service: mysqld + # official oracle mysql repo # creates this file, that rewrites /etc/mysql/my.cnf setting # so, make it empty diff --git a/pillar.example b/pillar.example index edde7f9..f78d3a1 100644 --- a/pillar.example +++ b/pillar.example @@ -134,3 +134,50 @@ mysql: # Install dev package - defaults to False install: False + macos: + products: + community_server: + enabled: True # default + url: https://downloads.mysql.com/archives/get/file/mysql-8.0.11-macos10.13-x86_64.dmg + sum: 'md5=602a84390ecf3d82025b1d99fc594124' + workbench: + enabled: True # default + url: https://downloads.mysql.com/archives/get/file/mysql-workbench-community-8.0.11-rc-macos-x86_64.dmg + sum: 'md5=37c5ae5bd75a4e1804ae6e0127d68611' + cluster: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-cluster-gpl-7.6.6-macos10.13-x86_64.dmg + sum: 'md5=0df975908e7d8e4e8c1003d95edf4721' + router: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-router-8.0.11-macos10.13-x86-64bit.dmg + sum: 'md5=8dd536f2f223933ecbfb8b19e54ee2f6' + utilities: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-utilities-1.6.5-macos10.12.dmg + sum: 'md5=4c8e75bb217b8293dcdeb915b649c2c8' + shell: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-shell-8.0.11-macos10.13-x86-64bit.dmg + sum: 'md5=43db4f0fc39f88c1d7be4a4f52cec363' + proxy: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-proxy-0.8.5-osx10.7-x86-32bit.tar.gz + sum: 'md5=107df22412aa8c483d2021e1af24ee22' + connnector: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-connector-nodejs-8.0.11.tar.gz + sum: 'md5=dece7fe5607918ba68499ef07c31508d' + forvisualstudio: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-for-visualstudio-2.0.4-src.zip + sum: 'md5=fcf39316505ee2921e31a431eae77a9c' + forexcel: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-for-excel-1.3.6-src.zip + sum: 'md5=2cc8b65eb72a1b07a6e4e2665e2a29e3' + notifier: + enabled: False #default + url: https://downloads.mysql.com/archives/get/file/mysql-notifier-1.1.6-src.zip + sum: 'md5=349f1994681763fd6626a8ddf6be5363' +