2016-12-30 19:06:44 +00:00
|
|
|
#! /bin/bash
|
2016-08-29 11:44:36 +00:00
|
|
|
|
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
|
|
|
|
2021-04-12 13:18:15 +00:00
|
|
|
function dovecot_quota_to_hr()
|
|
|
|
{
|
|
|
|
if [ "${1}" == "-" ]
|
|
|
|
then
|
|
|
|
echo "~"
|
|
|
|
else
|
|
|
|
echo $(( 1024 * ${1} )) | numfmt --to=iec
|
|
|
|
fi
|
|
|
|
}
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2021-04-12 13:18:15 +00:00
|
|
|
DATABASE="/tmp/docker-mailserver/postfix-accounts.cf"
|
|
|
|
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}"
|
2016-08-29 11:44:36 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
exit 0
|