2022-10-17 08:40:09 +00:00
|
|
|
#!/bin/bash
|
2015-03-28 14:59:15 +00:00
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
# ------------------------------------------------------------
|
2022-03-21 12:42:12 +00:00
|
|
|
# ? >> Sourcing helpers & stacks
|
|
|
|
# 1. Helpers
|
|
|
|
# 2. Checks
|
|
|
|
# 3. Setup
|
|
|
|
# 4. Fixes
|
|
|
|
# 5. Miscellaneous
|
|
|
|
# 6. Daemons
|
|
|
|
# ------------------------------------------------------------
|
|
|
|
|
2022-02-21 10:56:57 +00:00
|
|
|
# shellcheck source=./helpers/index.sh
|
|
|
|
source /usr/local/bin/helpers/index.sh
|
2018-04-04 16:48:55 +00:00
|
|
|
|
2022-03-21 12:42:12 +00:00
|
|
|
# shellcheck source=./startup/check-stack.sh
|
|
|
|
source /usr/local/bin/check-stack.sh
|
|
|
|
|
|
|
|
# shellcheck source=./startup/setup-stack.sh
|
|
|
|
source /usr/local/bin/setup-stack.sh
|
|
|
|
|
|
|
|
# shellcheck source=./startup/fixes-stack.sh
|
|
|
|
source /usr/local/bin/fixes-stack.sh
|
|
|
|
|
|
|
|
# shellcheck source=./startup/misc-stack.sh
|
|
|
|
source /usr/local/bin/misc-stack.sh
|
|
|
|
|
|
|
|
# shellcheck source=./startup/daemons-stack.sh
|
|
|
|
source /usr/local/bin/daemons-stack.sh
|
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
# ------------------------------------------------------------
|
|
|
|
# ? << Sourcing helpers & stacks
|
|
|
|
# --
|
2022-08-22 06:31:32 +00:00
|
|
|
# ? >> Early setup & environment variables setup
|
2022-03-21 12:42:12 +00:00
|
|
|
# ------------------------------------------------------------
|
|
|
|
|
2022-08-22 06:31:32 +00:00
|
|
|
# shellcheck source=./helpers/variables.sh
|
|
|
|
source /usr/local/bin/helpers/variables.sh
|
2021-02-23 19:03:01 +00:00
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
_setup_supervisor
|
2022-03-02 21:22:17 +00:00
|
|
|
_obtain_hostname_and_domainname
|
2022-08-22 06:31:32 +00:00
|
|
|
_environment_variables_backwards_compatibility
|
|
|
|
_environment_variables_general_setup
|
2022-03-02 21:22:17 +00:00
|
|
|
|
2021-06-08 01:20:20 +00:00
|
|
|
# ------------------------------------------------------------
|
2022-08-22 06:31:32 +00:00
|
|
|
# ? << Early setup & environment variables setup
|
2021-06-08 01:20:20 +00:00
|
|
|
# --
|
2021-02-23 19:03:01 +00:00
|
|
|
# ? >> Registering functions
|
2021-06-08 01:20:20 +00:00
|
|
|
# ------------------------------------------------------------
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
function _register_functions
|
2020-09-23 08:21:37 +00:00
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'info' 'Initializing setup'
|
|
|
|
_log 'debug' 'Registering functions'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# ? >> Checks
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_check_function '_check_hostname'
|
2022-03-21 06:07:52 +00:00
|
|
|
_register_check_function '_check_log_level'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# ? >> Setup
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_setup_function '_setup_file_permissions'
|
2022-08-22 06:31:32 +00:00
|
|
|
_register_setup_function '_setup_timezone'
|
2022-04-06 14:48:41 +00:00
|
|
|
|
2020-09-23 08:21:37 +00:00
|
|
|
if [[ ${SMTP_ONLY} -ne 1 ]]
|
|
|
|
then
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_setup_function '_setup_dovecot'
|
|
|
|
_register_setup_function '_setup_dovecot_dhparam'
|
|
|
|
_register_setup_function '_setup_dovecot_quota'
|
|
|
|
fi
|
|
|
|
|
2022-08-22 06:31:32 +00:00
|
|
|
case "${ACCOUNT_PROVISIONER}" in
|
|
|
|
( 'FILE' )
|
|
|
|
_register_setup_function '_setup_dovecot_local_user'
|
|
|
|
;;
|
|
|
|
|
|
|
|
( 'LDAP' )
|
|
|
|
_environment_variables_ldap
|
|
|
|
_register_setup_function '_setup_ldap'
|
|
|
|
;;
|
|
|
|
|
|
|
|
( 'OIDC' )
|
|
|
|
_register_setup_function '_setup_oidc'
|
|
|
|
;;
|
|
|
|
|
|
|
|
( * )
|
|
|
|
_shutdown "'${ACCOUNT_PROVISIONER}' is not a valid value for ACCOUNT_PROVISIONER"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ ${ENABLE_SASLAUTHD} -eq 1 ]]
|
|
|
|
then
|
|
|
|
_environment_variables_saslauthd
|
|
|
|
_register_setup_function '_setup_saslauthd'
|
|
|
|
fi
|
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
[[ ${ENABLE_POSTGREY} -eq 1 ]] && _register_setup_function '_setup_postgrey'
|
2022-01-05 23:53:18 +00:00
|
|
|
[[ ${POSTFIX_INET_PROTOCOLS} != 'all' ]] && _register_setup_function '_setup_postfix_inet_protocols'
|
|
|
|
[[ ${DOVECOT_INET_PROTOCOLS} != 'all' ]] && _register_setup_function '_setup_dovecot_inet_protocols'
|
2021-04-18 10:55:43 +00:00
|
|
|
[[ ${ENABLE_FAIL2BAN} -eq 1 ]] && _register_setup_function '_setup_fail2ban'
|
2022-01-03 21:03:46 +00:00
|
|
|
[[ ${ENABLE_DNSBL} -eq 0 ]] && _register_setup_function '_setup_dnsbl_disable'
|
2022-03-03 15:17:01 +00:00
|
|
|
[[ ${CLAMAV_MESSAGE_SIZE_LIMIT} != '25M' ]] && _register_setup_function '_setup_clamav_sizelimit'
|
2023-01-05 07:39:00 +00:00
|
|
|
[[ ${ENABLE_RSPAMD} -eq 1 ]] && _register_setup_function '_setup_rspamd'
|
2021-02-23 19:03:01 +00:00
|
|
|
|
2023-01-25 09:28:59 +00:00
|
|
|
_register_setup_function '_setup_dkim_dmarc'
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_setup_function '_setup_ssl'
|
|
|
|
_register_setup_function '_setup_docker_permit'
|
|
|
|
_register_setup_function '_setup_mailname'
|
|
|
|
_register_setup_function '_setup_amavis'
|
|
|
|
_register_setup_function '_setup_dmarc_hostname'
|
|
|
|
_register_setup_function '_setup_postfix_hostname'
|
|
|
|
_register_setup_function '_setup_dovecot_hostname'
|
|
|
|
_register_setup_function '_setup_postfix_smtputf8'
|
|
|
|
_register_setup_function '_setup_postfix_sasl'
|
|
|
|
_register_setup_function '_setup_security_stack'
|
|
|
|
_register_setup_function '_setup_postfix_aliases'
|
|
|
|
_register_setup_function '_setup_postfix_vhost'
|
|
|
|
_register_setup_function '_setup_postfix_dhparam'
|
|
|
|
_register_setup_function '_setup_postfix_postscreen'
|
|
|
|
_register_setup_function '_setup_postfix_sizelimits'
|
2019-09-15 16:29:46 +00:00
|
|
|
|
2021-01-19 11:31:45 +00:00
|
|
|
# needs to come after _setup_postfix_aliases
|
2021-02-23 19:03:01 +00:00
|
|
|
[[ ${SPOOF_PROTECTION} -eq 1 ]] && _register_setup_function '_setup_spoof_protection'
|
2018-03-18 18:52:28 +00:00
|
|
|
|
2022-03-27 07:43:39 +00:00
|
|
|
if [[ ${ENABLE_FETCHMAIL} -eq 1 ]]
|
|
|
|
then
|
|
|
|
_register_setup_function '_setup_fetchmail'
|
|
|
|
[[ ${FETCHMAIL_PARALLEL} -eq 1 ]] && _register_setup_function '_setup_fetchmail_parallel'
|
|
|
|
fi
|
|
|
|
|
2020-09-23 08:21:37 +00:00
|
|
|
if [[ ${ENABLE_SRS} -eq 1 ]]
|
|
|
|
then
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_setup_function '_setup_SRS'
|
2022-03-27 07:43:39 +00:00
|
|
|
_register_start_daemon '_start_daemon_postsrsd'
|
2020-09-23 08:21:37 +00:00
|
|
|
fi
|
2019-09-15 13:40:05 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_setup_function '_setup_postfix_access_control'
|
2021-11-20 20:33:49 +00:00
|
|
|
_register_setup_function '_setup_postfix_relay_hosts'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2023-01-15 05:33:31 +00:00
|
|
|
[[ -n ${POSTFIX_DAGENT} ]] && _register_setup_function '_setup_postfix_virtual_transport'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_setup_function '_setup_postfix_override_configuration'
|
|
|
|
_register_setup_function '_setup_logrotate'
|
|
|
|
_register_setup_function '_setup_mail_summary'
|
|
|
|
_register_setup_function '_setup_logwatch'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# ? >> Fixes
|
2017-02-07 19:53:34 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_fix_function '_fix_var_mail_permissions'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
[[ ${ENABLE_CLAMAV} -eq 0 ]] && _register_fix_function '_fix_cleanup_clamav'
|
|
|
|
[[ ${ENABLE_SPAMASSASSIN} -eq 0 ]] && _register_fix_function '_fix_cleanup_spamassassin'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# ? >> Miscellaneous
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_misc_function '_misc_save_states'
|
2022-08-22 06:31:32 +00:00
|
|
|
_register_setup_function '_environment_variables_export'
|
2017-02-06 09:21:18 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# ? >> Daemons
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2022-03-27 07:43:39 +00:00
|
|
|
_register_start_daemon '_start_daemon_cron'
|
|
|
|
_register_start_daemon '_start_daemon_rsyslog'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2022-03-27 07:43:39 +00:00
|
|
|
[[ ${SMTP_ONLY} -ne 1 ]] && _register_start_daemon '_start_daemon_dovecot'
|
|
|
|
[[ ${ENABLE_UPDATE_CHECK} -eq 1 ]] && _register_start_daemon '_start_daemon_update_check'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2023-01-05 07:39:00 +00:00
|
|
|
if [[ ${ENABLE_RSPAMD} -eq 1 ]]
|
|
|
|
then
|
|
|
|
_register_start_daemon '_start_daemon_redis'
|
2023-01-25 09:28:59 +00:00
|
|
|
_register_start_daemon '_start_daemon_rspamd'
|
2023-01-05 07:39:00 +00:00
|
|
|
fi
|
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# needs to be started before SASLauthd
|
2023-01-25 09:28:59 +00:00
|
|
|
[[ ${ENABLE_OPENDKIM} -eq 1 ]] && _register_start_daemon '_start_daemon_opendkim'
|
|
|
|
[[ ${ENABLE_OPENDMARC} -eq 1 ]] && _register_start_daemon '_start_daemon_opendmarc'
|
2016-12-01 14:45:40 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# needs to be started before postfix
|
2022-03-27 07:43:39 +00:00
|
|
|
[[ ${ENABLE_POSTGREY} -eq 1 ]] && _register_start_daemon '_start_daemon_postgrey'
|
2020-09-23 08:21:37 +00:00
|
|
|
|
2022-03-27 07:43:39 +00:00
|
|
|
_register_start_daemon '_start_daemon_postfix'
|
2020-09-23 08:21:37 +00:00
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# needs to be started after postfix
|
2022-03-27 07:43:39 +00:00
|
|
|
[[ ${ENABLE_SASLAUTHD} -eq 1 ]] && _register_start_daemon '_start_daemon_saslauthd'
|
|
|
|
[[ ${ENABLE_FAIL2BAN} -eq 1 ]] && _register_start_daemon '_start_daemon_fail2ban'
|
|
|
|
[[ ${ENABLE_FETCHMAIL} -eq 1 ]] && _register_start_daemon '_start_daemon_fetchmail'
|
|
|
|
[[ ${ENABLE_CLAMAV} -eq 1 ]] && _register_start_daemon '_start_daemon_clamav'
|
2022-08-22 06:31:32 +00:00
|
|
|
[[ ${ACCOUNT_PROVISIONER} == 'FILE' ]] && _register_start_daemon '_start_daemon_changedetector'
|
2022-03-27 07:43:39 +00:00
|
|
|
[[ ${ENABLE_AMAVIS} -eq 1 ]] && _register_start_daemon '_start_daemon_amavis'
|
2016-12-01 14:45:40 +00:00
|
|
|
}
|
2020-09-23 08:21:37 +00:00
|
|
|
|
2020-10-02 13:45:57 +00:00
|
|
|
function _register_start_daemon
|
2020-09-23 08:21:37 +00:00
|
|
|
{
|
|
|
|
DAEMONS_START+=("${1}")
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "${1}() registered"
|
2016-12-01 14:45:40 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 13:45:57 +00:00
|
|
|
function _register_setup_function
|
2020-09-23 08:21:37 +00:00
|
|
|
{
|
|
|
|
FUNCS_SETUP+=("${1}")
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "${1}() registered"
|
2016-12-01 14:45:40 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 13:45:57 +00:00
|
|
|
function _register_fix_function
|
2020-09-23 08:21:37 +00:00
|
|
|
{
|
|
|
|
FUNCS_FIX+=("${1}")
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "${1}() registered"
|
2016-12-01 14:45:40 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 13:45:57 +00:00
|
|
|
function _register_check_function
|
2020-09-23 08:21:37 +00:00
|
|
|
{
|
|
|
|
FUNCS_CHECK+=("${1}")
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "${1}() registered"
|
2016-12-01 14:45:40 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 13:45:57 +00:00
|
|
|
function _register_misc_function
|
2020-09-23 08:21:37 +00:00
|
|
|
{
|
|
|
|
FUNCS_MISC+=("${1}")
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "${1}() registered"
|
2016-12-01 14:45:40 +00:00
|
|
|
}
|
2020-09-23 08:21:37 +00:00
|
|
|
|
2021-06-08 01:20:20 +00:00
|
|
|
# ------------------------------------------------------------
|
2021-02-23 19:03:01 +00:00
|
|
|
# ? << Registering functions
|
2021-06-08 01:20:20 +00:00
|
|
|
# --
|
2022-05-15 21:37:21 +00:00
|
|
|
# ? >> Executing all stacks / actual start of DMS
|
2021-06-08 01:20:20 +00:00
|
|
|
# ------------------------------------------------------------
|
2020-12-08 14:07:01 +00:00
|
|
|
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'info' "Welcome to docker-mailserver $(</VERSION)"
|
2020-12-08 14:07:01 +00:00
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
_register_functions
|
|
|
|
_check
|
|
|
|
_setup
|
2022-03-21 06:07:52 +00:00
|
|
|
[[ ${LOG_LEVEL} =~ (debug|trace) ]] && print-environment
|
2022-05-15 21:37:21 +00:00
|
|
|
_apply_fixes
|
|
|
|
_start_misc
|
2022-10-14 23:11:29 +00:00
|
|
|
_setup_user_patches
|
2022-03-27 07:43:39 +00:00
|
|
|
_start_daemons
|
2020-12-08 14:29:49 +00:00
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
# marker to check if container was restarted
|
2022-03-17 10:24:30 +00:00
|
|
|
date >/CONTAINER_START
|
2022-01-07 23:25:09 +00:00
|
|
|
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'info' "${HOSTNAME} is up and running"
|
2016-12-23 22:56:39 +00:00
|
|
|
|
2017-08-07 15:39:40 +00:00
|
|
|
touch /var/log/mail/mail.log
|
2021-05-17 12:54:43 +00:00
|
|
|
tail -Fn 0 /var/log/mail/mail.log
|
2016-12-01 14:45:40 +00:00
|
|
|
|
|
|
|
exit 0
|