diff --git a/README.rst b/README.rst index 111bf104bb73037f6de2087a8d9601064485556e..d1e4f88cd84d45253e3cb260eb78babc5a656f16 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 any other enabled products on MacOS. + +``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 d1899047a9d63563567e034571b272af25f956e1..807c17ba27a63c953b36ecae7fd56b6765d64eed 100644 --- a/mysql/defaults.yaml +++ b/mysql/defaults.yaml @@ -21,6 +21,74 @@ mysql: port: 3306 datadir: /var/lib/mysql + macos: + userhomes: /Users + user: + group: + dl: + tmpdir: /tmp/mysqltmp + bindir: /usr/local/bin + 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' + dest: /Applications/MySQL.app + isapp: False + 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 + 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 + 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 + 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 + 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 + 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: {} clients: {} diff --git a/mysql/macos/init.sls b/mysql/macos/init.sls new file mode 100644 index 0000000000000000000000000000000000000000..dbe2ee1baec7f84f10746e89cb19b17ef81fa139 --- /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 0000000000000000000000000000000000000000..8f1e163f9194d113946fce9e82cb4fd3f613a999 --- /dev/null +++ b/mysql/macos/install.sls @@ -0,0 +1,85 @@ +### 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 data.enabled %} + {%- set archivename = data.url.split('/')[-1]|quote %} + {%- set archiveformat = archivename.split('.')[-1] %} + +mysql-macos-remove-previous-{{ product }}-download-archive: + file.absent: + - name: {{ dl.tmpdir }}/{{ archivename }} + - 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 }}/{{ archivename }} {{ 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 }}/{{ archivename }} + - 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 }}/{{ archivename }}" + - 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',) %} + archive.extracted: + - source: file://{{ dl.tmpdir }}{{ archivename }} + - name: {{ dl.bindir }} + - trim_output: True + - source_hash: {{ data.sum }} + - onchanges: + - mysql-macos-download-{{ product }}-archive + - require_in: + - mysql-macos-remove-{{ product }}-archive + + {%- endif %} + +mysql-macos-remove-{{ product }}-archive: + file.absent: + - name: {{ dl.tmpdir }}/{{ archivename }} + - onchanges: + - mysql-macos-download-{{ product }}-archive + + {%- endfor %} + diff --git a/mysql/macos/remove.sls b/mysql/macos/remove.sls new file mode 100644 index 0000000000000000000000000000000000000000..30fcb5363da285de98cfb498dc0a6e537e4cf62e --- /dev/null +++ b/mysql/macos/remove.sls @@ -0,0 +1,36 @@ +### mysql/macos/remove.sls +# -*- coding: utf-8 -*- +# 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] %} + +mysql-macos-{{ product }}-remove-destdir: + file.absent: + - names: + - {{ data.dest }} + + {%- 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 29fd16f46be957b1acf1cc4ffb2d0f50167650c9..37e7d8c133d29f42c23b73f7c74a68baff009de2 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 a559a8f7b5dc8da561981ae10e93b72e7ff548b6..62ef0a0bc63e2a89bf734835f80b7909f027d6bd 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 edde7f9eb21b48681dd18e5d52fbfaebdb514110..f78d3a149aafef545086e50ec04c5736f8d90e3b 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' +