2020-04-24 12:55:32 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2021-01-16 09:16:05 +00:00
|
|
|
# shellcheck source=../scripts/helper-functions.sh
|
|
|
|
. /usr/local/bin/helper-functions.sh
|
2020-10-21 16:16:32 +00:00
|
|
|
|
2020-04-24 12:55:32 +00:00
|
|
|
DATABASE=${DATABASE:-/tmp/docker-mailserver/dovecot-quotas.cf}
|
|
|
|
USER_DATABASE=${USER_DATABASE:-/tmp/docker-mailserver/postfix-accounts.cf}
|
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
function __usage { echo "Usage: delquota <username@domain>" ; }
|
|
|
|
|
|
|
|
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
|
2020-04-24 12:55:32 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
USER="${1}"
|
2020-04-24 12:55:32 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
[[ -z ${USER} ]] && { __usage ; errex "No username specified" ; }
|
2021-12-21 16:01:40 +00:00
|
|
|
[[ ${USER} =~ .*\@.* ]] || { __usage ; errex "Username must include the domain"; }
|
2020-04-24 12:55:32 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
if ! grep -qE "^${USER}\|" "${USER_DATABASE}"
|
|
|
|
then
|
2021-02-23 19:03:01 +00:00
|
|
|
__usage
|
2020-10-21 16:16:32 +00:00
|
|
|
errex "user ${USER} does not exist"
|
2020-04-24 12:55:32 +00:00
|
|
|
fi
|
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
[[ -s ${DATABASE} ]] || exit 0
|
|
|
|
|
|
|
|
sed -i -e "/^${USER}:.*$/d" "${DATABASE}"
|