diff --git a/.env.dist b/.env.dist index 63563283..b934fb7a 100644 --- a/.env.dist +++ b/.env.dist @@ -1,4 +1,3 @@ - # ----------------------------------------------------------------------------------------------------------------------------- # --------------------- General Settings -------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------- @@ -6,4 +5,3 @@ HOSTNAME=mail DOMAINNAME=domain.com CONTAINER_NAME=mail - diff --git a/.gitignore b/.gitignore index 283c319b..e4031321 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,27 @@ +################################################# +### General ################################### +################################################# + .DS_Store -docker-compose.yml -.idea .env + +config/opendkim/ +docker-compose.yml + +################################################# +### IDEs ###################################### +################################################# + +.idea +.vscode + +################################################# +### Tests ##################################### +################################################# + test/config/empty/ -test/config/without-accounts/ -test/config/without-virtual/ -test/config/with-domain/ test/config/postfix-accounts.cf test/config/letsencrypt/mail.my-domain.com/combined.pem -test/onedir -config/opendkim/ test/config/dovecot-lmtp/userdb test/config/key* test/config/opendkim/keys/domain.tld/ @@ -22,3 +34,7 @@ test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf +test/config/without-accounts/ +test/config/without-virtual/ +test/config/with-domain/ +test/onedir diff --git a/.travis.yml b/.travis.yml index 9190cd23..7faa4755 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,8 +48,8 @@ notifications: slack: secure: TTo1z9nbZCWcIdfPwypubNa3y+pwvfgDGlzEVAGEuK7uuIpmEoAcAUNSSPTnbewDGHnDl8t/ml93MtvP+a+IVuAKytMqF39PHyoZO7aUl9J62V+G75OmnyGjXGJm40pQosCS6LzqoRRYXotl9+fwH568Kf4ifXCrMZX1d+ir7Ww= webhooks: - urls: - - https://webhooks.gitter.im/e/7ec65291bfb4bf1f8518 on_success: always on_failure: always on_start: never + urls: + - https://webhooks.gitter.im/e/7ec65291bfb4bf1f8518 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index d35bcdbd..744a2d2c 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -72,6 +72,6 @@ Community leaders will follow these Community Impact Guidelines in determining t ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at . 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 . Translations are available at . +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at . Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). [homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64e83700..2566943b 100644 --- a/CONTRIBUTING.md +++ b/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. 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. [Coding Style](#coding-style) 1. [Bash and Shell](#bash-and-shell) @@ -11,28 +11,19 @@ ## Issues & PRs -### Open an issue +### Opening an Issue -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. +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. ### 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 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: -- 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) - Run `git submodule init` and `git submodule update` to get the BATS submodules - 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: -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. -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`. -3. There is a **`.editorconfig`** file. Make your IDE use it or adhere to it manually! -4. It's okay to use `/bin/bash` instead of `/bin/sh`. You can alternatively use `/usr/bin/env bash`. +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 too, so you will need to do this. You can **lint your work with `make lint`** to check against all targets. +3. **Use the provided `.editorconfig`** file. +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. -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 ##### 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 #!/usr/bin/env bash @@ -101,15 +92,18 @@ fi ##### 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 . 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 # good local VAR="good" local NEW="${VAR}" -# bad +# bad -> TravisCI will fail var="bad" +new=$var ``` ##### Loops @@ -125,7 +119,7 @@ done ##### 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 function _ @@ -139,59 +133,80 @@ function _ ##### 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 -set -euxEo pipefail -trap '_report_err $_ $LINENO $?' ERR +set -euEo pipefail +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}" + } ``` -##### 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. -A positive example: +A positive example, which is taken from `start-mailserver.sh`, would be ``` BASH -# writes result to stdout -function _add_one() +function _setup_postfix_aliases { - echo $(( $1 + 1 )) -} -``` + _notify 'task' 'Setting up Postfix Aliases' -A negative example: + : >/etc/postfix/virtual + : >/etc/postfix/regexp -``` BASH -# adds one to the first argument and print it to stdout -function _add_one() -{ - # save the first variable - local FIRST=$1 + if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]] + then + # fixing old virtual user file + if grep -q ",$" /tmp/docker-mailserver/postfix-virtual.cf + then + sed -i -e "s/, /,/g" -e "s/,$//g" /tmp/docker-mailserver/postfix-virtual.cf + fi - # add one here - local RESULT=$(( FIRST + 1 )) + cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual - # print it to stdout - echo "$_RESULT" + # the `to` is important, don't delete it + # 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 -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) [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 [semver]: https://semver.org/ -[regex]: https://regex101.com/r/ikzJpF/5 +[regex]: https://regex101.com/r/ikzJpF/7 [prettier]: https://prettier.io diff --git a/README.md b/README.md index 9127c935..2749b505 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ Why I created this image: [Simple Mail Server with Docker](http://tvi.al/simple- - Dovecot was downgraded 2. ELK was removed 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 - [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) -- SASLauthd with 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) - [Amavis](https://www.amavis.org/) - [Spamassasin](http://spamassassin.apache.org/) supporting custom rules - [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) - [Postscreen](http://www.postfix.org/POSTSCREEN_README.html) - [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 - [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!) - [Integration tests](https://travis-ci.org/tomav/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 -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 @@ -84,31 +87,27 @@ Minimum: ### 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 -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 .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 ``` ### 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: - `.env` contains the configuration for docker-compose - `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/)). - Don't quote your values. - 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:** 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 @@ -119,7 +118,7 @@ docker-compose up -d mail ./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 @@ -131,9 +130,7 @@ docker pull tvial/docker-mailserver:latest docker-compose up -d mail ``` -You're done! - -And don't forget to have a look at the remaining functions of the `setup.sh` script +You're done! And don't forget to have a look at the remaining functions of the `setup.sh` script with `./setup.sh -h`. #### SPF/Forwarding Problems diff --git a/setup.sh b/setup.sh index 34c1f13f..9d8fbd1d 100755 --- a/setup.sh +++ b/setup.sh @@ -100,7 +100,7 @@ function _inspect function _usage { - echo "${SCRIPT,,}.sh + echo "${SCRIPT,,}.sh Bootstrapping Script Usage: ${0} [-i IMAGE_NAME] [-c CONTAINER_NAME] [args] @@ -112,7 +112,9 @@ OPTIONS: -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: @@ -152,6 +154,8 @@ SUBCOMMANDS: ${0} debug inspect ${0} debug login + help: Show this help dialogue + " } @@ -236,7 +240,7 @@ function _main fi local OPTIND - while getopts ":c:i:p:" OPT + while getopts ":c:i:p:h" OPT do case ${OPT} in c) CONTAINER_NAME="${OPTARG}" ; USE_CONTAINER=true ;; # container specified, connect to running instance @@ -254,6 +258,7 @@ function _main exit 40 fi ;; + h) _usage ; return ;; *) echo "Invalid option: -${OPTARG}" >&2 ;; esac done @@ -339,6 +344,8 @@ function _main esac ;; + help) _usage ;; + * ) _usage ; _unset_vars ; exit 1 ;; esac diff --git a/target/check-for-changes.sh b/target/check-for-changes.sh index 49aac44b..d1808d54 100755 --- a/target/check-for-changes.sh +++ b/target/check-for-changes.sh @@ -93,8 +93,8 @@ do postalias /etc/aliases # regenerate postfix accounts - echo -n >/etc/postfix/vmailbox - echo -n >/etc/dovecot/userdb + : >/etc/postfix/vmailbox + : >/etc/dovecot/userdb if [[ -f /tmp/docker-mailserver/postfix-accounts.cf ]] && [[ ${ENABLE_LDAP} -ne 1 ]] then @@ -113,7 +113,7 @@ do if [[ -n ${RELAY_HOST} ]] then # keep old config - echo -n >/etc/postfix/sasl_passwd + : >/etc/postfix/sasl_passwd if [[ -n ${SASL_PASSWD} ]] then echo "${SASL_PASSWD}" >>/etc/postfix/sasl_passwd @@ -122,13 +122,13 @@ do # add domain-specific auth from config file if [[ -f /tmp/docker-mailserver/postfix-sasl-password.cf ]] then - (grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-sasl-password.cf || true) | while read -r LINE + while read -r LINE do if ! echo "${LINE}" | grep -q -e "\s*#" then echo "${LINE}" >>/etc/postfix/sasl_passwd fi - done + done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-sasl-password.cf || true) fi # add default relay @@ -140,7 +140,7 @@ do # creating users ; 'pass' is encrypted # 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 USER=$(echo "${LOGIN}" | cut -d @ -f1) DOMAIN=$(echo "${LOGIN}" | cut -d @ -f2) @@ -171,7 +171,7 @@ do fi echo "${DOMAIN}" >>/tmp/vhost.tmp - done + done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-accounts.cf) fi [[ -n ${RELAY_HOST} ]] && _populate_relayhost_map @@ -186,8 +186,8 @@ do if [[ -f postfix-virtual.cf ]] then # regenerate postfix aliases - echo -n >/etc/postfix/virtual - echo -n >/etc/postfix/regexp + : >/etc/postfix/virtual + : >/etc/postfix/regexp if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]] then @@ -195,14 +195,14 @@ do # the `to` seems to be important; don't delete it # 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 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 + done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true) fi if [[ -f /tmp/docker-mailserver/postfix-regexp.cf ]] diff --git a/target/helper_functions.sh b/target/helper_functions.sh index 16df5d31..f2ac258f 100644 --- a/target/helper_functions.sh +++ b/target/helper_functions.sh @@ -159,7 +159,7 @@ export -f _notify # @domain3.com [smtp.mailgun.org]:587 function _populate_relayhost_map { - echo -n > /etc/postfix/relayhost_map + : >/etc/postfix/relayhost_map chown root:root /etc/postfix/relayhost_map chmod 0600 /etc/postfix/relayhost_map diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 44ebc136..531394af 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -640,7 +640,7 @@ function _setup_dovecot_quota if [[ ! -f /tmp/docker-mailserver/dovecot-quotas.cf ]] then _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 # enable quota policy check in postfix @@ -651,8 +651,8 @@ function _setup_dovecot_quota function _setup_dovecot_local_user { _notify 'task' 'Setting up Dovecot Local User' - echo -n > /etc/postfix/vmailbox - echo -n > /etc/dovecot/userdb + : >/etc/postfix/vmailbox + : >/etc/dovecot/userdb if [[ -f /tmp/docker-mailserver/postfix-accounts.cf ]] && [[ ${ENABLE_LDAP} -ne 1 ]] then @@ -674,7 +674,7 @@ function _setup_dovecot_local_user # creating users ; 'pass' is encrypted # 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 # Setting variables for better readability USER=$(echo "${LOGIN}" | cut -d @ -f1) @@ -709,7 +709,7 @@ function _setup_dovecot_local_user fi echo "${DOMAIN}" >> /tmp/vhost.tmp - done + done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-accounts.cf) else _notify 'inf' "'config/docker-mailserver/postfix-accounts.cf' is not provided. No mail account created." fi @@ -776,7 +776,7 @@ function _setup_ldap configomat.sh "DOVECOT_" "/etc/dovecot/dovecot-ldap.conf.ext" - # add domainname to vhost + # add domainname to vhost echo "${DOMAINNAME}" >>/tmp/vhost.tmp _notify 'inf' "Enabling dovecot LDAP authentification" @@ -961,8 +961,8 @@ function _setup_postfix_aliases { _notify 'task' 'Setting up Postfix Aliases' - echo -n > /etc/postfix/virtual - echo -n > /etc/postfix/regexp + : >/etc/postfix/virtual + : >/etc/postfix/regexp if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]] then @@ -976,15 +976,14 @@ function _setup_postfix_aliases # the `to` is important, don't delete it # 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 - # 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 + 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 @@ -1009,7 +1008,7 @@ s/$/ pcre:\/etc\/postfix\/regexp/ cat /tmp/docker-mailserver/postfix-aliases.cf >> /etc/aliases else _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 postalias /etc/aliases