2022-10-17 08:40:09 +00:00
|
|
|
#!/bin/bash
|
2015-03-28 14:59:15 +00:00
|
|
|
|
2023-02-27 22:37:35 +00:00
|
|
|
shopt -s globstar
|
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
# ------------------------------------------------------------
|
2022-03-21 12:42:12 +00:00
|
|
|
# ? >> Sourcing helpers & stacks
|
|
|
|
# ------------------------------------------------------------
|
|
|
|
|
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
|
|
|
|
2023-02-26 10:42:14 +00:00
|
|
|
# shellcheck source=./startup/variables-stack.sh
|
|
|
|
source /usr/local/bin/variables-stack.sh
|
|
|
|
|
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/daemons-stack.sh
|
|
|
|
source /usr/local/bin/daemons-stack.sh
|
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
# ------------------------------------------------------------
|
|
|
|
# ? << Sourcing helpers & stacks
|
|
|
|
# --
|
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 '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
|
|
|
|
2023-03-01 15:33:54 +00:00
|
|
|
_register_check_function '_check_improper_restart'
|
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' )
|
2023-02-26 10:42:14 +00:00
|
|
|
_shutdown 'OIDC user account provisioning is not yet implemented'
|
2022-08-22 06:31:32 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
( * )
|
|
|
|
_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
|
|
|
|
|
2023-02-28 09:25:23 +00:00
|
|
|
_register_setup_function '_setup_postfix_inet_protocols'
|
|
|
|
_register_setup_function '_setup_dovecot_inet_protocols'
|
2021-02-23 19:03:01 +00:00
|
|
|
|
2023-02-27 19:21:45 +00:00
|
|
|
_register_setup_function '_setup_opendkim'
|
|
|
|
_register_setup_function '_setup_opendmarc' # must come after `_setup_opendkim`
|
|
|
|
|
|
|
|
_register_setup_function '_setup_security_stack'
|
|
|
|
_register_setup_function '_setup_rspamd'
|
|
|
|
|
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_dovecot_hostname'
|
2023-02-27 19:21:45 +00:00
|
|
|
|
|
|
|
_register_setup_function '_setup_postfix_hostname'
|
2021-02-23 19:03:01 +00:00
|
|
|
_register_setup_function '_setup_postfix_smtputf8'
|
|
|
|
_register_setup_function '_setup_postfix_sasl'
|
|
|
|
_register_setup_function '_setup_postfix_aliases'
|
|
|
|
_register_setup_function '_setup_postfix_vhost'
|
|
|
|
_register_setup_function '_setup_postfix_dhparam'
|
|
|
|
_register_setup_function '_setup_postfix_sizelimits'
|
2023-02-28 09:25:23 +00:00
|
|
|
_register_setup_function '_setup_fetchmail'
|
|
|
|
_register_setup_function '_setup_fetchmail_parallel'
|
2019-09-15 16:29:46 +00:00
|
|
|
|
2021-01-19 11:31:45 +00:00
|
|
|
# needs to come after _setup_postfix_aliases
|
2023-02-27 19:21:45 +00:00
|
|
|
_register_setup_function '_setup_spoof_protection'
|
2022-03-27 07:43:39 +00:00
|
|
|
|
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'
|
2023-02-28 09:25:23 +00:00
|
|
|
_register_setup_function '_setup_postfix_virtual_transport'
|
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
|
|
|
|
2023-02-27 19:21:45 +00:00
|
|
|
_register_setup_function '_setup_save_states'
|
|
|
|
_register_setup_function '_setup_apply_fixes_after_configuration'
|
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
|
|
|
|
2023-02-27 19:21:45 +00:00
|
|
|
[[ ${SMTP_ONLY} -ne 1 ]] && _register_start_daemon '_start_daemon_dovecot'
|
2023-03-01 15:24:59 +00:00
|
|
|
|
|
|
|
[[ ${ENABLE_UPDATE_CHECK} -eq 1 ]] && _register_start_daemon '_start_daemon_update_check'
|
|
|
|
[[ ${ENABLE_REDIS} -eq 1 ]] && _register_start_daemon '_start_daemon_rspamd'
|
|
|
|
[[ ${ENABLE_RSPAMD} -eq 1 ]] && _register_start_daemon '_start_daemon_redis'
|
2023-02-27 19:21:45 +00:00
|
|
|
[[ ${ENABLE_UPDATE_CHECK} -eq 1 ]] && _register_start_daemon '_start_daemon_update_check'
|
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
# needs to be started before SASLauthd
|
2023-02-27 19:21:45 +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
|
2023-02-27 19:21:45 +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
|
2023-02-27 19:21:45 +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'
|
|
|
|
[[ ${ENABLE_AMAVIS} -eq 1 ]] && _register_start_daemon '_start_daemon_amavis'
|
2023-02-18 14:51:28 +00:00
|
|
|
[[ ${ACCOUNT_PROVISIONER} == 'FILE' ]] && _register_start_daemon '_start_daemon_changedetector'
|
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
|
|
|
|
2023-02-28 09:25:23 +00:00
|
|
|
_early_supervisor_setup
|
|
|
|
_early_variables_setup
|
|
|
|
|
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
|
2023-02-28 09:25:23 +00:00
|
|
|
_run_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
|