mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-07-23 20:24:54 +02:00
Complete Refactor for target/bin
(#1654)
* documentation and script updates trying to fix #1647 * preparations for refactoring target/bin/ * complete refactor for target/bin/ * changing script output slightly * outsourcing functions in `bin-helper.sh` * re-wrote linting to allow for proper shellcheck -x execution * show explanation for shellcheck ignore * adding some more information
This commit is contained in:
parent
0ada57d87c
commit
da8171388f
37 changed files with 579 additions and 504 deletions
|
@ -1,31 +1,25 @@
|
|||
#! /bin/bash
|
||||
|
||||
# shellcheck source=../bin-helper.sh
|
||||
. /usr/local/bin/bin-helper.sh
|
||||
|
||||
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-virtual.cf}
|
||||
|
||||
EMAIL="$1"
|
||||
RECIPIENT="$2"
|
||||
EMAIL="${1}"
|
||||
RECIPIENT="${2}"
|
||||
|
||||
usage() {
|
||||
echo "Usage: addalias <alias@domain> <recipient@other>"
|
||||
}
|
||||
function usage { echo "Usage: addalias <alias@domain> <recipient@other>" ; }
|
||||
|
||||
errex() {
|
||||
echo "$@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
[[ -z ${EMAIL} ]] && { usage ; errex "Error: No alias specified" ; }
|
||||
[[ -z ${RECIPIENT} ]] && { usage ; errex "Error: No recipient specified" ; }
|
||||
|
||||
escape() {
|
||||
echo "${1//./\\.}"
|
||||
}
|
||||
grep \
|
||||
-qi "^$(escape "${EMAIL}")[a-zA-Z@.\ ]*$(escape "${RECIPIENT}")" \
|
||||
"${DATABASE}" 2>/dev/null && errex "Alias \"${EMAIL} ${RECIPIENT}\" already exists"
|
||||
|
||||
[ -z "$EMAIL" ] && { usage; errex "Error: No alias specified"; }
|
||||
[ -z "$RECIPIENT" ] && { usage; errex "Error: No recipient specified"; }
|
||||
|
||||
grep -qi "^$(escape $EMAIL)[a-zA-Z@.\ ]*$(escape $RECIPIENT)" $DATABASE 2>/dev/null &&
|
||||
errex "Alias \"$EMAIL $RECIPIENT\" already exists"
|
||||
|
||||
if grep -qi "^$(escape $EMAIL)" $DATABASE 2>/dev/null; then
|
||||
sed -i "/$EMAIL/s/$/,$RECIPIENT/" $DATABASE
|
||||
else
|
||||
echo "$EMAIL $RECIPIENT" >> $DATABASE
|
||||
if grep -qi "^$(escape "${EMAIL}")" "${DATABASE}" 2>/dev/null
|
||||
then
|
||||
sed -i "/${EMAIL}/s/$/,${RECIPIENT}/" "${DATABASE}"
|
||||
else
|
||||
echo "${EMAIL} ${RECIPIENT}" >> "${DATABASE}"
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue