docker-mailserver/target/bin/delalias

24 lines
652 B
Bash
Executable file

#! /bin/bash
# shellcheck source=../scripts/helpers/index.sh
source /usr/local/bin/helpers/index.sh
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-virtual.cf}
EMAIL="${1}"
RECIPIENT="${2}"
function __usage { echo "Usage: delalias <alias@domain> <recipient@other>" ; }
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
[[ -z ${EMAIL} ]] && { __usage ; _errex "Error: No alias specified" ; }
[[ -z ${RECIPIENT} ]] && { __usage ; _errex "Error: No recipient specified" ; }
[[ -s ${DATABASE} ]] || exit 0
sed -i \
-e "/^${EMAIL} *${RECIPIENT}$/d" \
-e "/^${EMAIL}/s/,${RECIPIENT}//g" \
-e "/^${EMAIL}/s/${RECIPIENT},//g" \
"${DATABASE}"