2016-12-30 19:06:44 +00:00
|
|
|
#! /bin/bash
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
# ? This is done to ignore the message "Make sure not to read and write
|
|
|
|
# ? the same file in the same pipeline", which is a result of ${DATABASE}
|
|
|
|
# ? being used below. (This disables the message file-wide.)
|
|
|
|
# shellcheck disable=SC2094
|
|
|
|
|
2021-01-16 09:16:05 +00:00
|
|
|
# shellcheck source=../scripts/helper-functions.sh
|
|
|
|
. /usr/local/bin/helper-functions.sh
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-accounts.cf}
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
[[ -f ${DATABASE} ]] || errex "Error: No postfix-virtual.cf file"
|
|
|
|
[[ -s ${DATABASE} ]] || errex "Error: Empty postfix-virtual.cf - no aliases have been added"
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2019-08-01 17:39:25 +00:00
|
|
|
# Lock database even though we are only reading
|
|
|
|
(
|
|
|
|
flock -e 200
|
2020-10-21 16:16:32 +00:00
|
|
|
( grep -v "^\s*$\|^\s*\#" "${DATABASE}" || true ) | awk -F '|' '{ print $1; }'
|
|
|
|
) 200< "${DATABASE}"
|