2020-04-24 12:55:32 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2022-02-21 10:56:57 +00:00
|
|
|
# shellcheck source=../scripts/helpers/index.sh
|
|
|
|
source /usr/local/bin/helpers/index.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}
|
|
|
|
|
2022-03-26 08:30:09 +00:00
|
|
|
function __usage { echo 'Usage: delquota <username@domain>' ; }
|
2021-02-23 19:03:01 +00:00
|
|
|
|
|
|
|
[[ ${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
|
|
|
|
2022-03-26 08:30:09 +00:00
|
|
|
[[ -z ${USER} ]] && { __usage ; _exit_with_error 'No username specified' ; }
|
|
|
|
[[ ${USER} =~ .*\@.* ]] || { __usage ; _exit_with_error 'Username must include the domain' ; }
|
2020-04-24 12:55:32 +00:00
|
|
|
|
2022-03-26 08:30:09 +00:00
|
|
|
grep -qE "^${USER}\|" "${USER_DATABASE}" || _exit_with_error "User '${USER}' does not exist"
|
2020-04-24 12:55:32 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
[[ -s ${DATABASE} ]] || exit 0
|
|
|
|
|
|
|
|
sed -i -e "/^${USER}:.*$/d" "${DATABASE}"
|