-
Notifications
You must be signed in to change notification settings - Fork 2
/
email-relay-dash-to-plus-install
executable file
·72 lines (57 loc) · 2.52 KB
/
email-relay-dash-to-plus-install
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
#!/bin/bash -ex
#
# email-relay-dash-to-plus-install (Ubuntu 16.04 LTS xenial, 18.04 LTS bionic)
#
# https://github.com/alestic/alestic-email-relay-dash-to-plus
#
domain="${1-example.com}"
host="${2-email-relay-dash-to-plus}"
waithandle="$3"
email="$4"
if [ -n "$waithandle" ]; then
# Let CloudFormation know if this instance fails
trap '
instance_id=$(curl -s http://instance-data/latest/meta-data/instance-id)
curl -X PUT -H '"'"'Content-Type:'"'"' --data-binary '"'"'{"Status":"FAILURE","Reason":"Configuration Failed","UniqueId":"'$instance_id'","Data":"Error during instance initialization. See /var/log/user-data.log"}'"'"' "$waithandle"
' ERR
fi
echo "INSTANCE CONFIGURATION START"
echo "$0"
hostname $host.$domain
echo "127.0.1.2 $host.$domain $host" >> /etc/hosts
echo $host.$domain > /etc/hostname
echo $host.$domain > /etc/mailname
service rsyslog restart
# Avoid hanging on dist-upgrade terminal input in Ubuntu 18.04
tmpfile=$(mktemp /tmp/encoding-XXXXXX.conf)
echo "console-setup console-setup/charmap47 select UTF-8" > $tmpfile
debconf-set-selections $tmpfile
rm $tmpfile
# And another to prevent hanging on console input
apt-mark hold grub-legacy-ec2
apt-get update
apt-get dist-upgrade -y
DEBIAN_FRONTEND=noninteractive apt-get install -y postfix postfix-pcre
if [ -n "$email" ]; then
echo "root: $email" >> /etc/aliases
newaliases
fi
# Reject addresses without '-' to prevent infinite loop with Google.
echo '!'"/^([^-]+)-(.*)@$domain\$/ REJECT" > /etc/postfix/recipients-pcre
postconf -e "smtpd_recipient_restrictions = check_recipient_access pcre:/etc/postfix/recipients-pcre reject_unauth_destination"
# Rewrite USERNAME-ANYTHING@DOMAIN to USERNAME+ANYTHING@DOMAIN
echo "/^([^-]+)-(.*)@$domain\$/ \$1+\$2@$domain" \
> /etc/postfix/valiases-pcre
postconf -e "virtual_alias_maps = pcre:/etc/postfix/valiases-pcre"
postconf -e "myhostname = $host.$domain"
postconf -e "relay_domains = $domain"
postconf -e "mydestination = $host.$domain, localhost.$domain, localhost"
# Increase message size limit from default ~10MB to 25MB (GMail limit)
postconf -e "message_size_limit = 26214400"
/etc/init.d/postfix reload
# Let CloudFormation know this instance is ready.
if [ -n "$waithandle" ]; then
instance_id=$(curl -s http://instance-data/latest/meta-data/instance-id)
curl -X PUT -H 'Content-Type:' --data-binary '{"Status":"SUCCESS","Reason":"Configuration Complete","UniqueId":"'$instance_id'","Data":"Instance has completed configuration."}' "$waithandle"
fi
echo "INSTANCE CONFIGURATION COMPLETE"