[DOCKER][MAIL] Moved and modified setup.sh

This commit is contained in:
Pastilhas 2020-11-19 13:43:15 +00:00 committed by Hugo Sales
parent 93939d8b25
commit def5e06a28
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
6 changed files with 39 additions and 61 deletions

View File

@ -1,21 +0,0 @@
#!/bin/sh
printf "Domain root: "
read -r domain_root
printf "Subdomain (can be empty): "
read -r sub_domain
if [ -z "$sub_domain" ]
then
domain="${domain_root}"
else
domain="${sub_domain}.${domain_root}"
fi
cat > ./docker/mail/mail.env <<EOF
#!/bin/sh
DOMAINNAME=${domain_root}
MAILNAME=${domain}
SSL_CERT=/etc/letsencrypt/live/${domain_root}/fullchain.pem
SSL_KEY=/etc/letsencrypt/live/${domain_root}/privkey.pem
EOF

View File

@ -36,7 +36,7 @@ RUN \
COPY rootfs/ /
# Expose ports
EXPOSE 25 143 587 993
EXPOSE 110 143 587 993 995
# Run start script
ENTRYPOINT /usr/bin/start.sh

View File

@ -1,22 +0,0 @@
#!/bin/sh
USAGE = "Usage: $0 new domain <domain_name>\n : $0 new user <user_name> <user_password>\n : $0 new alias <user_alias> <user_name>"
if [ -z "$2" ]
then
echo "$USAGE";
exit 1;
fi
if [ "$1" == "new" ]
then
if [ "$2" == "domain" ]
then
docker exec mail new-domain "${*,3}"
elif [ "$2" == "user" ]
then
docker exec mail new-user "${*,3}"
elif [ "$2" == "alias" ]
then
docker exec mail new-alias "${*,3}"
fi
fi

View File

@ -8,6 +8,3 @@
172.17.0.0/16
fe80::/64
#HOSTNAME
#host.example.com
#192.168.1.0/24

View File

@ -1,18 +1,4 @@
#!/bin/sh
# Config postfix
postconf -e myhostname="$MAILNAME"
postconf -e mydomain="$DOMAINNAME"
postconf -e smtpd_tls_cert_file="$SSL_CERT"
postconf -e smtpd_tls_key_file="$SSL_KEY"
# Config dovecot
sed -i -e "s#^\s*ssl_cert\s*=.*#ssl_cert = <$SSL_CERT#" /etc/mail/dovecot/dovecot.conf
sed -i -e "s#^\s*ssl_key\s*=.*#ssl_key = <$SSL_KEY#" /etc/mail/dovecot/dovecot.conf
sed -i -e "s#^\s*hostname\s*=.*#hostname = $MAILNAME#" /etc/mail/dovecot/dovecot.conf
sed -i -e "s#^\s*postmaster_address\s*=.*#postmaster_address = $POSTMASTER#" /etc/mail/dovecot/dovecot.conf
# Config dkim
sed -i -e "s/#HOSTNAME/$MAILNAME/" /etc/mail/opendkim/TrustedHosts
# Run openssl
if [ ! -e "$SSL_CERT" ]
@ -28,6 +14,7 @@ then
opendkim-genkey -d "$DOMAINNAME" -D "/var/opendkim/keys"
fi
# Prepare postfix
if [ ! -d "/var/mail/$DOMAINNAME" ]
then
touch /etc/mail/aliases /etc/mail/domains /etc/mail/mailboxes /etc/mail/passwd

37
docker/mail/setup.sh Normal file
View File

@ -0,0 +1,37 @@
#!/bin/sh
printf "Domain root: "
read -r domain_root
printf "Subdomain (can be empty): "
read -r sub_domain
if [ -z "$sub_domain" ]
then
domain="${domain_root}"
else
domain="${sub_domain}.${domain_root}"
fi
cat > mail.env <<EOF
#!/bin/sh
DOMAINNAME=${domain_root}
MAILNAME=${domain}
SSL_CERT=/etc/letsencrypt/live/${domain_root}/fullchain.pem
SSL_KEY=/etc/letsencrypt/live/${domain_root}/privkey.pem
EOF
# Config postfix
sed -i -e "s#^\s*myhostname\s*=.*#myhostname = $MAILNAME#" rootfs/etc/mail/postfix/main.cf
sed -i -e "s#^\s*mydomain\s*=.*#mydomain = $DOMAINNAME#" rootfs/etc/mail/postfix/main.cf
sed -i -e "s#^\s*smtpd_tls_cert_file\s*=.*#smtpd_tls_cert_file = $SSL_CERT#" rootfs/etc/mail/postfix/main.cf
sed -i -e "s#^\s*smtpd_tls_key_file\s*=.*#smtpd_tls_key_file = $SSL_KEY#" rootfs/etc/mail/postfix/main.cf
# Config dovecot
sed -i -e "s#^\s*ssl_cert\s*=.*#ssl_cert = <$SSL_CERT#" rootfs/etc/mail/dovecot/dovecot.conf
sed -i -e "s#^\s*ssl_key\s*=.*#ssl_key = <$SSL_KEY#" rootfs/etc/mail/dovecot/dovecot.conf
sed -i -e "s#^\s*hostname\s*=.*#hostname = $MAILNAME#" rootfs/etc/mail/dovecot/dovecot.conf
sed -i -e "s#^\s*postmaster_address\s*=.*#postmaster_address = $POSTMASTER#" rootfs/etc/mail/dovecot/dovecot.conf
# Config dkim
sed -i -e "s/#HOSTNAME/$MAILNAME/" rootfs/etc/mail/opendkim/TrustedHosts