mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
1bd8ef3976
Adopt the new colour vars from `helpers/log.sh` like the other supported commands have.
76 lines
1.9 KiB
Bash
Executable file
76 lines
1.9 KiB
Bash
Executable file
#! /bin/bash
|
|
|
|
# shellcheck disable=SC2094
|
|
# ? 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 source=../scripts/helpers/index.sh
|
|
source /usr/local/bin/helpers/index.sh
|
|
|
|
DATABASE=/tmp/docker-mailserver/dovecot-masters.cf
|
|
|
|
function __usage
|
|
{
|
|
printf '%s' "${PURPLE}DELDOVECOTMASTERUSER${RED}(${YELLOW}8${RED})
|
|
|
|
${ORANGE}NAME${RESET}
|
|
deldovecotmasteruser - delete a dovecot master user
|
|
|
|
${ORANGE}SYNOPSIS${RESET}
|
|
./setup.sh dovecot-master del [ OPTIONS ] { <MAIL ADDRESS> [<MAIL ADDRESS>${RED}...${RESET}] ${RED}|${RESET} help }
|
|
|
|
${ORANGE}DESCRIPTION${RESET}
|
|
Delete a dovecot master user.
|
|
|
|
${ORANGE}OPTIONS${RESET}
|
|
-h
|
|
Show this help dialogue.
|
|
|
|
${ORANGE}EXAMPLES${RESET}
|
|
${LWHITE}./setup.sh dovecot-master del administrator${RESET}
|
|
Delete the dovecot master user called 'administrator'.
|
|
|
|
${LWHITE}./setup.sh dovecot-master del administrator admin${RESET}
|
|
Delete dovecot master users 'administrator' and 'admin'.
|
|
|
|
${ORANGE}EXIT STATUS${RESET}
|
|
Exit status is 0 if command was successful, and 1 if there was an error.
|
|
"
|
|
}
|
|
|
|
if [[ ${1} == 'help' ]]
|
|
then
|
|
__usage
|
|
exit 0
|
|
fi
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
[[ -z ${*} ]] && { __usage ; _exit_with_error 'No user specified' ; }
|
|
[[ -s ${DATABASE} ]] || exit 0
|
|
|
|
_create_lock # Protect config file with lock to avoid race conditions
|
|
|
|
for USER in "${@}"
|
|
do
|
|
ERROR=false
|
|
|
|
# ${USER} must not contain /s and other syntactic characters
|
|
UNESCAPED_USER="${USER}"
|
|
USER=$(_escape "${USER}")
|
|
|
|
if [[ -f ${DATABASE} ]]
|
|
then
|
|
if ! sedfile --strict -i "/^${USER}|/d" "${DATABASE}"
|
|
then
|
|
_log 'error' "'${UNESCAPED_USER}' couldn't be deleted in '${DATABASE}'"
|
|
ERROR=true
|
|
fi
|
|
fi
|
|
|
|
${ERROR} && _exit_with_error 'See the messages above.'
|
|
done
|
|
|
|
exit 0
|