From 38c7ce8f6a8939e29630111e837e961cf6989250 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 24 Nov 2026 15:12:45 +0100 Subject: [PATCH] install_update_dovecot-2.4.sh: make provided mail services selectable - New config parameter 'mail_protocols' (blank separated list of imap, pop3, sieve; defaults to "imap pop3 sieve"). lmtp is always enabled. - New selection menu at install/update time: [1] all common mail services (imap pop3 sieve) [2] all common except pop3 (imap sieve) [3] other (follow-up input, preset with an individual list from the configuration file) The line matching the configuration file is highlighted. - 'protocols' block is built from the selection; not selected protocols and dovecot's submission service are set to 'no'. - Dovecot's submission service is no longer configured: submission (587/465) is provided by postfix. 'service submission-login' and 'service submission' blocks are removed from 10-master.conf. - 'service pop3-login' / 'service pop3' are only written if pop3 is selected, otherwise removed. - Summary lists each protocol with its state; listener addresses are only shown for enabled protocols. 'mail_protocols' is written to the environment file. - Helper functions call 'gawk' explicitly (they need GNU awk extensions like '\s'; mawk silently fails). gawk is installed for update and new installation, abort if that fails. - Fix apt-get calls: '2&>1' -> '2>&1', add '-y', append to log. - conf/install_update_dovecot.conf.sample: document 'mail_protocols'. Co-Authored-By: Claude Opus 5.5 --- conf/install_update_dovecot.conf.sample | 36 ++ install_update_dovecot-2.4.sh | 620 ++++++++++++++++++++---- 2 files changed, 570 insertions(+), 86 deletions(-) diff --git a/conf/install_update_dovecot.conf.sample b/conf/install_update_dovecot.conf.sample index dae2108..5020d9a 100644 --- a/conf/install_update_dovecot.conf.sample +++ b/conf/install_update_dovecot.conf.sample @@ -69,6 +69,42 @@ ipv6="" #postfix_main_cf="/etc/postfix/main.cf" +# --- +# - Mail services (dovecot protocols) +# --- + +# - mail_protocols +# - +# - Blank separated list of the mail services (dovecot protocols) to provide. +# - +# - Possible values: +# - +# - imap - IMAP (port 143) and IMAPS (port 993) +# - pop3 - POP3 (port 110) and POP3S (port 995) +# - sieve - ManageSieve (port 4190), e.g. used by the roundcube +# - 'managesieve' plugin (filter rules, vacation, ..) +# - +# - Note: +# - 'lmtp' is not part of this list. LMTP is required for delivering mail +# - from postfix into the mailboxes and is therefore always enabled. +# - +# - 'submission' is not part of this list either. In this mailsystem +# - submission (587) and submissions (465) are provided by postfix, so +# - dovecot's submission service is always disabled. +# - +# - The value given here determines which line is highlighted (and taken by +# - pressing ) in the selection menu of the install script: +# - +# - "imap pop3 sieve" --> [1] all common mail services +# - "imap sieve" --> [2] all common mail services except pop3 +# - anything else --> [3] other (the value is offered as default for +# - the following input) +# - +# - Defaults to "imap pop3 sieve" +# - +#mail_protocols="imap pop3 sieve" + + # --- # - Listener configuration # --- diff --git a/install_update_dovecot-2.4.sh b/install_update_dovecot-2.4.sh index 9f7378c..167c03e 100755 --- a/install_update_dovecot-2.4.sh +++ b/install_update_dovecot-2.4.sh @@ -149,6 +149,24 @@ detect_os_1 () { } +# --- +# - Helper functions to edit dovecot's configuration files +# --- +# - +# - !! These functions require GNU awk (gawk) !! +# - +# - They use GNU awk extensions (e.g. '\s' in regular expressions). Therefore +# - 'gawk' is called explicitly - not 'awk'. On Debian 'awk' is usually 'mawk', +# - which does NOT support these extensions: blocks would silently not be +# - found, so nothing gets replaced/deleted, or blocks are appended a second +# - time instead of being replaced. +# - +# - gawk is installed (if missing) before dovecot is configured - see +# - "Check / install GNU awk (gawk)". +# - +# - Simple awk calls elsewhere (e.g. "awk '{print $1}'") only use POSIX awk +# - features and keep using 'awk'. +# - replace_code_block() { local block_name="$1" local new_block="$2" @@ -168,7 +186,7 @@ replace_code_block() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" -v new_block="$new_block" ' + gawk -v block_name="$block_name" -v new_block="$new_block" ' function count_char(str, c) { n = 0 for (i = 1; i <= length(str); i++) { @@ -222,7 +240,7 @@ replace_or_append_code_block() { local block_found=0 - awk -v block_name="$block_name" -v new_block="$new_block" ' + gawk -v block_name="$block_name" -v new_block="$new_block" ' function count_char(str, c) { n = 0 for (i = 1; i <= length(str); i++) { @@ -333,7 +351,7 @@ replace_or_append_code_block_if_keyval() { local block_found=0 - awk -v block_name="$block_name" -v new_block="$new_block" \ + gawk -v block_name="$block_name" -v new_block="$new_block" \ -v req_key="$required_key" -v req_val="$required_value" ' function count_char(str, c) { n = 0 @@ -450,7 +468,7 @@ replace_code_block_if_keyval() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" -v new_block="$new_block" \ + gawk -v block_name="$block_name" -v new_block="$new_block" \ -v req_key="$required_key" -v req_val="$required_value" ' function count_char(str, c) { n = 0 @@ -555,7 +573,7 @@ replace_or_append_code_block_if_keyval_strict() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" -v new_block="$new_block" \ + gawk -v block_name="$block_name" -v new_block="$new_block" \ -v req_key="$required_key" -v req_val="$required_value" ' function count_char(str, c) { n = 0 @@ -660,7 +678,7 @@ delete_code_block() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" ' + gawk -v block_name="$block_name" ' function count_char(str, c) { n = 0 for (i = 1; i <= length(str); i++) { @@ -710,7 +728,7 @@ delete_code_block_with_comments() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" ' + gawk -v block_name="$block_name" ' function count_char(str, c) { n = 0 for (i = 1; i <= length(str); i++) { @@ -782,7 +800,7 @@ replace_variable() { local tmp_file tmp_file=$(mktemp) - awk -v var_name="$var_name" -v new_value="$new_value" ' + gawk -v var_name="$var_name" -v new_value="$new_value" ' BEGIN { replaced = 0 } @@ -840,7 +858,7 @@ replace_or_append_variable() { local tmp_file tmp_file=$(mktemp) - awk -v var_name="$var_name" -v new_value="$new_value" ' + gawk -v var_name="$var_name" -v new_value="$new_value" ' BEGIN { replaced = 0 } { @@ -894,7 +912,7 @@ delete_variable() { local tmp_file tmp_file=$(mktemp) - awk -v var_name="$var_name" ' + gawk -v var_name="$var_name" ' # match: key = val, key=val, key val !($0 ~ "^[[:space:]]*" var_name "[[:space:]]*(=|[^[:alnum:]#])") { print @@ -923,7 +941,7 @@ delete_variable_with_comments() { local tmp_file tmp_file=$(mktemp) - awk -v var_name="$var_name" ' + gawk -v var_name="$var_name" ' { lines[NR] = $0 @@ -961,6 +979,132 @@ delete_variable_with_comments() { } +# --- +# - Mail services (dovecot protocols) +# --- + +# - Known (selectable) mail services - in canonical order. +# - +# - imap - IMAP (143) and IMAPS (993) +# - pop3 - POP3 (110) and POP3S (995) +# - sieve - ManageSieve (4190) +# - +# - Note: +# - 'lmtp' is NOT part of this list. LMTP is needed for delivering mail from +# - postfix into the mailboxes and is therefore always enabled. +# - +KNOWN_MAIL_PROTOCOLS="imap pop3 sieve" + +# - Mail services (dovecot protocols), which are ALWAYS disabled. +# - +# - submission - Dovecot's SMTP submission service (587 / 465) +# - +# - In this mailsystem submission (587) and submissions (465) +# - are provided by postfix. Dovecot's submission service would +# - collide with postfix (same ports) and also would need a +# - relay configuration (submission_relay_host, ..), which is +# - not done by this script. +# - +# - These protocols are explicitly set to 'no' in the 'protocols' block of +# - dovecot.conf and the corresponding 'service' blocks are removed from +# - 10-master.conf. +# - +DISABLED_MAIL_PROTOCOLS="submission" + +# - Predefined selections of the menu entries [1] and [2] +# - +MAIL_PROTOCOLS_ALL="imap pop3 sieve" +MAIL_PROTOCOLS_ALL_BUT_POP3="imap sieve" + + +# - normalize_mail_protocols +# - +# - Normalizes a blank (or comma) separated list of mail services and prints +# - the result to stdout: +# - +# - - all lowercase +# - - 'lmtp' is removed (always enabled anyway) +# - - unknown entries are removed (see unknown_mail_protocols()) +# - - duplicates are removed +# - - sorted in canonical order (see KNOWN_MAIL_PROTOCOLS) +# - +# - Example: +# - normalize_mail_protocols "Sieve,IMAP lmtp imap" --> "imap sieve" +# - +normalize_mail_protocols() { + + local _list="${1,,}" + local _known + local _entry + local _result="" + + # - Commas are allowed as separator as well + # - + _list="${_list//,/ }" + + # - Walk through the known services (canonical order) and take each one, + # - which is part of the given list. So duplicates and unknown entries + # - vanish automatically. + # - + for _known in ${KNOWN_MAIL_PROTOCOLS} ; do + for _entry in ${_list} ; do + if [[ "${_entry}" = "${_known}" ]] ; then + _result="${_result} ${_known}" + break + fi + done + done + + # - Remove leading blank + # - + echo "${_result# }" +} + + +# - unknown_mail_protocols +# - +# - Prints all entries of the given (blank or comma separated) list, which are +# - neither part of KNOWN_MAIL_PROTOCOLS nor 'lmtp'. Prints nothing if all +# - entries are known. +# - +unknown_mail_protocols() { + + local _list="${1,,}" + local _entry + local _result="" + + _list="${_list//,/ }" + + for _entry in ${_list} ; do + + # - 'lmtp' is always enabled - so its ok to be listed here + # - + [[ "${_entry}" = "lmtp" ]] && continue + + if [[ ! " ${KNOWN_MAIL_PROTOCOLS} " =~ " ${_entry} " ]] ; then + _result="${_result} ${_entry}" + fi + done + + echo "${_result# }" +} + + +# - mail_protocol_enabled +# - +# - Returns 0 (true) if the given service is part of the (normalized) list +# - in variable 'mail_protocols', otherwise 1 (false). +# - +# - Example: +# - if mail_protocol_enabled pop3 ; then +# - ... +# - fi +# - +mail_protocol_enabled() { + [[ " ${mail_protocols} " =~ " ${1,,} " ]] +} + + # - Support systemd ? # - @@ -1099,6 +1243,25 @@ fi [[ -n "$service_limit_nofile" ]] || service_limit_nofile=524280 +# - Mail services (dovecot protocols) to provide +# - +# - Parameter 'mail_protocols' (configuration file) defaults to +# - "imap pop3 sieve" (= menu entry [1]). +# - +# - The (normalized) value determines, which line of the selection menu +# - will be highlighted (see below "Mail services (dovecot protocols)"). +# - +[[ -n "$mail_protocols" ]] || mail_protocols="${MAIL_PROTOCOLS_ALL}" + +_unknown="$(unknown_mail_protocols "${mail_protocols}")" +if [[ -n "${_unknown}" ]] ; then + fatal "Wrong value(s) for parameter 'mail_protocols' (${_unknown}). Only '${KNOWN_MAIL_PROTOCOLS}' is allowed." +fi +mail_protocols="$(normalize_mail_protocols "${mail_protocols}")" +if [[ -z "${mail_protocols}" ]] ; then + fatal "Parameter 'mail_protocols' contains no mail service. At least one of '${KNOWN_MAIL_PROTOCOLS}' is required." +fi + [[ -n "${vmail_uid}" ]] || vmail_uid=${DEFAULT_VMAIL_UID} [[ -n "${vmail_gid}" ]] || vmail_gid=${DEFAULT_VMAIL_GID} @@ -1243,6 +1406,152 @@ while [[ "$update" != "true" && "$update" != "false" ]] ; do done +# ------------- +# - Mail services (dovecot protocols) +# ------------- + +# - Which line of the menu is highlighted (default for )? +# - +# - mail_protocols (configuration file) highlighted menu entry +# - ----------------------------------- ---------------------- +# - "imap pop3 sieve" (or not set) [1] all common mail services +# - "imap sieve" [2] all except pop3 +# - anything else [3] other +# - +# - Note: +# - 'mail_protocols' is already normalized here (see "Some defaults if +# - missing"), so the order of the entries in the configuration file +# - doesn't matter. +# - +if [[ "${mail_protocols}" = "${MAIL_PROTOCOLS_ALL}" ]] ; then + _default_mail_protocols_choice=1 +elif [[ "${mail_protocols}" = "${MAIL_PROTOCOLS_ALL_BUT_POP3}" ]] ; then + _default_mail_protocols_choice=2 +else + _default_mail_protocols_choice=3 +fi + +# - Value offered as default for the follow-up input of menu entry [3] +# - +# - Only if the configuration file contains an individual list (not the one +# - of [1] or [2]), this list is offered. Otherwise an explicit input is +# - required. +# - +if [[ ${_default_mail_protocols_choice} -eq 3 ]] ; then + _preset_mail_protocols="${mail_protocols}" +else + _preset_mail_protocols="" +fi + +# - The menu lines +# - +_mail_protocols_menu[1]="[1] All common mail services ........: ${MAIL_PROTOCOLS_ALL}" +_mail_protocols_menu[2]="[2] All common except pop3 ..........: ${MAIL_PROTOCOLS_ALL_BUT_POP3}" +if [[ -n "${_preset_mail_protocols}" ]] ; then + _mail_protocols_menu[3]="[3] Other ...........................: ${_preset_mail_protocols}" +else + _mail_protocols_menu[3]="[3] Other (explicit input)" +fi + +echo "" +echo -e "\033[32m--\033[m" +echo "" +echo "Which mail services (dovecot protocols) should be provided?" +echo "" +echo -e " \033[33mNote\033[m: LMTP (delivery postfix --> mailboxes) is always enabled." +echo "" +echo "" +for _i in 1 2 3 ; do + if [[ ${_i} -eq ${_default_mail_protocols_choice} ]] ; then + echo -e "\033[37m\033[1m${_mail_protocols_menu[${_i}]}\033[m" + else + echo "${_mail_protocols_menu[${_i}]}" + fi +done +echo "" +echononl "Choose a number or press for highlighted value: " + +_mail_protocols_choice="" +while [[ -z "${_mail_protocols_choice}" ]] ; do + read OPTION + case $OPTION in + 1|2|3) _mail_protocols_choice=$OPTION + ;; + '') _mail_protocols_choice=${_default_mail_protocols_choice} + ;; + *) echo "" + echo -e "\tWrong entry! [ 1 = all common ; 2 = all except pop3 ; 3 = other ] or type " + echo "" + echononl "Reentry: " + ;; + esac +done + +case ${_mail_protocols_choice} in + + 1) mail_protocols="${MAIL_PROTOCOLS_ALL}" + ;; + + 2) mail_protocols="${MAIL_PROTOCOLS_ALL_BUT_POP3}" + ;; + + 3) # - Follow-up input: list of mail services + # - + # - - preset with the value from the configuration file, if that value + # - is an individual list --> takes the preset + # - - otherwise an explicit input is required + # - + echo "" + echo " Enter a blank separated list of mail services to provide." + echo "" + echo -e " Possible values: \033[1m${KNOWN_MAIL_PROTOCOLS}\033[m" + echo "" + echo -e " \033[33mNote\033[m: 'submission' (587/465) is provided by postfix - not by dovecot." + echo "" + + _new_mail_protocols="" + while [[ -z "${_new_mail_protocols}" ]] ; do + + if [[ -n "${_preset_mail_protocols}" ]] ; then + echononl "Mail services [${_preset_mail_protocols}]: " + else + echononl "Mail services: " + fi + read _input + + # - (or only blanks) --> take preset (if any) + # - + if [[ -z "${_input//[[:space:]]/}" ]] ; then + if [[ -n "${_preset_mail_protocols}" ]] ; then + _new_mail_protocols="${_preset_mail_protocols}" + else + echo -e "\n\t\033[33m\033[1mAt least one mail service is required!\033[m\n" + fi + continue + fi + + # - Unknown entries? + # - + _unknown="$(unknown_mail_protocols "${_input}")" + if [[ -n "${_unknown}" ]] ; then + echo -e "\n\t\033[33m\033[1mUnknown mail service(s): ${_unknown}\033[m" + echo -e "\t\033[33m\033[1mPossible values: ${KNOWN_MAIL_PROTOCOLS}\033[m\n" + continue + fi + + # - Normalize (sort, remove duplicates and 'lmtp') + # - + _new_mail_protocols="$(normalize_mail_protocols "${_input}")" + if [[ -z "${_new_mail_protocols}" ]] ; then + echo -e "\n\t\033[33m\033[1mAt least one mail service (besides lmtp) is required!\033[m\n" + fi + done + + mail_protocols="${_new_mail_protocols}" + ;; +esac + + # ------------- @@ -1272,12 +1581,48 @@ echo "" echo -e "\tIPv4 address..................: $ipv4" echo -e "\tIPv6 address..................: $ipv6" echo "" -echo -e "\tIMAP listener addresses.......: $imap_listener_adresses" -echo -e "\tIMAPS listener addresses......: $imaps_listener_adresses" -echo "" -echo -e "\tPOP3 listener addresses.......: $pop_listener_adresses" -echo -e "\tPOP3S listener addresses......: $pops_listener_adresses" + +# - Mail services (dovecot protocols) to activate +# - +# - Each protocol is listed with its state. Enabled protocols are highlighted. +# - +# - 'lmtp' is always enabled, the protocols of DISABLED_MAIL_PROTOCOLS +# - (submission) are always disabled. +# - +echo -e "\tMail services (protocols) to activate:" +echo -e "\t lmtp.......................: \033[1myes\033[m (always - delivery postfix --> mailboxes)" +for _protocol in ${KNOWN_MAIL_PROTOCOLS} ; do + + # - Fill up the protocol name with dots (column width as used above) + # - + _label="${_protocol}..........................." + _label="${_label:0:27}" + + if mail_protocol_enabled "${_protocol}" ; then + echo -e "\t ${_label}: \033[1myes\033[m" + else + echo -e "\t ${_label}: no" + fi +done +for _protocol in ${DISABLED_MAIL_PROTOCOLS} ; do + _label="${_protocol}..........................." + _label="${_label:0:27}" + echo -e "\t ${_label}: no (provided by postfix)" +done echo "" + +# - Listener addresses only for the enabled protocols +# - +if mail_protocol_enabled imap ; then + echo -e "\tIMAP listener addresses.......: $imap_listener_adresses" + echo -e "\tIMAPS listener addresses......: $imaps_listener_adresses" + echo "" +fi +if mail_protocol_enabled pop3 ; then + echo -e "\tPOP3 listener addresses.......: $pop_listener_adresses" + echo -e "\tPOP3S listener addresses......: $pops_listener_adresses" + echo "" +fi echo -e "\tPostfix Configuration File....: $postfix_main_cf" echo "" echo -e "\tDatenbank.....................: $database" @@ -1453,6 +1798,24 @@ detect_os_1 () { } +# --- +# - Helper functions to edit dovecot's configuration files +# --- +# - +# - !! These functions require GNU awk (gawk) !! +# - +# - They use GNU awk extensions (e.g. '\s' in regular expressions). Therefore +# - 'gawk' is called explicitly - not 'awk'. On Debian 'awk' is usually 'mawk', +# - which does NOT support these extensions: blocks would silently not be +# - found, so nothing gets replaced/deleted, or blocks are appended a second +# - time instead of being replaced. +# - +# - gawk is installed (if missing) before dovecot is configured - see +# - "Check / install GNU awk (gawk)". +# - +# - Simple awk calls elsewhere (e.g. "awk '{print $1}'") only use POSIX awk +# - features and keep using 'awk'. +# - replace_code_block() { local block_name="$1" local new_block="$2" @@ -1472,7 +1835,7 @@ replace_code_block() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" -v new_block="$new_block" ' + gawk -v block_name="$block_name" -v new_block="$new_block" ' function count_char(str, c) { n = 0 for (i = 1; i <= length(str); i++) { @@ -1526,7 +1889,7 @@ replace_or_append_code_block() { local block_found=0 - awk -v block_name="$block_name" -v new_block="$new_block" ' + gawk -v block_name="$block_name" -v new_block="$new_block" ' function count_char(str, c) { n = 0 for (i = 1; i <= length(str); i++) { @@ -1637,7 +2000,7 @@ replace_or_append_code_block_if_keyval() { local block_found=0 - awk -v block_name="$block_name" -v new_block="$new_block" \ + gawk -v block_name="$block_name" -v new_block="$new_block" \ -v req_key="$required_key" -v req_val="$required_value" ' function count_char(str, c) { n = 0 @@ -1754,7 +2117,7 @@ replace_code_block_if_keyval() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" -v new_block="$new_block" \ + gawk -v block_name="$block_name" -v new_block="$new_block" \ -v req_key="$required_key" -v req_val="$required_value" ' function count_char(str, c) { n = 0 @@ -1859,7 +2222,7 @@ replace_or_append_code_block_if_keyval_strict() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" -v new_block="$new_block" \ + gawk -v block_name="$block_name" -v new_block="$new_block" \ -v req_key="$required_key" -v req_val="$required_value" ' function count_char(str, c) { n = 0 @@ -1964,7 +2327,7 @@ delete_code_block() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" ' + gawk -v block_name="$block_name" ' function count_char(str, c) { n = 0 for (i = 1; i <= length(str); i++) { @@ -2014,7 +2377,7 @@ delete_code_block_with_comments() { local tmp_file tmp_file=$(mktemp) - awk -v block_name="$block_name" ' + gawk -v block_name="$block_name" ' function count_char(str, c) { n = 0 for (i = 1; i <= length(str); i++) { @@ -2086,7 +2449,7 @@ replace_variable() { local tmp_file tmp_file=$(mktemp) - awk -v var_name="$var_name" -v new_value="$new_value" ' + gawk -v var_name="$var_name" -v new_value="$new_value" ' BEGIN { replaced = 0 } @@ -2144,7 +2507,7 @@ replace_or_append_variable() { local tmp_file tmp_file=$(mktemp) - awk -v var_name="$var_name" -v new_value="$new_value" ' + gawk -v var_name="$var_name" -v new_value="$new_value" ' BEGIN { replaced = 0 } { @@ -2198,7 +2561,7 @@ delete_variable() { local tmp_file tmp_file=$(mktemp) - awk -v var_name="$var_name" ' + gawk -v var_name="$var_name" ' # match: key = val, key=val, key val !($0 ~ "^[[:space:]]*" var_name "[[:space:]]*(=|[^[:alnum:]#])") { print @@ -2227,7 +2590,7 @@ delete_variable_with_comments() { local tmp_file tmp_file=$(mktemp) - awk -v var_name="$var_name" ' + gawk -v var_name="$var_name" ' { lines[NR] = $0 @@ -2303,6 +2666,10 @@ echo "pops_listener_adresses=\"${pops_listener_adresses}\"" >> ${INSTALL_UPDATE_ echo "" >> ${INSTALL_UPDATE_ENVIRONMENT_FILE} +echo "mail_protocols=\"${mail_protocols}\"" >> ${INSTALL_UPDATE_ENVIRONMENT_FILE} + +echo "" >> ${INSTALL_UPDATE_ENVIRONMENT_FILE} + echo "xmpp_listener=${xmpp_listener}" >> ${INSTALL_UPDATE_ENVIRONMENT_FILE} if $xmpp_listener ; then echo "xmpp_listener_addresses=\"${xmpp_listener_addresses}\"" >> ${INSTALL_UPDATE_ENVIRONMENT_FILE} @@ -2627,31 +2994,66 @@ dovecot_pigeonhole_archiv_prefix="${dovecot_pigeonhole_archiv%.tar.gz}" dovecot_pigeonhole_archiv_dir="${dovecot_pigeonhole_archiv%.tar.gz}" +## - Check / install GNU awk (gawk) +## - +## - Required for update AND new installation: the helper functions which +## - edit dovecot's configuration files (replace_code_block, +## - delete_code_block_with_comments, replace_variable, ..) call 'gawk' +## - explicitly (see "Helper functions to edit dovecot's configuration files"). +## - +## - Without gawk these functions would empty the configuration files +## - (command not found --> empty output). So abort here, if gawk cannot be +## - installed. +## - +echo "" +echo -e "\033[1mCheck required tools\033[m.." +echononl " Installing gawk (GNU awk).." +if ! command -v gawk > /dev/null 2>&1 ; then + apt-get install -y gawk > "${log_file}" 2>&1 + if [[ $? -eq 0 ]] && command -v gawk > /dev/null 2>&1 ; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + error "$(cat "${log_file}")" + fatal "Installing debian package 'gawk' failed - but gawk is required!" + fi +else + echo -e "$rc_skipped" +fi + + if $_new ; then ## - Install reqired debian packages ## - echo "" echo -e "\033[1mInstalling required debian packages\033[m.." + # - Note: + # - - '-y' : no interactive confirmation (output goes into the + # - log file, so a prompt would not be visible) + # - - '>> .. 2>&1' : stdout AND stderr into the log file + # - - 'dpkg -l .. 2>/dev/null' : suppress "no packages found .." message + # - if the package is not installed + # - echononl " Installing libpq5 libpq-dev .." - if ! dpkg -l libpq-dev | grep -e "^ii" | grep libpq-dev > /dev/null ; then - apt-get install libpq5 libpq-dev > ${_log_dir}/debian-install.log 2&>1 + if ! dpkg -l libpq-dev 2>/dev/null | grep -e "^ii" | grep libpq-dev > /dev/null ; then + apt-get install -y libpq5 libpq-dev >> "${_log_dir}/debian-install.log" 2>&1 if [ "$?" = 0 ]; then echo -e "$rc_done" else echo -e "$rc_failed" - fatal "installing debian package(s) failed" + fatal "installing debian package(s) failed - see '${_log_dir}/debian-install.log'" fi else echo -e "$rc_skipped" fi echononl " Installing libkrb5-dev .." - if ! dpkg -l libkrb5-dev | grep -e "^ii" | grep libkrb5-dev > /dev/null ; then - apt-get install libkrb5-dev >> ${_log_dir}/debian-install.log 2&>1 + if ! dpkg -l libkrb5-dev 2>/dev/null | grep -e "^ii" | grep libkrb5-dev > /dev/null ; then + apt-get install -y libkrb5-dev >> "${_log_dir}/debian-install.log" 2>&1 if [ "$?" = 0 ]; then echo -e "$rc_done" else echo -e "$rc_failed" - fatal "installing debian package(s) failed" + fatal "installing debian package(s) failed - see '${_log_dir}/debian-install.log'" fi else echo -e "$rc_skipped" @@ -3632,7 +4034,38 @@ if [[ $dovecot_major_version -gt 2 ]] \ echo -e "$rc_skipped" fi - _protocols_block="protocols {\n imap = yes\n lmtp = yes\n pop3 = yes\n sieve = yes\n}" + # - Build 'protocols' block from the selected mail services (mail_protocols) + # - + # - - lmtp is always enabled (delivery postfix --> mailboxes) + # - - every known but NOT selected service is explicitly set to 'no'. So it + # - is guaranteed, that no protocol is enabled via dovecot's built-in + # - defaults (boolean lists are merged with the defaults). + # - - the always disabled services (DISABLED_MAIL_PROTOCOLS, e.g. + # - submission) are set to 'no' as well. + # - + # - Example (mail_protocols="imap sieve"): + # - + # - protocols { + # - lmtp = yes + # - imap = yes + # - pop3 = no + # - sieve = yes + # - submission = no + # - } + # - + _protocols_block="protocols {\n lmtp = yes" + for _protocol in ${KNOWN_MAIL_PROTOCOLS} ; do + if mail_protocol_enabled "${_protocol}" ; then + _protocols_block="${_protocols_block}\n ${_protocol} = yes" + else + _protocols_block="${_protocols_block}\n ${_protocol} = no" + fi + done + for _protocol in ${DISABLED_MAIL_PROTOCOLS} ; do + _protocols_block="${_protocols_block}\n ${_protocol} = no" + done + _protocols_block="${_protocols_block}\n}" + if [[ -n "$ipv6" ]]; then _listen="$ipv4 $ipv6" else @@ -3876,7 +4309,10 @@ else perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(listen\ ?=.*)#\1\#\# \2\n\1listen = $ipv4#g" \ /usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf || _failed=true fi - perl -i -n -p -e "s#^([ ]*)\#?\ ?(protocols\ ?=.*)#\1\#\# \2\n\1protocols = imap pop3 sieve#g" \ + # - protocols: the selected mail services (mail_protocols) - lmtp is + # - enabled later on (see "Change (from lda) to lmtp-service") + # - + perl -i -n -p -e "s#^([ ]*)\#?\ ?(protocols\ ?=.*)#\1\#\# \2\n\1protocols = ${mail_protocols}#g" \ /usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf || _failed=true perl -i -n -p -e "s#^([ ]*)\#?\ ?(base_dir\ ?=.*)#\1\#\# \2\n\1base_dir = /run/dovecot/\n\nstate_dir = /run/dovecot#g" \ /usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf || _failed=true @@ -4284,6 +4720,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # process_min_avail = 16 # } # + # # only if mail service 'pop3' is selected - otherwise removed # service pop3-login { # inet_listener pop3 { # address = $pop_listener_adresses @@ -4295,16 +4732,8 @@ if [[ $dovecot_major_version -gt 2 ]] \ # } # } # - # service submission-login { - # - # inet_listener submission { - # #port = 587 - # } - # - # inet_listener submissions { - # #port = 465 - # } - # } + # # 'service submission-login' and 'service submission' are removed: + # # submission (587/465) is provided by postfix in this mailsystem. # # service lmtp { # @@ -4335,6 +4764,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # #process_limit = 1024 # } # + # # only if mail service 'pop3' is selected - otherwise removed # service pop3 { # # # tell imap to do post-login lookup using a socket called "imap-postlogin" @@ -4344,12 +4774,6 @@ if [[ $dovecot_major_version -gt 2 ]] \ # #process_limit = 1024 # } # - # service submission { - # - # # Max. number of SMTP Submission processes (connections) - # #process_limit = 1024 - # } - # # service auth { # # # Auth Listener (XMPP - Jabber) @@ -4453,7 +4877,14 @@ EOF _failed=true fi - read -r -d '' NEW_BLOCK <> "${log_file}" 2>&1 - if [[ $? -gt 0 ]]; then - _failed=true + replace_or_append_code_block "service pop3-login" "${NEW_BLOCK}" "${_conf_file}" >> "${log_file}" 2>&1 + if [[ $? -gt 0 ]]; then + _failed=true + fi + else + delete_code_block_with_comments "service pop3-login" "${_conf_file}" >> "${log_file}" 2>&1 + if [[ $? -gt 1 ]]; then + _failed=true + fi fi - read -r -d '' NEW_BLOCK <> "${log_file}" 2>&1 - if [[ $? -gt 0 ]]; then + # - service submission-login + # - + # - Dovecot's submission service is NOT used in this mailsystem (submission + # - is provided by postfix - see DISABLED_MAIL_PROTOCOLS). So remove an + # - existing block (e.g. from the shipped example configuration). + # - + delete_code_block_with_comments "service submission-login" "${_conf_file}" >> "${log_file}" 2>&1 + if [[ $? -gt 1 ]]; then _failed=true fi @@ -4531,7 +4962,13 @@ EOF _failed=true fi - read -r -d '' NEW_BLOCK <> "${log_file}" 2>&1 - if [[ $? -gt 0 ]]; then - _failed=true + replace_or_append_code_block "service pop3" "${NEW_BLOCK}" "${_conf_file}" >> "${log_file}" 2>&1 + if [[ $? -gt 0 ]]; then + _failed=true + fi + else + delete_code_block_with_comments "service pop3" "${_conf_file}" >> "${log_file}" 2>&1 + if [[ $? -gt 1 ]]; then + _failed=true + fi fi - read -r -d '' NEW_BLOCK <> "${log_file}" 2>&1 - if [[ $? -gt 0 ]]; then + # - service submission + # - + # - Not used in this mailsystem (see DISABLED_MAIL_PROTOCOLS) - remove an + # - existing block. + # - + delete_code_block_with_comments "service submission" "${_conf_file}" >> "${log_file}" 2>&1 + if [[ $? -gt 1 ]]; then _failed=true fi @@ -10186,7 +10627,13 @@ EOF _failed=true fi - read -r -d '' NEW_BLOCK <> "${log_file}" 2>&1 - if [[ $? -gt 0 ]]; then - _failed=true + replace_or_append_code_block "service pop3" "${NEW_BLOCK}" "${_conf_file}" >> "${log_file}" 2>&1 + if [[ $? -gt 0 ]]; then + _failed=true + fi fi read -r -d '' NEW_BLOCK <<'EOF'