--- /dev/null
+#!/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
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