From: Cloud User Date: Thu, 1 Dec 2016 01:36:28 +0000 (+0000) Subject: Add a setup step to Dovecot which grants permission to the postfix database to the... X-Git-Url: http://id.pley.net/postfix.git/commitdiff_plain/09fd1a8ed2f80a6d1349f83650c35dd0eef05c0d?ds=sidebyside Add a setup step to Dovecot which grants permission to the postfix database to the Dovecot user. --- diff --git a/dovecot/Makefile b/dovecot/Makefile index 495f587..e57b6d1 100644 --- a/dovecot/Makefile +++ b/dovecot/Makefile @@ -4,8 +4,13 @@ INPUTS := dovecot-sql.conf.ext local.conf OUTPUTS := $(INPUTS:%=$(DST)/%) -all: $(OUTPUTS) +all: $(OUTPUTS) setup + +.PHONY: setup $(DST)/%: % @mkdir -p $(@D) cp $^ $@ + +setup: + @./setup-dovecot.sh diff --git a/dovecot/setup-dovecot.sh b/dovecot/setup-dovecot.sh new file mode 100755 index 0000000..7171f19 --- /dev/null +++ b/dovecot/setup-dovecot.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if [[ -z "$( mysql -u root -e 'SELECT User FROM mysql.user WHERE User = "dovecot"' )" ]]; then + echo Creating \"dovecot\" user. + mysql -u root -e 'CREATE USER "dovecot"@"localhost" IDENTIFIED BY "dovecot"' + if [[ -n "$( mysql -u root -e 'SHOW DATABASES LIKE "postfix"' )" ]]; then + mysql -u root -e 'GRANT ALL PRIVILEGES ON dovecot.* TO "dovecot"@"localhost"' + mysql -u root -e 'FLUSH PRIVILEGES' + fi +fi diff --git a/postfixadmin/setup-postfixadmin.sh b/postfixadmin/setup-postfixadmin.sh index b19e9e2..11630e0 100755 --- a/postfixadmin/setup-postfixadmin.sh +++ b/postfixadmin/setup-postfixadmin.sh @@ -9,6 +9,9 @@ if [[ -z "$( mysql -u root -e 'SHOW DATABASES LIKE "postfix"' )" ]]; then echo Creating \"postfix\" database. mysql -u root -e 'CREATE DATABASE postfix' mysql -u root -e 'GRANT ALL PRIVILEGES ON postfix.* TO "postfix"@"localhost"' + if [[ -n "$( mysql -u root -e 'SELECT User FROM mysql.user WHERE User = "dovecot"' )" ]]; then + mysql -u root -e 'GRANT ALL PRIVILEGES ON postfix.* TO "dovecot"@"localhost"' + fi mysql -u root -e 'FLUSH PRIVILEGES' fi