Change 'function' style (#3364)

This commit is contained in:
Casper 2023-05-26 01:01:41 +02:00 committed by GitHub
parent cf74127f78
commit 37ca0f9ba9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 233 additions and 466 deletions

View file

@ -6,8 +6,7 @@
#
# The OpenDKIM milter must come before the OpenDMARC milter in Postfix's
# `smtpd_milters` milters options.
function _setup_opendkim
{
function _setup_opendkim() {
if [[ ${ENABLE_OPENDKIM} -eq 1 ]]; then
_log 'debug' 'Configuring DKIM'
@ -54,8 +53,7 @@ function _setup_opendkim
#
# The OpenDMARC milter must come after the OpenDKIM milter in Postfix's
# `smtpd_milters` milters options.
function _setup_opendmarc
{
function _setup_opendmarc() {
if [[ ${ENABLE_OPENDMARC} -eq 1 ]]; then
# TODO When disabling SPF is possible, add a check whether DKIM and SPF is disabled
# for DMARC to work, you should have at least one enabled
@ -83,8 +81,7 @@ function _setup_opendmarc
# Configures the SPF check inside Postfix's configuration via policyd-spf. When
# using Rspamd, you will likely want to turn that off.
function _setup_policyd_spf
{
function _setup_policyd_spf() {
if [[ ${ENABLE_POLICYD_SPF} -eq 1 ]]; then
_log 'debug' 'Configuring policyd-spf'
cat >>/etc/postfix/master.cf <<EOF

View file

@ -1,7 +1,6 @@
#!/bin/bash
function _setup_dovecot
{
function _setup_dovecot() {
_log 'debug' 'Setting up Dovecot'
cp -a /usr/share/dovecot/protocols.d /etc/dovecot/
@ -46,8 +45,7 @@ function _setup_dovecot
[[ -f /tmp/docker-mailserver/dovecot.cf ]] && cp /tmp/docker-mailserver/dovecot.cf /etc/dovecot/local.conf
}
function _setup_dovecot_sieve
{
function _setup_dovecot_sieve() {
mkdir -p /usr/lib/dovecot/sieve-{filter,global,pipe}
mkdir -p /usr/lib/dovecot/sieve-global/{before,after}
@ -83,8 +81,7 @@ function _setup_dovecot_sieve
find /usr/lib/dovecot/sieve-{filter,pipe} -type f -exec chmod +x {} +
}
function _setup_dovecot_quota
{
function _setup_dovecot_quota() {
_log 'debug' 'Setting up Dovecot quota'
# Dovecot quota is disabled when using LDAP or SMTP_ONLY or when explicitly disabled.
@ -136,8 +133,7 @@ function _setup_dovecot_quota
fi
}
function _setup_dovecot_local_user
{
function _setup_dovecot_local_user() {
[[ ${SMTP_ONLY} -eq 1 ]] && return 0
[[ ${ACCOUNT_PROVISIONER} == 'FILE' ]] || return 0
@ -147,8 +143,7 @@ function _setup_dovecot_local_user
_log 'trace' "No mail accounts to create - '/tmp/docker-mailserver/postfix-accounts.cf' is missing"
fi
function __wait_until_an_account_is_added_or_shutdown
{
function __wait_until_an_account_is_added_or_shutdown() {
local SLEEP_PERIOD='10'
for (( COUNTER = 11 ; COUNTER >= 0 ; COUNTER-- ))
@ -169,8 +164,7 @@ function _setup_dovecot_local_user
_create_accounts
}
function _setup_dovecot_inet_protocols
{
function _setup_dovecot_inet_protocols() {
[[ ${DOVECOT_INET_PROTOCOLS} == 'all' ]] && return 0
_log 'trace' 'Setting up DOVECOT_INET_PROTOCOLS option'
@ -189,13 +183,11 @@ function _setup_dovecot_inet_protocols
sedfile -i "s|^#listen =.*|listen = ${PROTOCOL}|g" /etc/dovecot/dovecot.conf
}
function _setup_dovecot_dhparam
{
function _setup_dovecot_dhparam() {
_setup_dhparam 'Dovecot' '/etc/dovecot/dh.pem'
}
function _setup_dovecot_hostname
{
function _setup_dovecot_hostname() {
_log 'debug' 'Applying hostname to Dovecot'
sed -i "s|^#hostname =.*$|hostname = '${HOSTNAME}'|g" /etc/dovecot/conf.d/15-lda.conf
}

View file

@ -1,7 +1,6 @@
#!/bin/bash
function _setup_fetchmail
{
function _setup_fetchmail() {
if [[ ${ENABLE_FETCHMAIL} -eq 1 ]]; then
_log 'trace' 'Enabling and configuring Fetchmail'
@ -23,8 +22,7 @@ function _setup_fetchmail
fi
}
function _setup_fetchmail_parallel
{
function _setup_fetchmail_parallel() {
if [[ ${FETCHMAIL_PARALLEL} -eq 1 ]]; then
_log 'trace' 'Enabling and configuring Fetchmail parallel'
mkdir /etc/fetchmailrc.d/
@ -35,8 +33,7 @@ function _setup_fetchmail_parallel
#
# The sole purpose for this is to work around what is known
# as the Fetchmail IMAP idle issue.
function _fetchmailrc_split
{
function _fetchmailrc_split() {
local FETCHMAILRC='/etc/fetchmailrc'
local FETCHMAILRCD='/etc/fetchmailrc.d'
local DEFAULT_FILE="${FETCHMAILRCD}/defaults"

View file

@ -1,7 +1,6 @@
#!/bin/bash
function _setup_getmail
{
function _setup_getmail() {
if [[ ${ENABLE_GETMAIL} -eq 1 ]]; then
_log 'trace' 'Preparing Getmail configuration'

View file

@ -1,7 +1,6 @@
#!/bin/bash
function _setup_ldap
{
function _setup_ldap() {
_log 'debug' 'Setting up LDAP'
_log 'trace' 'Checking for custom configs'

View file

@ -1,7 +1,6 @@
#!/bin/bash
function _setup_logs_general
{
function _setup_logs_general() {
_log 'debug' 'Setting up general log files'
# File/folder permissions are fine when using docker volumes, but may be wrong
@ -11,8 +10,7 @@ function _setup_logs_general
chown syslog:root /var/log/mail
}
function _setup_logrotate
{
function _setup_logrotate() {
_log 'debug' 'Setting up logrotate'
LOGROTATE='/var/log/mail/mail.log\n{\n compress\n copytruncate\n delaycompress\n'
@ -42,8 +40,7 @@ function _setup_logrotate
echo -e "${LOGROTATE}}" >/etc/logrotate.d/maillog
}
function _setup_mail_summary
{
function _setup_mail_summary() {
local ENABLED_MESSAGE
ENABLED_MESSAGE="Enabling Postfix log summary reports with recipient '${PFLOGSUMM_RECIPIENT}'"
@ -80,8 +77,7 @@ EOF
esac
}
function _setup_logwatch
{
function _setup_logwatch() {
echo 'LogFile = /var/log/mail/freshclam.log' >>/etc/logwatch/conf/logfiles/clam-update.conf
echo "MailFrom = ${LOGWATCH_SENDER}" >>/etc/logwatch/conf/logwatch.conf
echo "Mailer = \"sendmail -t -f ${LOGWATCH_SENDER}\"" >>/etc/logwatch/conf/logwatch.conf

View file

@ -2,8 +2,7 @@
# Consolidate all states into a single directory
# (/var/mail-state) to allow persistence using docker volumes
function _setup_save_states
{
function _setup_save_states() {
local DEST DESTDIR STATEDIR SERVICEDIR SERVICEDIRS SERVICEFILE SERVICEFILES
STATEDIR='/var/mail-state'

View file

@ -1,13 +1,11 @@
#!/bin/bash
function _setup_mailname
{
function _setup_mailname() {
_log 'debug' "Setting up mailname and creating '/etc/mailname'"
echo "${DOMAINNAME}" >/etc/mailname
}
function _setup_docker_permit
{
function _setup_docker_permit() {
_log 'debug' 'Setting up PERMIT_DOCKER option'
local CONTAINER_IP CONTAINER_NETWORK
@ -29,14 +27,12 @@ function _setup_docker_permit
CONTAINER_NETWORKS+=("${IP}")
done < <(ip -o -4 addr show type veth | grep -E -o '[0-9\.]+/[0-9]+')
function __clear_postfix_mynetworks
{
function __clear_postfix_mynetworks() {
_log 'trace' "Clearing Postfix's 'mynetworks'"
postconf "mynetworks ="
}
function __add_to_postfix_mynetworks
{
function __add_to_postfix_mynetworks() {
local NETWORK_TYPE=$1
local NETWORK=$2

View file

@ -7,8 +7,7 @@
# @param ${2} = message
function __postfix__log { _log "${1:-}" "(Postfix setup) ${2:-}" ; }
function _setup_postfix_early
{
function _setup_postfix_early() {
_log 'debug' 'Configuring Postfix (early setup)'
__postfix__log 'trace' 'Applying hostname and domainname'
@ -66,8 +65,7 @@ EOF
fi
}
function _setup_postfix_late
{
function _setup_postfix_late() {
_log 'debug' 'Configuring Postfix (late setup)'
__postfix__log 'trace' 'Configuring user access'
@ -91,8 +89,7 @@ function _setup_postfix_late
__postfix__setup_override_configuration
}
function __postfix__setup_override_configuration
{
function __postfix__setup_override_configuration() {
__postfix__log 'debug' 'Overriding / adjusting configuration with user-supplied values'
if [[ -f /tmp/docker-mailserver/postfix-main.cf ]]; then
@ -122,8 +119,7 @@ function __postfix__setup_override_configuration
fi
}
function _setup_SRS
{
function _setup_SRS() {
_log 'debug' 'Setting up SRS'
postconf 'sender_canonical_maps = tcp:localhost:10001'
@ -131,8 +127,7 @@ function _setup_SRS
postconf 'recipient_canonical_maps = tcp:localhost:10002'
postconf 'recipient_canonical_classes = envelope_recipient,header_recipient'
function __generate_secret
{
function __generate_secret() {
(
umask 0077
dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64 -w0 >"${1}"

View file

@ -1,8 +1,7 @@
#!/bin/bash
function _setup_saslauthd
{
function _setup_saslauthd() {
_log 'debug' 'Setting up SASLAUTHD'
if [[ ! -f /etc/saslauthd.conf ]]; then

View file

@ -1,7 +1,6 @@
#!/bin/bash
function _setup_security_stack
{
function _setup_security_stack() {
_log 'debug' 'Setting up Security Stack'
__setup__security__postgrey
@ -23,8 +22,7 @@ function _setup_security_stack
__setup__security__amavis
}
function __setup__security__postgrey
{
function __setup__security__postgrey() {
if [[ ${ENABLE_POSTGREY} -eq 1 ]]; then
_log 'debug' 'Enabling and configuring Postgrey'
@ -52,8 +50,7 @@ function __setup__security__postgrey
fi
}
function __setup__security__postscreen
{
function __setup__security__postscreen() {
_log 'debug' 'Configuring Postscreen'
sed -i \
-e "s|postscreen_dnsbl_action = enforce|postscreen_dnsbl_action = ${POSTSCREEN_ACTION}|" \
@ -69,8 +66,7 @@ function __setup__security__postscreen
fi
}
function __setup__security__spamassassin
{
function __setup__security__spamassassin() {
if [[ ${ENABLE_SPAMASSASSIN} -eq 1 ]]; then
_log 'debug' 'Enabling and configuring SpamAssassin'
@ -157,8 +153,7 @@ EOF
fi
}
function __setup__security__clamav
{
function __setup__security__clamav() {
if [[ ${ENABLE_CLAMAV} -eq 1 ]]; then
_log 'debug' 'Enabling and configuring ClamAV'
@ -197,8 +192,7 @@ function __setup__security__clamav
fi
}
function __setup__security__fail2ban
{
function __setup__security__fail2ban() {
if [[ ${ENABLE_FAIL2BAN} -eq 1 ]]; then
_log 'debug' 'Enabling and configuring Fail2Ban'
@ -221,8 +215,7 @@ function __setup__security__fail2ban
fi
}
function __setup__security__amavis
{
function __setup__security__amavis() {
if [[ ${ENABLE_AMAVIS} -eq 1 ]]; then
_log 'debug' 'Configuring Amavis'
if [[ -f /tmp/docker-mailserver/amavis.cf ]]; then
@ -257,8 +250,7 @@ function __setup__security__amavis
}
# We can use Sieve to move spam emails to the "Junk" folder.
function _setup_spam_to_junk
{
function _setup_spam_to_junk() {
if [[ ${MOVE_SPAM_TO_JUNK} -eq 1 ]]; then
_log 'debug' 'Spam emails will be moved to the Junk folder'
cat >/usr/lib/dovecot/sieve-global/after/spam_to_junk.sieve << EOF

View file

@ -1,8 +1,7 @@
#!/bin/bash
# Function called during global setup to handle the complete setup of Rspamd.
function _setup_rspamd
{
function _setup_rspamd() {
if _env_var_expect_zero_or_one 'ENABLE_RSPAMD' && [[ ${ENABLE_RSPAMD} -eq 1 ]]; then
_log 'debug' 'Enabling and configuring Rspamd'
__rspamd__log 'trace' '---------- Setup started ----------'
@ -36,8 +35,7 @@ function __rspamd__log { _log "${1:-}" "(Rspamd setup) ${2:-}" ; }
# @param ${2} = `true` when you want to enable the module (default),
# `false` when you want to disable the module [OPTIONAL]
# @param ${3} = whether to use `local` (default) or `override` [OPTIONAL]
function __rspamd__helper__enable_disable_module
{
function __rspamd__helper__enable_disable_module() {
local MODULE=${1:?Module name must be provided}
local ENABLE_MODULE=${2:-true}
local LOCAL_OR_OVERRIDE=${3:-local}
@ -61,8 +59,7 @@ EOF
# Run miscellaneous early setup tasks and checks, such as creating files needed at runtime
# or checking for other anti-spam/anti-virus software.
function __rspamd__run_early_setup_and_checks
{
function __rspamd__run_early_setup_and_checks() {
# Note: Variables not marked with `local` are
# used in other functions as well.
RSPAMD_LOCAL_D='/etc/rspamd/local.d'
@ -105,8 +102,7 @@ function __rspamd__run_early_setup_and_checks
# Sets up Redis. In case the user does not use a dedicated Redis instance, we
# supply a configuration for our local Redis instance which is started later.
function __rspamd__setup_redis
{
function __rspamd__setup_redis() {
if _env_var_expect_zero_or_one 'ENABLE_RSPAMD_REDIS' && [[ ${ENABLE_RSPAMD_REDIS} -eq 1 ]]; then
__rspamd__log 'debug' 'Internal Redis is enabled, adding configuration'
cat >"${RSPAMD_LOCAL_D}/redis.conf" << "EOF"
@ -136,8 +132,7 @@ EOF
# Adjust Postfix's configuration files. We only need to append Rspamd at the end of
# `smtpd_milters` in `/etc/postfix/main.cf`.
function __rspamd__setup_postfix
{
function __rspamd__setup_postfix() {
__rspamd__log 'debug' "Adjusting Postfix's configuration"
postconf 'rspamd_milter = inet:localhost:11332'
@ -146,8 +141,7 @@ function __rspamd__setup_postfix
}
# If ClamAV is enabled, we will integrate it into Rspamd.
function __rspamd__setup_clamav
{
function __rspamd__setup_clamav() {
if _env_var_expect_zero_or_one 'ENABLE_CLAMAV' && [[ ${ENABLE_CLAMAV} -eq 1 ]]; then
__rspamd__log 'debug' 'Enabling ClamAV integration'
sedfile -i -E 's|^(enabled).*|\1 = true;|g' "${RSPAMD_LOCAL_D}/antivirus.conf"
@ -169,8 +163,7 @@ function __rspamd__setup_clamav
# We disable the modules listed in `DISABLE_MODULES` as we believe these modules
# are not commonly used and the average user does not need them. As a consequence,
# disabling them saves resources.
function __rspamd__setup_default_modules
{
function __rspamd__setup_default_modules() {
__rspamd__log 'debug' 'Disabling default modules'
# This array contains all the modules we disable by default. They
@ -197,8 +190,7 @@ function __rspamd__setup_default_modules
# 1. enabling auto-learn for the classifier-bayes module
# 2. setting up sieve scripts that detect when a user is moving e-mail
# from or to the "Junk" folder, and learning them as ham or spam.
function __rspamd__setup_learning
{
function __rspamd__setup_learning() {
if _env_var_expect_zero_or_one 'RSPAMD_LEARN' && [[ ${RSPAMD_LEARN} -eq 1 ]]; then
__rspamd__log 'debug' 'Setting up intelligent learning of spam and ham'
@ -241,8 +233,7 @@ EOF
# Sets up greylisting with the greylisting module (see
# https://rspamd.com/doc/modules/greylisting.html).
function __rspamd__setup_greylisting
{
function __rspamd__setup_greylisting() {
if _env_var_expect_zero_or_one 'RSPAMD_GREYLISTING' && [[ ${RSPAMD_GREYLISTING} -eq 1 ]]; then
__rspamd__log 'debug' 'Enabling greylisting'
sedfile -i -E "s|(enabled =).*|\1 true;|g" "${RSPAMD_LOCAL_D}/greylist.conf"
@ -255,8 +246,7 @@ function __rspamd__setup_greylisting
# https://www.rspamd.com/doc/modules/hfilter.html). This module is mainly
# used for hostname checks, and whether or not a reverse-DNS check
# succeeds.
function __rspamd__setup_hfilter_group
{
function __rspamd__setup_hfilter_group() {
local MODULE_FILE="${RSPAMD_LOCAL_D}/hfilter_group.conf"
if _env_var_expect_zero_or_one 'RSPAMD_HFILTER' && [[ ${RSPAMD_HFILTER} -eq 1 ]]; then
__rspamd__log 'debug' 'Hfilter (group) module is enabled'
@ -278,8 +268,7 @@ function __rspamd__setup_hfilter_group
# Parses `RSPAMD_CUSTOM_COMMANDS_FILE` and executed the directives given by the file.
# To get a detailed explanation of the commands and how the file works, visit
# https://docker-mailserver.github.io/docker-mailserver/edge/config/security/rspamd/#with-the-help-of-a-custom-file
function __rspamd__handle_user_modules_adjustments
{
function __rspamd__handle_user_modules_adjustments() {
# Adds an option with a corresponding value to a module, or, in case the option
# is already present, overwrites it.
#
@ -293,8 +282,7 @@ function __rspamd__handle_user_modules_adjustments
# While this function is currently bound to the scope of `__rspamd__handle_user_modules_adjustments`,
# it is written in a versatile way (taking 4 arguments instead of assuming `ARGUMENT2` / `ARGUMENT3`
# are set) so that it may be used elsewhere if needed.
function __add_or_replace
{
function __add_or_replace() {
local MODULE_FILE=${1:?Module file name must be provided}
local MODULE_LOG_NAME=${2:?Module log name must be provided}
local OPTION=${3:?Option name must be provided}

View file

@ -1,7 +1,6 @@
#!/bin/bash
function _setup_spoof_protection
{
function _setup_spoof_protection() {
if [[ ${SPOOF_PROTECTION} -eq 1 ]]; then
_log 'trace' 'Enabling and configuring spoof protection'