Created
January 25, 2017 16:41
-
-
Save tzwenn/6f2e347c267290313678b65063270b4a to your computer and use it in GitHub Desktop.
Postfix Admin: Create a new <foo>@example.com alias to your e-mail address by direct postgres insert over SSH.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOMAIN=example.com | |
TARGET=mail@$DOMAIN | |
SSH_HOST=example.com | |
SSH_USER=$USER | |
DBNAME=postfixadmin | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 <alias>"; | |
exit 1 | |
fi | |
FORBIDDEN="\'\"\\\;\:\#\[\]\{\}\(\)\|\&\^\$\@\!\?\,\ \*\<\>" # '"\;:#[]{}()|&^$@!?, *<> | |
if grep -qP "[$FORBIDDEN]" <<<$1; then | |
echo "Alias may not contain any of $FORBIDDEN (of course unescaped)" | |
exit 2 | |
fi | |
ALIAS=$1@$DOMAIN | |
CMD="\"INSERT INTO alias VALUES ('$ALIAS', '$TARGET', '$DOMAIN');\"" | |
set -x | |
ssh -t $SSH_USER@$SSH_HOST sudo -u postgres psql $DBNAME -c "$CMD" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment