-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostfix_add_domain
executable file
·82 lines (73 loc) · 2.68 KB
/
postfix_add_domain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# Add Domain to Postfix
# 08/16/17 - Created by Andrew Puckett
# https://www.hardenize.com/blog/mta-sts
if [ $# -lt 1 ]; then
echo "NAME"
echo " $(basename $0) options"
echo
echo "DESCRIPTION"
echo " $(basename $0) is used to add a domain to postfix."
echo
echo "OPTIONS"
echo " -a"
echo " Email address to forward admin mail to."
echo " -d"
echo " Domain. Required."
echo " -f"
echo " Forwarding domain."
echo " -n"
echo " Name of host (abbreviation or domain). Optional."
echo " -p"
echo " Email address to forward postmaster mail to. Optional."
echo
echo "AUTHOR"
echo " Andrew Puckett"
echo
exit 1
fi
[ $(id -u) != "0" ] && echo "ERROR: You must be the superuser to run this script" >&2 && exit 1
DOMAIN=
SHORT_NAME=
ADMIN_EMAIL=
FORWARD_DOMAIN=
POSTMASTER=
while getopts a:d:f:n:p: opt
do
case "$opt" in
a) ADMIN_EMAIL=$OPTARG;;
d) DOMAIN=$OPTARG;;
f) FORWARD_DOMAIN=$OPTARG;;
n) SHORT_NAME=$OPTARG;;
p) POSTMASTER=$OPTARG;;
esac
done
[ -z "$DOMAIN" ] && echo "ERROR: Domain is required." >&2 && exit 1
[ -z "$SHORT_NAME" ] && SHORT_NAME=$DOMAIN
yes "y" | opendkim_add_key -d $DOMAIN -n $SHORT_NAME
[ -f /etc/postfix/virtual ] && cat /etc/postfix/virtual > /etc/postfix/virtual_new
echo $DOMAIN -- >> /etc/postfix/virtual_new
if [ -n "$FORWARD_DOMAIN" ]; then
echo @$DOMAIN @$FORWARD_DOMAIN >> /etc/postfix/virtual_new
else
for ACCT in abuse accounts contact ftp hostmaster info list mail marketing postmaster root sales security social support webmaster www; do
case "$ACCT" in
accounts|root|security|webmaster) echo $ACCT@$DOMAIN admin@$DOMAIN >> /etc/postfix/virtual_new;;
mail|marketing|sales) echo $ACCT@$DOMAIN info@$DOMAIN >> /etc/postfix/virtual_new;;
abuse|contact|ftp|hostmaster|info|list|social|support|www) echo $ACCT@$DOMAIN webmaster@$DOMAIN >> /etc/postfix/virtual_new;;
esac
done
if [ -n "$POSTMASTER" ]; then
echo postmaster@$DOMAIN $POSTMASTER >> /etc/postfix/virtual_new
else
echo postmaster@$DOMAIN postmaster-$SHORT_NAME@localhost >> /etc/postfix/virtual_new
echo "postmaster-$SHORT_NAME: \"| SERVER_NAME=$DOMAIN php /var/www/$SHORT_NAME/current/lib/_8n/controllers/logevent.php POSTMASTER\"" >> /etc/aliases
fi
echo no-reply@$DOMAIN devnull@localhost >> /etc/postfix/virtual_new
echo listunsubscribe@$DOMAIN listunsubscribe-$SHORT_NAME@localhost >> /etc/postfix/virtual_new
echo "listunsubscribe-$SHORT_NAME: \"| php /var/www/$SHORT_NAME/current/lib/_8n/emailmarketing/controllers/listunsubscribe.php\"" >> /etc/aliases
newaliases
fi
[ -n "$ADMIN_EMAIL" ] && echo admin@$DOMAIN $ADMIN_EMAIL >> /etc/postfix/virtual_new
mv --backup=numbered /etc/postfix/virtual_new /etc/postfix/virtual
postmap /etc/postfix/virtual