Miscellaneous cleanup / housekeeping (#1641)
This commit is contained in:
parent
ed6e3ebd30
commit
916ef571b9
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------------------
|
||||||
# --------------------- General Settings --------------------------------------------------------------------------------------
|
# --------------------- General Settings --------------------------------------------------------------------------------------
|
||||||
# -----------------------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -6,4 +5,3 @@
|
||||||
HOSTNAME=mail
|
HOSTNAME=mail
|
||||||
DOMAINNAME=domain.com
|
DOMAINNAME=domain.com
|
||||||
CONTAINER_NAME=mail
|
CONTAINER_NAME=mail
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,27 @@
|
||||||
|
#################################################
|
||||||
|
### General ###################################
|
||||||
|
#################################################
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
docker-compose.yml
|
|
||||||
.idea
|
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
config/opendkim/
|
||||||
|
docker-compose.yml
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
### IDEs ######################################
|
||||||
|
#################################################
|
||||||
|
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
### Tests #####################################
|
||||||
|
#################################################
|
||||||
|
|
||||||
test/config/empty/
|
test/config/empty/
|
||||||
test/config/without-accounts/
|
|
||||||
test/config/without-virtual/
|
|
||||||
test/config/with-domain/
|
|
||||||
test/config/postfix-accounts.cf
|
test/config/postfix-accounts.cf
|
||||||
test/config/letsencrypt/mail.my-domain.com/combined.pem
|
test/config/letsencrypt/mail.my-domain.com/combined.pem
|
||||||
test/onedir
|
|
||||||
config/opendkim/
|
|
||||||
test/config/dovecot-lmtp/userdb
|
test/config/dovecot-lmtp/userdb
|
||||||
test/config/key*
|
test/config/key*
|
||||||
test/config/opendkim/keys/domain.tld/
|
test/config/opendkim/keys/domain.tld/
|
||||||
|
@ -22,3 +34,7 @@ test/config/postfix-send-access.cf
|
||||||
test/config/postfix-send-access.cfe
|
test/config/postfix-send-access.cfe
|
||||||
test/config/relay-hosts/chksum
|
test/config/relay-hosts/chksum
|
||||||
test/config/relay-hosts/postfix-aliases.cf
|
test/config/relay-hosts/postfix-aliases.cf
|
||||||
|
test/config/without-accounts/
|
||||||
|
test/config/without-virtual/
|
||||||
|
test/config/with-domain/
|
||||||
|
test/onedir
|
||||||
|
|
|
@ -48,8 +48,8 @@ notifications:
|
||||||
slack:
|
slack:
|
||||||
secure: TTo1z9nbZCWcIdfPwypubNa3y+pwvfgDGlzEVAGEuK7uuIpmEoAcAUNSSPTnbewDGHnDl8t/ml93MtvP+a+IVuAKytMqF39PHyoZO7aUl9J62V+G75OmnyGjXGJm40pQosCS6LzqoRRYXotl9+fwH568Kf4ifXCrMZX1d+ir7Ww=
|
secure: TTo1z9nbZCWcIdfPwypubNa3y+pwvfgDGlzEVAGEuK7uuIpmEoAcAUNSSPTnbewDGHnDl8t/ml93MtvP+a+IVuAKytMqF39PHyoZO7aUl9J62V+G75OmnyGjXGJm40pQosCS6LzqoRRYXotl9+fwH568Kf4ifXCrMZX1d+ir7Ww=
|
||||||
webhooks:
|
webhooks:
|
||||||
urls:
|
|
||||||
- https://webhooks.gitter.im/e/7ec65291bfb4bf1f8518
|
|
||||||
on_success: always
|
on_success: always
|
||||||
on_failure: always
|
on_failure: always
|
||||||
on_start: never
|
on_start: never
|
||||||
|
urls:
|
||||||
|
- https://webhooks.gitter.im/e/7ec65291bfb4bf1f8518
|
||||||
|
|
|
@ -72,6 +72,6 @@ Community leaders will follow these Community Impact Guidelines in determining t
|
||||||
|
|
||||||
## Attribution
|
## Attribution
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at <https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>. Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). For answers to common questions about this code of conduct, see the FAQ at <https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at <https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>. Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
||||||
|
|
||||||
[homepage]: https://www.contributor-covenant.org
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
109
CONTRIBUTING.md
109
CONTRIBUTING.md
|
@ -3,7 +3,7 @@
|
||||||
`docker-mailserver` is OpenSource. That means that you can contribute on enhancements, bug fixing or improving the documentation in the Wiki.
|
`docker-mailserver` is OpenSource. That means that you can contribute on enhancements, bug fixing or improving the documentation in the Wiki.
|
||||||
|
|
||||||
1. [Issues & PRs](#issues--prs)
|
1. [Issues & PRs](#issues--prs)
|
||||||
1. [Open an Issue](#open-an-issue)
|
1. [Opening an Issue](#opening-an-issue)
|
||||||
2. [Pull Request](#pull-requests)
|
2. [Pull Request](#pull-requests)
|
||||||
2. [Coding Style](#coding-style)
|
2. [Coding Style](#coding-style)
|
||||||
1. [Bash and Shell](#bash-and-shell)
|
1. [Bash and Shell](#bash-and-shell)
|
||||||
|
@ -11,28 +11,19 @@
|
||||||
|
|
||||||
## Issues & PRs
|
## Issues & PRs
|
||||||
|
|
||||||
### Open an issue
|
### Opening an Issue
|
||||||
|
|
||||||
When opening an issue, please provide details use case to let the community reproduce your problem.
|
When opening an issue, please provide details use case to let the community reproduce your problem. Please start the mail server with env `DMS_DEBUG=1` and paste the output into the issue. **Use the issue templates** to provide the necessary information. Issues which do not use these templates are not worked on and closed.
|
||||||
Please start the mail server with env `DMS_DEBUG=1` and paste the output into the issue.
|
|
||||||
|
|
||||||
### Pull Requests
|
### Pull Requests
|
||||||
|
|
||||||
#### Project architecture
|
|
||||||
|
|
||||||
``` TXT
|
|
||||||
├── config # User: personal configurations
|
|
||||||
├── target # Developer: default server configuration, used when building the image
|
|
||||||
└── test # Developer: integration tests to check that everything keeps working
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Submit a Pull-Request
|
#### Submit a Pull-Request
|
||||||
|
|
||||||
You want to add a feature? Feel free to start creating an issue explaining what you want to do and how you're thinking doing it. Other users may have the same need and collaboration may lead to better results.
|
You want to add a feature? Feel free to start creating an issue explaining what you want to do and how you're thinking doing it. Other users may have the same need and collaboration may lead to better results.
|
||||||
|
|
||||||
The development workflow is the following:
|
The development workflow is the following:
|
||||||
|
|
||||||
- Fork project and clone your fork
|
- Fork the project and clone your fork
|
||||||
- Create a branch using `git checkout -b branch_name` (you can use `issue-xxx` if fixing an existing issue)
|
- Create a branch using `git checkout -b branch_name` (you can use `issue-xxx` if fixing an existing issue)
|
||||||
- Run `git submodule init` and `git submodule update` to get the BATS submodules
|
- Run `git submodule init` and `git submodule update` to get the BATS submodules
|
||||||
- Code :-)
|
- Code :-)
|
||||||
|
@ -53,18 +44,18 @@ The development workflow is the following:
|
||||||
|
|
||||||
When refactoring, writing or altering scripts, that is Shell and Bash scripts, in any way, adhere to these rules:
|
When refactoring, writing or altering scripts, that is Shell and Bash scripts, in any way, adhere to these rules:
|
||||||
|
|
||||||
1. **Adjust your style of coding to the style that is already present**! Even if you do not like it, this is due to consistency. Look up the GNU coding style guide. There was a lot of work involved in making these scripts consistent.
|
1. **Adjust your style of coding to the style that is already present**! Even if you do not like it, this is due to consistency. There was a lot of work involved in making all scripts consistent.
|
||||||
2. **Use `shellcheck` to check your scripts**! Your contributions are checked by TravisCI with shellcheck. You can check your scripts like Travis with `make shellcheck`.
|
2. **Use `shellcheck` to check your scripts**! Your contributions are checked by TravisCI too, so you will need to do this. You can **lint your work with `make lint`** to check against all targets.
|
||||||
3. There is a **`.editorconfig`** file. Make your IDE use it or adhere to it manually!
|
3. **Use the provided `.editorconfig`** file.
|
||||||
4. It's okay to use `/bin/bash` instead of `/bin/sh`. You can alternatively use `/usr/bin/env bash`.
|
4. Use `/bin/bash` or `/usr/bin/env bash` instead of `/bin/sh`. Adjust the style accordingly.
|
||||||
5. `setup.sh` provides a good starting point to look for.
|
5. `setup.sh` provides a good starting point to look for.
|
||||||
6. When appropriate, use the `set` builtin. We recommend `set -euEo pipefail` (very strong) or `set -uE` (weaker).
|
6. When appropriate, use the `set` builtin. We recommend `set -euEo pipefail` or `set -uE`.
|
||||||
|
|
||||||
#### Styling rules
|
#### Styling rules
|
||||||
|
|
||||||
##### Initial Description
|
##### Initial Description
|
||||||
|
|
||||||
When writing a script, provide the version and the script's task. We use [semantic versioning][semver] - so do you.
|
When writing a script, provide the version and the script's task. Please use [semantic versioning][semver].
|
||||||
|
|
||||||
``` BASH
|
``` BASH
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
@ -101,15 +92,18 @@ fi
|
||||||
|
|
||||||
##### Variables & Braces
|
##### Variables & Braces
|
||||||
|
|
||||||
Variables are always uppercase. We always use braces. If you forgot this and want to change it later, you can use [this link][regex], which points to <https://regex101.com>. The used regex is `\$([^{("\\'\/])([a-zA-Z0-9_]*)([^}\/ \t'"\n.\]:]*)`, where you should in practice be able to replace all variable occurrences without braces with occurrences with braces.
|
Variables are always uppercase. We always use braces.
|
||||||
|
|
||||||
|
If you forgot this and want to change it later, you can use [this link][regex]. The used regex is `\$([^{("\\'\/])([a-zA-Z0-9_]*)([^}\/ \t'"\n.\]:(=\\-]*)`, where you should in practice be able to replace all variable occurrences without braces with occurrences with braces.
|
||||||
|
|
||||||
``` BASH
|
``` BASH
|
||||||
# good
|
# good
|
||||||
local VAR="good"
|
local VAR="good"
|
||||||
local NEW="${VAR}"
|
local NEW="${VAR}"
|
||||||
|
|
||||||
# bad
|
# bad -> TravisCI will fail
|
||||||
var="bad"
|
var="bad"
|
||||||
|
new=$var
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Loops
|
##### Loops
|
||||||
|
@ -125,7 +119,7 @@ done
|
||||||
|
|
||||||
##### Functions
|
##### Functions
|
||||||
|
|
||||||
It's always nice to see the use of functions. Not only as it's more C-style, but it also provides a clear structure. If scripts are small, this is unnecessary, but if they become larger, please consider using functions. When doing so, provide `function _main()`. When using functions, they are **always** at the top of the script!
|
It's always nice to see the use of functions as it also provides a clear structure. If scripts are small, this is unnecessary, but if they become larger, please consider using functions. When doing so, provide `function _main`.
|
||||||
|
|
||||||
``` BASH
|
``` BASH
|
||||||
function _<name_underscored_and_lowercase>
|
function _<name_underscored_and_lowercase>
|
||||||
|
@ -139,59 +133,80 @@ function _<name_underscored_and_lowercase>
|
||||||
|
|
||||||
##### Error Tracing
|
##### Error Tracing
|
||||||
|
|
||||||
A construct to trace error in your scripts looks like this. Please use it like this (copy-paste) to make errors streamlined. Remember: Remove `set -x` in the end. This of debugging purposes only.
|
A construct to trace error in your scripts looks like this. Remember: Remove `set -x` in the end. This is for debugging purposes only.
|
||||||
|
|
||||||
``` BASH
|
``` BASH
|
||||||
set -euxEo pipefail
|
set -euEo pipefail
|
||||||
trap '_report_err $_ $LINENO $?' ERR
|
trap '__log_err ${FUNCNAME[0]:-"?"} ${_:-"?"} ${LINENO:-"?"} ${?:-"?"}' ERR
|
||||||
|
|
||||||
function _report_err()
|
function __log_err
|
||||||
{
|
{
|
||||||
echo "ERROR occurred :: source (hint) $1 ; line $2 ; exit code $3 ;;" >&2
|
local FUNC_NAME LINE EXIT_CODE
|
||||||
|
FUNC_NAME="${1} / ${2}"
|
||||||
|
LINE="${3}"
|
||||||
|
EXIT_CODE="${4}"
|
||||||
|
|
||||||
|
printf "\n––– \e[1m\e[31mUNCHECKED ERROR\e[0m\n%s\n%s\n%s\n%s\n\n" \
|
||||||
|
" – script = ${SCRIPT,,}.sh" \
|
||||||
|
" – function = ${FUNC_NAME}" \
|
||||||
|
" – line = ${LINE}" \
|
||||||
|
" – exit code = ${EXIT_CODE}"
|
||||||
|
|
||||||
<CODE TO RUN AFTERWARDS>
|
<CODE TO RUN AFTERWARDS>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Comments and Descriptiveness
|
##### Comments, Descriptiveness & An Example
|
||||||
|
|
||||||
Comments should only describe non-obvious matters. Comments should start lowercase when they aren't sentences. Make the code **self-descriptive** by using meaningful names! Make comments not longer than approximately 80 columns, then wrap the line.
|
Comments should only describe non-obvious matters. Comments should start lowercase when they aren't sentences. Make the code **self-descriptive** by using meaningful names! Make comments not longer than approximately 80 columns, then wrap the line.
|
||||||
|
|
||||||
A positive example:
|
A positive example, which is taken from `start-mailserver.sh`, would be
|
||||||
|
|
||||||
``` BASH
|
``` BASH
|
||||||
# writes result to stdout
|
function _setup_postfix_aliases
|
||||||
function _add_one()
|
|
||||||
{
|
{
|
||||||
echo $(( $1 + 1 ))
|
_notify 'task' 'Setting up Postfix Aliases'
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
A negative example:
|
: >/etc/postfix/virtual
|
||||||
|
: >/etc/postfix/regexp
|
||||||
|
|
||||||
``` BASH
|
if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]]
|
||||||
# adds one to the first argument and print it to stdout
|
then
|
||||||
function _add_one()
|
# fixing old virtual user file
|
||||||
{
|
if grep -q ",$" /tmp/docker-mailserver/postfix-virtual.cf
|
||||||
# save the first variable
|
then
|
||||||
local FIRST=$1
|
sed -i -e "s/, /,/g" -e "s/,$//g" /tmp/docker-mailserver/postfix-virtual.cf
|
||||||
|
fi
|
||||||
|
|
||||||
# add one here
|
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual
|
||||||
local RESULT=$(( FIRST + 1 ))
|
|
||||||
|
|
||||||
# print it to stdout
|
# the `to` is important, don't delete it
|
||||||
echo "$_RESULT"
|
# shellcheck disable=SC2034
|
||||||
|
while read -r FROM TO
|
||||||
|
do
|
||||||
|
# Setting variables for better readability
|
||||||
|
UNAME=$(echo "${FROM}" | cut -d @ -f1)
|
||||||
|
DOMAIN=$(echo "${FROM}" | cut -d @ -f2)
|
||||||
|
|
||||||
|
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
||||||
|
[ "${UNAME}" != "${DOMAIN}" ] && echo "${DOMAIN}" >> /tmp/vhost.tmp
|
||||||
|
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true)
|
||||||
|
else
|
||||||
|
_notify 'inf' "Warning 'config/postfix-virtual.cf' is not provided. No mail alias/forward created."
|
||||||
|
fi
|
||||||
|
|
||||||
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### YAML
|
### YAML
|
||||||
|
|
||||||
When formatting YAML files, you can opt for [Prettier][prettier]. There are many plugins for IDEs around.
|
When formatting YAML files, use [Prettier][prettier], an opinionated formatter. There are many plugins for IDEs around.
|
||||||
|
|
||||||
[//]: # (Links)
|
[//]: # (Links)
|
||||||
|
|
||||||
[commit]: https://help.github.com/articles/closing-issues-via-commit-messages/
|
[commit]: https://help.github.com/articles/closing-issues-via-commit-messages/
|
||||||
[gpg]: https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key
|
[gpg]: https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key
|
||||||
[semver]: https://semver.org/
|
[semver]: https://semver.org/
|
||||||
[regex]: https://regex101.com/r/ikzJpF/5
|
[regex]: https://regex101.com/r/ikzJpF/7
|
||||||
[prettier]: https://prettier.io
|
[prettier]: https://prettier.io
|
||||||
|
|
29
README.md
29
README.md
|
@ -36,13 +36,13 @@ Why I created this image: [Simple Mail Server with Docker](http://tvi.al/simple-
|
||||||
- Dovecot was downgraded
|
- Dovecot was downgraded
|
||||||
2. ELK was removed
|
2. ELK was removed
|
||||||
3. New contributing guidelines were added
|
3. New contributing guidelines were added
|
||||||
4. Added option to use non-default network interface
|
4. Added coherent coding style and linting
|
||||||
|
5. Added option to use non-default network interface
|
||||||
|
|
||||||
## Includes
|
## Includes
|
||||||
|
|
||||||
- [Postfix](http://www.postfix.org) with SMTP or LDAP auth
|
- [Postfix](http://www.postfix.org) with SMTP or LDAP auth
|
||||||
- [Dovecot](https://www.dovecot.org) for SASL, IMAP (and optional POP3) with ssl support, with ldap auth, sieve and [quotas](https://github.com/tomav/docker-mailserver/wiki/Configure-Accounts#mailbox-quota)
|
- [Dovecot](https://www.dovecot.org) for SASL, IMAP (and optional POP3) with SSL support, with LDAP auth, Sieve and [quotas](https://github.com/tomav/docker-mailserver/wiki/Configure-Accounts#mailbox-quota)
|
||||||
- SASLauthd with LDAP auth
|
|
||||||
- [Amavis](https://www.amavis.org/)
|
- [Amavis](https://www.amavis.org/)
|
||||||
- [Spamassasin](http://spamassassin.apache.org/) supporting custom rules
|
- [Spamassasin](http://spamassassin.apache.org/) supporting custom rules
|
||||||
- [ClamAV](https://www.clamav.net/) with automatic updates
|
- [ClamAV](https://www.clamav.net/) with automatic updates
|
||||||
|
@ -52,9 +52,10 @@ Why I created this image: [Simple Mail Server with Docker](http://tvi.al/simple-
|
||||||
- [Fetchmail](http://www.fetchmail.info/fetchmail-man.html)
|
- [Fetchmail](http://www.fetchmail.info/fetchmail-man.html)
|
||||||
- [Postscreen](http://www.postfix.org/POSTSCREEN_README.html)
|
- [Postscreen](http://www.postfix.org/POSTSCREEN_README.html)
|
||||||
- [Postgrey](https://postgrey.schweikert.ch/)
|
- [Postgrey](https://postgrey.schweikert.ch/)
|
||||||
- basic [Sieve support](https://github.com/tomav/docker-mailserver/wiki/Configure-Sieve-filters) using dovecot
|
|
||||||
- [LetsEncrypt](https://letsencrypt.org/) and self-signed certificates
|
- [LetsEncrypt](https://letsencrypt.org/) and self-signed certificates
|
||||||
- [Setup script](https://github.com/tomav/docker-mailserver/wiki/Setup-docker-mailserver-using-the-script-setup.sh) to easily configure and maintain your mailserver
|
- [Setup script](https://github.com/tomav/docker-mailserver/wiki/Setup-docker-mailserver-using-the-script-setup.sh) to easily configure and maintain your mailserver
|
||||||
|
- basic [Sieve support](https://github.com/tomav/docker-mailserver/wiki/Configure-Sieve-filters) using dovecot
|
||||||
|
- SASLauthd with LDAP auth
|
||||||
- persistent data and state (but think about backups!)
|
- persistent data and state (but think about backups!)
|
||||||
- [Integration tests](https://travis-ci.org/tomav/docker-mailserver)
|
- [Integration tests](https://travis-ci.org/tomav/docker-mailserver)
|
||||||
- [Automated builds on docker hub](https://hub.docker.com/r/tvial/docker-mailserver/)
|
- [Automated builds on docker hub](https://hub.docker.com/r/tvial/docker-mailserver/)
|
||||||
|
@ -63,7 +64,9 @@ Why I created this image: [Simple Mail Server with Docker](http://tvi.al/simple-
|
||||||
|
|
||||||
## Issues & Contributing
|
## Issues & Contributing
|
||||||
|
|
||||||
Before you open an issue, please have a look this `README`, the [Wiki](https://github.com/tomav/docker-mailserver/wiki/) and Postfix/Dovecot documentation. If you'd like to contribute, read [`CONTRIBUTING.md`](./CONTRIBUTING.md) thoroughly.
|
Before opening an issue, please have a look this `README`, the [Wiki](https://github.com/tomav/docker-mailserver/wiki/) and the Postfix/Dovecot documentation.
|
||||||
|
|
||||||
|
If you'd like to contribute, read [`CONTRIBUTING.md`](./CONTRIBUTING.md) thoroughly.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
@ -84,31 +87,27 @@ Minimum:
|
||||||
|
|
||||||
### Get the tools
|
### Get the tools
|
||||||
|
|
||||||
Download the docker-compose.yml, the .env and the setup.sh files:
|
Download the `docker-compose.yml`, `.env`, `env-mailserver` and the `setup.sh` files:
|
||||||
|
|
||||||
``` BASH
|
``` BASH
|
||||||
curl -o setup.sh https://raw.githubusercontent.com/tomav/docker-mailserver/master/setup.sh; chmod a+x ./setup.sh
|
curl -o setup.sh https://raw.githubusercontent.com/tomav/docker-mailserver/master/setup.sh && chmod a+x ./setup.sh
|
||||||
|
|
||||||
curl -o docker-compose.yml https://raw.githubusercontent.com/tomav/docker-mailserver/master/docker-compose.yml.dist
|
curl -o docker-compose.yml https://raw.githubusercontent.com/tomav/docker-mailserver/master/docker-compose.yml.dist
|
||||||
|
|
||||||
curl -o .env https://raw.githubusercontent.com/tomav/docker-mailserver/master/.env.dist
|
curl -o .env https://raw.githubusercontent.com/tomav/docker-mailserver/master/.env.dist
|
||||||
|
|
||||||
curl -o env-mailserver https://raw.githubusercontent.com/tomav/docker-mailserver/master/env-mailserver.dist
|
curl -o env-mailserver https://raw.githubusercontent.com/tomav/docker-mailserver/master/env-mailserver.dist
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create a docker-compose environment
|
### Create a docker-compose environment
|
||||||
|
|
||||||
|
- [Install the latest docker-compose](https://docs.docker.com/compose/install/)
|
||||||
- Edit the files `.env` and `env-mailserver` to your liking:
|
- Edit the files `.env` and `env-mailserver` to your liking:
|
||||||
- `.env` contains the configuration for docker-compose
|
- `.env` contains the configuration for docker-compose
|
||||||
- `env-mailserver` contains the configuration for the mailserver container
|
- `env-mailserver` contains the configuration for the mailserver container
|
||||||
- These files supports only simple `VAR=VAL` lines (see [Documentation](https://docs.docker.com/compose/env-file/)).
|
- These files supports only simple `VAR=VAL` lines (see [Documentation](https://docs.docker.com/compose/env-file/)).
|
||||||
- Don't quote your values.
|
- Don't quote your values.
|
||||||
- Variable substitution is *not* supported (e.g. `OVERRIDE_HOSTNAME=$HOSTNAME.$DOMAINNAME`).
|
- Variable substitution is *not* supported (e.g. `OVERRIDE_HOSTNAME=$HOSTNAME.$DOMAINNAME`).
|
||||||
- [Install the latest docker-compose](https://docs.docker.com/compose/install/)
|
|
||||||
|
|
||||||
**Note:**: Variables in `.env` are expanded in the `docker-compose.yml` file **only** and **not** in the container. The file `env-mailserver` serves this case where environment variables are used in the container.
|
**Note:**: Variables in `.env` are expanded in the `docker-compose.yml` file **only** and **not** in the container. The file `env-mailserver` serves this case where environment variables are used in the container.
|
||||||
|
|
||||||
|
|
||||||
**Note:** If you want to use a bare domain (host name equals domain name) see [FAQ](https://github.com/tomav/docker-mailserver/wiki/FAQ-and-Tips#can-i-use-nakedbare-domains-no-host-name).
|
**Note:** If you want to use a bare domain (host name equals domain name) see [FAQ](https://github.com/tomav/docker-mailserver/wiki/FAQ-and-Tips#can-i-use-nakedbare-domains-no-host-name).
|
||||||
|
|
||||||
### Get up and running
|
### Get up and running
|
||||||
|
@ -119,7 +118,7 @@ docker-compose up -d mail
|
||||||
./setup.sh config dkim
|
./setup.sh config dkim
|
||||||
```
|
```
|
||||||
|
|
||||||
Now the keys are generated, you can configure your DNS server by just pasting the content of `config/opendkim/keys/domain.tld/mail.txt` in your `domain.tld.hosts` zone.
|
Now that the keys are generated, you can configure your DNS server by just pasting the content of `config/opendkim/keys/domain.tld/mail.txt` in your `domain.tld.hosts` zone.
|
||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
|
@ -131,9 +130,7 @@ docker pull tvial/docker-mailserver:latest
|
||||||
docker-compose up -d mail
|
docker-compose up -d mail
|
||||||
```
|
```
|
||||||
|
|
||||||
You're done!
|
You're done! And don't forget to have a look at the remaining functions of the `setup.sh` script with `./setup.sh -h`.
|
||||||
|
|
||||||
And don't forget to have a look at the remaining functions of the `setup.sh` script
|
|
||||||
|
|
||||||
#### SPF/Forwarding Problems
|
#### SPF/Forwarding Problems
|
||||||
|
|
||||||
|
|
13
setup.sh
13
setup.sh
|
@ -100,7 +100,7 @@ function _inspect
|
||||||
|
|
||||||
function _usage
|
function _usage
|
||||||
{
|
{
|
||||||
echo "${SCRIPT,,}.sh
|
echo "${SCRIPT,,}.sh Bootstrapping Script
|
||||||
|
|
||||||
Usage: ${0} [-i IMAGE_NAME] [-c CONTAINER_NAME] <subcommand> <subcommand> [args]
|
Usage: ${0} [-i IMAGE_NAME] [-c CONTAINER_NAME] <subcommand> <subcommand> [args]
|
||||||
|
|
||||||
|
@ -112,7 +112,9 @@ OPTIONS:
|
||||||
|
|
||||||
-c CONTAINER_NAME The name of the running container.
|
-c CONTAINER_NAME The name of the running container.
|
||||||
|
|
||||||
-p PATH config folder path (default: ${CDIR}/config)
|
-p PATH Config folder path (default: ${CDIR}/config)
|
||||||
|
|
||||||
|
-h Show this help dialogue
|
||||||
|
|
||||||
SUBCOMMANDS:
|
SUBCOMMANDS:
|
||||||
|
|
||||||
|
@ -152,6 +154,8 @@ SUBCOMMANDS:
|
||||||
${0} debug inspect
|
${0} debug inspect
|
||||||
${0} debug login <commands>
|
${0} debug login <commands>
|
||||||
|
|
||||||
|
help: Show this help dialogue
|
||||||
|
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +240,7 @@ function _main
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local OPTIND
|
local OPTIND
|
||||||
while getopts ":c:i:p:" OPT
|
while getopts ":c:i:p:h" OPT
|
||||||
do
|
do
|
||||||
case ${OPT} in
|
case ${OPT} in
|
||||||
c) CONTAINER_NAME="${OPTARG}" ; USE_CONTAINER=true ;; # container specified, connect to running instance
|
c) CONTAINER_NAME="${OPTARG}" ; USE_CONTAINER=true ;; # container specified, connect to running instance
|
||||||
|
@ -254,6 +258,7 @@ function _main
|
||||||
exit 40
|
exit 40
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
h) _usage ; return ;;
|
||||||
*) echo "Invalid option: -${OPTARG}" >&2 ;;
|
*) echo "Invalid option: -${OPTARG}" >&2 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -339,6 +344,8 @@ function _main
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
help) _usage ;;
|
||||||
|
|
||||||
* ) _usage ; _unset_vars ; exit 1 ;;
|
* ) _usage ; _unset_vars ; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
|
@ -93,8 +93,8 @@ do
|
||||||
postalias /etc/aliases
|
postalias /etc/aliases
|
||||||
|
|
||||||
# regenerate postfix accounts
|
# regenerate postfix accounts
|
||||||
echo -n >/etc/postfix/vmailbox
|
: >/etc/postfix/vmailbox
|
||||||
echo -n >/etc/dovecot/userdb
|
: >/etc/dovecot/userdb
|
||||||
|
|
||||||
if [[ -f /tmp/docker-mailserver/postfix-accounts.cf ]] && [[ ${ENABLE_LDAP} -ne 1 ]]
|
if [[ -f /tmp/docker-mailserver/postfix-accounts.cf ]] && [[ ${ENABLE_LDAP} -ne 1 ]]
|
||||||
then
|
then
|
||||||
|
@ -113,7 +113,7 @@ do
|
||||||
if [[ -n ${RELAY_HOST} ]]
|
if [[ -n ${RELAY_HOST} ]]
|
||||||
then
|
then
|
||||||
# keep old config
|
# keep old config
|
||||||
echo -n >/etc/postfix/sasl_passwd
|
: >/etc/postfix/sasl_passwd
|
||||||
if [[ -n ${SASL_PASSWD} ]]
|
if [[ -n ${SASL_PASSWD} ]]
|
||||||
then
|
then
|
||||||
echo "${SASL_PASSWD}" >>/etc/postfix/sasl_passwd
|
echo "${SASL_PASSWD}" >>/etc/postfix/sasl_passwd
|
||||||
|
@ -122,13 +122,13 @@ do
|
||||||
# add domain-specific auth from config file
|
# add domain-specific auth from config file
|
||||||
if [[ -f /tmp/docker-mailserver/postfix-sasl-password.cf ]]
|
if [[ -f /tmp/docker-mailserver/postfix-sasl-password.cf ]]
|
||||||
then
|
then
|
||||||
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-sasl-password.cf || true) | while read -r LINE
|
while read -r LINE
|
||||||
do
|
do
|
||||||
if ! echo "${LINE}" | grep -q -e "\s*#"
|
if ! echo "${LINE}" | grep -q -e "\s*#"
|
||||||
then
|
then
|
||||||
echo "${LINE}" >>/etc/postfix/sasl_passwd
|
echo "${LINE}" >>/etc/postfix/sasl_passwd
|
||||||
fi
|
fi
|
||||||
done
|
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-sasl-password.cf || true)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# add default relay
|
# add default relay
|
||||||
|
@ -140,7 +140,7 @@ do
|
||||||
|
|
||||||
# creating users ; 'pass' is encrypted
|
# creating users ; 'pass' is encrypted
|
||||||
# comments and empty lines are ignored
|
# comments and empty lines are ignored
|
||||||
grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-accounts.cf | while IFS=$'|' read -r LOGIN PASS
|
while IFS=$'|' read -r LOGIN PASS
|
||||||
do
|
do
|
||||||
USER=$(echo "${LOGIN}" | cut -d @ -f1)
|
USER=$(echo "${LOGIN}" | cut -d @ -f1)
|
||||||
DOMAIN=$(echo "${LOGIN}" | cut -d @ -f2)
|
DOMAIN=$(echo "${LOGIN}" | cut -d @ -f2)
|
||||||
|
@ -171,7 +171,7 @@ do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${DOMAIN}" >>/tmp/vhost.tmp
|
echo "${DOMAIN}" >>/tmp/vhost.tmp
|
||||||
done
|
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-accounts.cf)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n ${RELAY_HOST} ]] && _populate_relayhost_map
|
[[ -n ${RELAY_HOST} ]] && _populate_relayhost_map
|
||||||
|
@ -186,8 +186,8 @@ do
|
||||||
if [[ -f postfix-virtual.cf ]]
|
if [[ -f postfix-virtual.cf ]]
|
||||||
then
|
then
|
||||||
# regenerate postfix aliases
|
# regenerate postfix aliases
|
||||||
echo -n >/etc/postfix/virtual
|
: >/etc/postfix/virtual
|
||||||
echo -n >/etc/postfix/regexp
|
: >/etc/postfix/regexp
|
||||||
|
|
||||||
if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]]
|
if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]]
|
||||||
then
|
then
|
||||||
|
@ -195,14 +195,14 @@ do
|
||||||
|
|
||||||
# the `to` seems to be important; don't delete it
|
# the `to` seems to be important; don't delete it
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true) | while read -r FROM TO
|
while read -r FROM TO
|
||||||
do
|
do
|
||||||
UNAME=$(echo "${FROM}" | cut -d @ -f1)
|
UNAME=$(echo "${FROM}" | cut -d @ -f1)
|
||||||
DOMAIN=$(echo "${FROM}" | cut -d @ -f2)
|
DOMAIN=$(echo "${FROM}" | cut -d @ -f2)
|
||||||
|
|
||||||
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
||||||
[ "${UNAME}" != "${DOMAIN}" ] && echo "${DOMAIN}" >>/tmp/vhost.tmp
|
[ "${UNAME}" != "${DOMAIN}" ] && echo "${DOMAIN}" >>/tmp/vhost.tmp
|
||||||
done
|
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f /tmp/docker-mailserver/postfix-regexp.cf ]]
|
if [[ -f /tmp/docker-mailserver/postfix-regexp.cf ]]
|
||||||
|
|
|
@ -159,7 +159,7 @@ export -f _notify
|
||||||
# @domain3.com [smtp.mailgun.org]:587
|
# @domain3.com [smtp.mailgun.org]:587
|
||||||
function _populate_relayhost_map
|
function _populate_relayhost_map
|
||||||
{
|
{
|
||||||
echo -n > /etc/postfix/relayhost_map
|
: >/etc/postfix/relayhost_map
|
||||||
chown root:root /etc/postfix/relayhost_map
|
chown root:root /etc/postfix/relayhost_map
|
||||||
chmod 0600 /etc/postfix/relayhost_map
|
chmod 0600 /etc/postfix/relayhost_map
|
||||||
|
|
||||||
|
|
|
@ -640,7 +640,7 @@ function _setup_dovecot_quota
|
||||||
if [[ ! -f /tmp/docker-mailserver/dovecot-quotas.cf ]]
|
if [[ ! -f /tmp/docker-mailserver/dovecot-quotas.cf ]]
|
||||||
then
|
then
|
||||||
_notify 'inf' "'config/docker-mailserver/dovecot-quotas.cf' is not provided. Using default quotas."
|
_notify 'inf' "'config/docker-mailserver/dovecot-quotas.cf' is not provided. Using default quotas."
|
||||||
echo -n >/tmp/docker-mailserver/dovecot-quotas.cf
|
: >/tmp/docker-mailserver/dovecot-quotas.cf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# enable quota policy check in postfix
|
# enable quota policy check in postfix
|
||||||
|
@ -651,8 +651,8 @@ function _setup_dovecot_quota
|
||||||
function _setup_dovecot_local_user
|
function _setup_dovecot_local_user
|
||||||
{
|
{
|
||||||
_notify 'task' 'Setting up Dovecot Local User'
|
_notify 'task' 'Setting up Dovecot Local User'
|
||||||
echo -n > /etc/postfix/vmailbox
|
: >/etc/postfix/vmailbox
|
||||||
echo -n > /etc/dovecot/userdb
|
: >/etc/dovecot/userdb
|
||||||
|
|
||||||
if [[ -f /tmp/docker-mailserver/postfix-accounts.cf ]] && [[ ${ENABLE_LDAP} -ne 1 ]]
|
if [[ -f /tmp/docker-mailserver/postfix-accounts.cf ]] && [[ ${ENABLE_LDAP} -ne 1 ]]
|
||||||
then
|
then
|
||||||
|
@ -674,7 +674,7 @@ function _setup_dovecot_local_user
|
||||||
|
|
||||||
# creating users ; 'pass' is encrypted
|
# creating users ; 'pass' is encrypted
|
||||||
# comments and empty lines are ignored
|
# comments and empty lines are ignored
|
||||||
grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-accounts.cf | while IFS=$'|' read -r LOGIN PASS
|
while IFS=$'|' read -r LOGIN PASS
|
||||||
do
|
do
|
||||||
# Setting variables for better readability
|
# Setting variables for better readability
|
||||||
USER=$(echo "${LOGIN}" | cut -d @ -f1)
|
USER=$(echo "${LOGIN}" | cut -d @ -f1)
|
||||||
|
@ -709,7 +709,7 @@ function _setup_dovecot_local_user
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${DOMAIN}" >> /tmp/vhost.tmp
|
echo "${DOMAIN}" >> /tmp/vhost.tmp
|
||||||
done
|
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-accounts.cf)
|
||||||
else
|
else
|
||||||
_notify 'inf' "'config/docker-mailserver/postfix-accounts.cf' is not provided. No mail account created."
|
_notify 'inf' "'config/docker-mailserver/postfix-accounts.cf' is not provided. No mail account created."
|
||||||
fi
|
fi
|
||||||
|
@ -776,7 +776,7 @@ function _setup_ldap
|
||||||
|
|
||||||
configomat.sh "DOVECOT_" "/etc/dovecot/dovecot-ldap.conf.ext"
|
configomat.sh "DOVECOT_" "/etc/dovecot/dovecot-ldap.conf.ext"
|
||||||
|
|
||||||
# add domainname to vhost
|
# add domainname to vhost
|
||||||
echo "${DOMAINNAME}" >>/tmp/vhost.tmp
|
echo "${DOMAINNAME}" >>/tmp/vhost.tmp
|
||||||
|
|
||||||
_notify 'inf' "Enabling dovecot LDAP authentification"
|
_notify 'inf' "Enabling dovecot LDAP authentification"
|
||||||
|
@ -961,8 +961,8 @@ function _setup_postfix_aliases
|
||||||
{
|
{
|
||||||
_notify 'task' 'Setting up Postfix Aliases'
|
_notify 'task' 'Setting up Postfix Aliases'
|
||||||
|
|
||||||
echo -n > /etc/postfix/virtual
|
: >/etc/postfix/virtual
|
||||||
echo -n > /etc/postfix/regexp
|
: >/etc/postfix/regexp
|
||||||
|
|
||||||
if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]]
|
if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]]
|
||||||
then
|
then
|
||||||
|
@ -976,15 +976,14 @@ function _setup_postfix_aliases
|
||||||
|
|
||||||
# the `to` is important, don't delete it
|
# the `to` is important, don't delete it
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true) | while read -r FROM TO
|
while read -r FROM TO
|
||||||
do
|
do
|
||||||
# Setting variables for better readability
|
|
||||||
UNAME=$(echo "${FROM}" | cut -d @ -f1)
|
UNAME=$(echo "${FROM}" | cut -d @ -f1)
|
||||||
DOMAIN=$(echo "${FROM}" | cut -d @ -f2)
|
DOMAIN=$(echo "${FROM}" | cut -d @ -f2)
|
||||||
|
|
||||||
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
||||||
[ "${UNAME}" != "${DOMAIN}" ] && echo "${DOMAIN}" >> /tmp/vhost.tmp
|
[ "${UNAME}" != "${DOMAIN}" ] && echo "${DOMAIN}" >> /tmp/vhost.tmp
|
||||||
done
|
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true)
|
||||||
else
|
else
|
||||||
_notify 'inf' "Warning 'config/postfix-virtual.cf' is not provided. No mail alias/forward created."
|
_notify 'inf' "Warning 'config/postfix-virtual.cf' is not provided. No mail alias/forward created."
|
||||||
fi
|
fi
|
||||||
|
@ -1009,7 +1008,7 @@ s/$/ pcre:\/etc\/postfix\/regexp/
|
||||||
cat /tmp/docker-mailserver/postfix-aliases.cf >> /etc/aliases
|
cat /tmp/docker-mailserver/postfix-aliases.cf >> /etc/aliases
|
||||||
else
|
else
|
||||||
_notify 'inf' "'config/postfix-aliases.cf' is not provided and will be auto created."
|
_notify 'inf' "'config/postfix-aliases.cf' is not provided and will be auto created."
|
||||||
echo -n >/tmp/docker-mailserver/postfix-aliases.cf
|
: >/tmp/docker-mailserver/postfix-aliases.cf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
postalias /etc/aliases
|
postalias /etc/aliases
|
||||||
|
|
Loading…
Reference in New Issue