mirror of
https://git.myvelabs.com/docker/myvemailbackup.git
synced 2025-12-17 22:56:18 +00:00
First commit
This commit is contained in:
commit
cd1be5abe2
6 changed files with 423 additions and 0 deletions
28
build/Dockerfile
Normal file
28
build/Dockerfile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# syntax = docker/dockerfile:1
|
||||
FROM alpine:edge
|
||||
|
||||
# LABEL about the custom image
|
||||
LABEL description="MyveMail Backup"
|
||||
|
||||
# Copy required files folders
|
||||
ADD run/docker-entrypoint /docker-entrypoint/
|
||||
ADD run/installer.sh /tmp/
|
||||
|
||||
# Update Ubuntu Software repository and install requisites
|
||||
RUN printf '%s\n' 'https://dl-cdn.alpinelinux.org/alpine/latest-stable/main/' \
|
||||
'https://dl-cdn.alpinelinux.org/alpine/latest-stable/community/' >/etc/apk/repositories \
|
||||
&& apk update \
|
||||
&& apk upgrade \
|
||||
&& apk add --no-cache \
|
||||
bash bash-completion ncurses \
|
||||
ca-certificates openssl \
|
||||
postfix \
|
||||
# Installer
|
||||
&& /tmp/installer.sh \
|
||||
&& rm /tmp/installer.sh
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 25
|
||||
|
||||
# Entrypoint hd-wallet-derive script
|
||||
CMD ["/docker-entrypoint/entrypoint.sh"]
|
||||
75
build/run/docker-entrypoint/entrypoint.sh
Executable file
75
build/run/docker-entrypoint/entrypoint.sh
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env bash
|
||||
# Abort if an error is encountered
|
||||
set -e
|
||||
|
||||
# Exit function
|
||||
trap '[ "${?}" -ne 77 ] || exit 77' ERR
|
||||
function die
|
||||
{
|
||||
local reset="\e[0m"
|
||||
local red="\e[0m\e[0;31m"
|
||||
local yellow="\e[0m\e[0;33m"
|
||||
|
||||
echo -e "${red}
|
||||
Error encountered in the following init script:
|
||||
${yellow}
|
||||
${@}
|
||||
${red}
|
||||
Aborting...
|
||||
${reset}"
|
||||
|
||||
exit 77
|
||||
}
|
||||
|
||||
# Reset
|
||||
echo | tee /var/log/maillog /etc/postfix/{relaydomains,transportmaps,helo_access,rbl_override}
|
||||
|
||||
# Postfix
|
||||
echo ${MYVEMAIL_DOMAIN} >/etc/mailname
|
||||
postconf -e "myhostname = ${MYVEMAIL_SUBDOMAIN}.${MYVEMAIL_DOMAIN}"
|
||||
postconf -e "mydestination = \$myhostname, ${MYVEMAIL_SUBDOMAIN}.${MYVEMAIL_DOMAIN}, localhost, localhost.localdomain, localhost"
|
||||
postconf -e "mydomain = ${MYVEMAIL_DOMAIN}"
|
||||
|
||||
# resolv.conf
|
||||
[ -d /var/spool/postfix/etc/ ] || mkdir /var/spool/postfix/etc/
|
||||
cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf
|
||||
|
||||
# Add primary mail servers to mynetworks
|
||||
if [ ${MYVEMAIL_PRIMARYMX} ]
|
||||
then
|
||||
primarymx+=(${MYVEMAIL_PRIMARYMX//,/ })
|
||||
postconf -e "$(postconf mynetworks)$(printf ' %s/32' ${primarymx[@]})"
|
||||
fi
|
||||
|
||||
# Relay setup
|
||||
addmx=(${MYVEMAIL_DOMAIN})
|
||||
addmx+=(${MYVEMAIL_ADDMX//,/ })
|
||||
printf '%s OK\n' ${addmx[@]} >/etc/postfix/relaydomains
|
||||
for domain in ${addmx[@]}
|
||||
do
|
||||
echo "${domain} smtp:mail.${domain}:25" | tee -a /etc/postfix/transportmaps >/dev/null
|
||||
echo "${domain} OK" | tee -a /etc/postfix/{helo_access,rbl_override} >/dev/null
|
||||
done
|
||||
|
||||
# Start postfix
|
||||
postfix start
|
||||
postmap /etc/postfix/relaydomains /etc/postfix/transportmaps /etc/postfix/helo_access /etc/postfix/rbl_override
|
||||
postfix reload
|
||||
|
||||
# Downtime log
|
||||
install /dev/stdin /usr/local/bin/downtime <<- downtime
|
||||
#!/usr/bin/env bash
|
||||
# Send downtime log to downtime email address
|
||||
echo "From: ${MYVEMAIL_SUBDOMAIN}@${MYVEMAIL_DOMAIN}
|
||||
To: downtime@${MYVEMAIL_DOMAIN}
|
||||
Subject: Monthly downtime log
|
||||
|
||||
\$(cat /var/log/downtime)" | sendmail downtime@${MYVEMAIL_DOMAIN}
|
||||
|
||||
# Delete log to start anew
|
||||
echo >/var/log/downtime
|
||||
downtime
|
||||
|
||||
# Monitor log
|
||||
echo -e "\n\e[1;32mMail service is ready\e[0m\n"
|
||||
tail -f /var/log/maillog
|
||||
62
build/run/installer.sh
Executable file
62
build/run/installer.sh
Executable file
|
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
###############
|
||||
#//
|
||||
#// Postfix
|
||||
#//
|
||||
###############
|
||||
# Postfix
|
||||
postconf -e 'myorigin = $mydomain'
|
||||
postconf -e 'inet_interfaces = all'
|
||||
postconf -e 'inet_protocols = ipv4'
|
||||
postconf -e 'smtp_address_preference = ipv4'
|
||||
postconf -e 'message_size_limit = 0'
|
||||
postconf -e 'mailbox_size_limit = 0'
|
||||
|
||||
# Touch aliases db
|
||||
newaliases
|
||||
|
||||
# Logging
|
||||
postconf -e "maillog_file = /var/log/maillog"
|
||||
|
||||
# Backup mail server specific settings
|
||||
postconf -e 'maximal_queue_lifetime = 30d'
|
||||
postconf -e 'minimal_backoff_time = 60s'
|
||||
postconf -e 'relay_recipient_maps = '
|
||||
postconf -e "relay_domains = lmdb:/etc/postfix/relaydomains"
|
||||
postconf -e "transport_maps = lmdb:/etc/postfix/transportmaps"
|
||||
|
||||
# Security
|
||||
postconf -e 'smtpd_tls_security_level = may'
|
||||
postconf -e 'smtp_tls_security_level = may'
|
||||
|
||||
postconf -e 'smtpd_tls_loglevel = 1'
|
||||
postconf -e 'smtp_tls_verify_cert_match = hostname, nexthop, dot-nexthop'
|
||||
postconf -e 'smtp_tls_CApath = /etc/ssl/certs'
|
||||
postconf -e "smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt"
|
||||
postconf -e 'smtp_tls_loglevel = 1'
|
||||
openssl rehash /etc/ssl/certs || c_rehash /etc/ssl/certs
|
||||
|
||||
[ -d /etc/postfix/ssl/ ] || mkdir -p /etc/postfix/ssl/
|
||||
postconf -e "smtpd_tls_key_file = /etc/postfix/ssl/tls.key"
|
||||
postconf -e "smtpd_tls_cert_file = /etc/postfix/ssl/tls.pem"
|
||||
|
||||
# # Enforce TLSv1.2 or TLSv1.2
|
||||
postconf -e "smtpd_tls_protocols = >=TLSv1.2"
|
||||
|
||||
# Spam filters (https://www.linuxbabe.com/mail-server/block-email-spam-postfix)
|
||||
postconf -e "smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unknown_sender_domain, reject_unknown_reverse_client_hostname, reject_unknown_client_hostname"
|
||||
postconf -e "smtpd_helo_required = yes"
|
||||
postconf -e "smtpd_helo_restrictions = permit_mynetworks, permit_sasl_authenticated, check_helo_access lmdb:/etc/postfix/helo_access, reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname, reject_unknown_helo_hostname"
|
||||
postconf -e "smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"
|
||||
|
||||
# Check postqueue every 5 seconds
|
||||
install /dev/stdin /usr/local/bin/postqueue-check >/dev/null <<'postqueue'
|
||||
#!/usr/bin/env bash
|
||||
if postqueue -p | grep -q 'Mail queue is empty'
|
||||
then
|
||||
exit 0
|
||||
else
|
||||
postqueue -f
|
||||
fi
|
||||
postqueue
|
||||
Loading…
Add table
Add a link
Reference in a new issue