Enhance setup.sh email list (#1898)

* add quota and aliases to output

* shellcheck fixes

* fix test

Co-authored-by: Georg Lauterbach <44545919+aendeavor@users.noreply.github.com>
This commit is contained in:
Casper 2021-04-12 15:18:15 +02:00 committed by GitHub
parent deca22bcd4
commit dea9bca900
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 5 deletions

View file

@ -3,10 +3,39 @@
# shellcheck source=../scripts/helper-functions.sh # shellcheck source=../scripts/helper-functions.sh
. /usr/local/bin/helper-functions.sh . /usr/local/bin/helper-functions.sh
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-accounts.cf} function dovecot_quota_to_hr()
{
if [ "${1}" == "-" ]
then
echo "~"
else
echo $(( 1024 * ${1} )) | numfmt --to=iec
fi
}
[[ -f ${DATABASE} ]] || errex "Error: No postfix-virtual.cf file" DATABASE="/tmp/docker-mailserver/postfix-accounts.cf"
[[ -s ${DATABASE} ]] || errex "Error: Empty postfix-virtual.cf - no aliases have been added" ALIASES="/tmp/docker-mailserver/postfix-virtual.cf"
[[ -f ${DATABASE} ]] || errex "Error: No postfix-accounts.cf file"
[[ -s ${DATABASE} ]] || errex "Error: Empty postfix-accounts.cf - no accounts have been added"
while read -r LINE
do
USER=$(echo "${LINE}" | cut -d'|' -f1)
# ${QUOTA[0]} => current size
# ${QUOTA[1]} => configured size limit
# ${QUOTA[2]} => usage in percent
IFS=' ' read -r -a QUOTA <<< "$(doveadm quota get -u "${USER}" | tail +2 | awk '{ if ($3 == "STORAGE") { print $4" "$5" "$6 } }')"
echo "* ${USER} ( $(dovecot_quota_to_hr "${QUOTA[0]}") / $(dovecot_quota_to_hr "${QUOTA[1]}") ) [${QUOTA[2]}%]"
if [[ -f ${ALIASES} ]] && grep -q "${USER}" "${ALIASES}"
then
echo -e " [ aliases -> $(grep "${USER}" "${ALIASES}" | awk '{print $1;}' | sed ':a;N;$!ba;s/\n/, /g')]\n"
else
echo
fi
done < "${DATABASE}"
{ grep -v "^\s*$\|^\s*\#" "${DATABASE}" || true ; } | awk -F '|' '{ print $1; }'
exit 0 exit 0

View file

@ -673,7 +673,7 @@ EOF
@test "checking accounts: listmailuser" { @test "checking accounts: listmailuser" {
run docker exec mail /bin/sh -c "listmailuser | head -n 1" run docker exec mail /bin/sh -c "listmailuser | head -n 1"
assert_success assert_success
assert_output 'user1@localhost.localdomain' assert_output '* user1@localhost.localdomain ( 12K / ~ ) [0%]'
} }
@test "checking accounts: no error is generated when deleting a user if /tmp/docker-mailserver/postfix-accounts.cf is missing" { @test "checking accounts: no error is generated when deleting a user if /tmp/docker-mailserver/postfix-accounts.cf is missing" {