Compare commits

..
2 Commits
Author SHA1 Message Date
chrisandClaude Opus 5.5 29fe6d0e0d install_update_dovecot-2.4.sh: use '2>&1' instead of '2<&1' for stderr redirection
'2<&1' duplicates fd 1 as an input descriptor. In bash it happens to
behave like '2>&1', but it is unusual and misleading. Use the common
form '2>&1' (cp, grep, pigeonhole configure/make/make install).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 15:13:37 +01:00
chrisandClaude Opus 5.5 38c7ce8f6a 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 <noreply@anthropic.com>
2026-11-24 15:12:45 +01:00
2 changed files with 563 additions and 79 deletions

No files matched your search

+36
View File
@@ -69,6 +69,42 @@ ipv6=""
#postfix_main_cf="/etc/postfix/main.cf" #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 <RETURN>) 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 # - Listener configuration
# --- # ---
+527 -79
View File
@@ -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() { replace_code_block() {
local block_name="$1" local block_name="$1"
local new_block="$2" local new_block="$2"
@@ -168,7 +186,7 @@ replace_code_block() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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) { function count_char(str, c) {
n = 0 n = 0
for (i = 1; i <= length(str); i++) { for (i = 1; i <= length(str); i++) {
@@ -222,7 +240,7 @@ replace_or_append_code_block() {
local block_found=0 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) { function count_char(str, c) {
n = 0 n = 0
for (i = 1; i <= length(str); i++) { for (i = 1; i <= length(str); i++) {
@@ -333,7 +351,7 @@ replace_or_append_code_block_if_keyval() {
local block_found=0 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" ' -v req_key="$required_key" -v req_val="$required_value" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
@@ -450,7 +468,7 @@ replace_code_block_if_keyval() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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" ' -v req_key="$required_key" -v req_val="$required_value" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
@@ -555,7 +573,7 @@ replace_or_append_code_block_if_keyval_strict() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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" ' -v req_key="$required_key" -v req_val="$required_value" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
@@ -660,7 +678,7 @@ delete_code_block() {
local tmp_file local tmp_file
tmp_file=$(mktemp) tmp_file=$(mktemp)
awk -v block_name="$block_name" ' gawk -v block_name="$block_name" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
for (i = 1; i <= length(str); i++) { for (i = 1; i <= length(str); i++) {
@@ -710,7 +728,7 @@ delete_code_block_with_comments() {
local tmp_file local tmp_file
tmp_file=$(mktemp) tmp_file=$(mktemp)
awk -v block_name="$block_name" ' gawk -v block_name="$block_name" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
for (i = 1; i <= length(str); i++) { for (i = 1; i <= length(str); i++) {
@@ -782,7 +800,7 @@ replace_variable() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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 { BEGIN {
replaced = 0 replaced = 0
} }
@@ -840,7 +858,7 @@ replace_or_append_variable() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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 } BEGIN { replaced = 0 }
{ {
@@ -894,7 +912,7 @@ delete_variable() {
local tmp_file local tmp_file
tmp_file=$(mktemp) tmp_file=$(mktemp)
awk -v var_name="$var_name" ' gawk -v var_name="$var_name" '
# match: key = val, key=val, key val # match: key = val, key=val, key val
!($0 ~ "^[[:space:]]*" var_name "[[:space:]]*(=|[^[:alnum:]#])") { !($0 ~ "^[[:space:]]*" var_name "[[:space:]]*(=|[^[:alnum:]#])") {
print print
@@ -923,7 +941,7 @@ delete_variable_with_comments() {
local tmp_file local tmp_file
tmp_file=$(mktemp) tmp_file=$(mktemp)
awk -v var_name="$var_name" ' gawk -v var_name="$var_name" '
{ {
lines[NR] = $0 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 <list of mail services>
# -
# - 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 <list of mail services>
# -
# - 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 <service>
# -
# - 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 ? # - Support systemd ?
# - # -
@@ -1099,6 +1243,25 @@ fi
[[ -n "$service_limit_nofile" ]] || service_limit_nofile=524280 [[ -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_uid}" ]] || vmail_uid=${DEFAULT_VMAIL_UID}
[[ -n "${vmail_gid}" ]] || vmail_gid=${DEFAULT_VMAIL_GID} [[ -n "${vmail_gid}" ]] || vmail_gid=${DEFAULT_VMAIL_GID}
@@ -1243,6 +1406,152 @@ while [[ "$update" != "true" && "$update" != "false" ]] ; do
done done
# -------------
# - Mail services (dovecot protocols)
# -------------
# - Which line of the menu is highlighted (default for <RETURN>)?
# -
# - 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 <RETURN> 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 <RETURN>"
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 --> <RETURN> 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
# - <RETURN> (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 "\tIPv4 address..................: $ipv4"
echo -e "\tIPv6 address..................: $ipv6" echo -e "\tIPv6 address..................: $ipv6"
echo "" echo ""
echo -e "\tIMAP listener addresses.......: $imap_listener_adresses"
echo -e "\tIMAPS listener addresses......: $imaps_listener_adresses" # - Mail services (dovecot protocols) to activate
echo "" # -
echo -e "\tPOP3 listener addresses.......: $pop_listener_adresses" # - Each protocol is listed with its state. Enabled protocols are highlighted.
echo -e "\tPOP3S listener addresses......: $pops_listener_adresses" # -
# - '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 "" 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 -e "\tPostfix Configuration File....: $postfix_main_cf"
echo "" echo ""
echo -e "\tDatenbank.....................: $database" 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() { replace_code_block() {
local block_name="$1" local block_name="$1"
local new_block="$2" local new_block="$2"
@@ -1472,7 +1835,7 @@ replace_code_block() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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) { function count_char(str, c) {
n = 0 n = 0
for (i = 1; i <= length(str); i++) { for (i = 1; i <= length(str); i++) {
@@ -1526,7 +1889,7 @@ replace_or_append_code_block() {
local block_found=0 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) { function count_char(str, c) {
n = 0 n = 0
for (i = 1; i <= length(str); i++) { for (i = 1; i <= length(str); i++) {
@@ -1637,7 +2000,7 @@ replace_or_append_code_block_if_keyval() {
local block_found=0 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" ' -v req_key="$required_key" -v req_val="$required_value" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
@@ -1754,7 +2117,7 @@ replace_code_block_if_keyval() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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" ' -v req_key="$required_key" -v req_val="$required_value" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
@@ -1859,7 +2222,7 @@ replace_or_append_code_block_if_keyval_strict() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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" ' -v req_key="$required_key" -v req_val="$required_value" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
@@ -1964,7 +2327,7 @@ delete_code_block() {
local tmp_file local tmp_file
tmp_file=$(mktemp) tmp_file=$(mktemp)
awk -v block_name="$block_name" ' gawk -v block_name="$block_name" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
for (i = 1; i <= length(str); i++) { for (i = 1; i <= length(str); i++) {
@@ -2014,7 +2377,7 @@ delete_code_block_with_comments() {
local tmp_file local tmp_file
tmp_file=$(mktemp) tmp_file=$(mktemp)
awk -v block_name="$block_name" ' gawk -v block_name="$block_name" '
function count_char(str, c) { function count_char(str, c) {
n = 0 n = 0
for (i = 1; i <= length(str); i++) { for (i = 1; i <= length(str); i++) {
@@ -2086,7 +2449,7 @@ replace_variable() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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 { BEGIN {
replaced = 0 replaced = 0
} }
@@ -2144,7 +2507,7 @@ replace_or_append_variable() {
local tmp_file local tmp_file
tmp_file=$(mktemp) 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 } BEGIN { replaced = 0 }
{ {
@@ -2198,7 +2561,7 @@ delete_variable() {
local tmp_file local tmp_file
tmp_file=$(mktemp) tmp_file=$(mktemp)
awk -v var_name="$var_name" ' gawk -v var_name="$var_name" '
# match: key = val, key=val, key val # match: key = val, key=val, key val
!($0 ~ "^[[:space:]]*" var_name "[[:space:]]*(=|[^[:alnum:]#])") { !($0 ~ "^[[:space:]]*" var_name "[[:space:]]*(=|[^[:alnum:]#])") {
print print
@@ -2227,7 +2590,7 @@ delete_variable_with_comments() {
local tmp_file local tmp_file
tmp_file=$(mktemp) tmp_file=$(mktemp)
awk -v var_name="$var_name" ' gawk -v var_name="$var_name" '
{ {
lines[NR] = $0 lines[NR] = $0
@@ -2303,6 +2666,10 @@ echo "pops_listener_adresses=\"${pops_listener_adresses}\"" >> ${INSTALL_UPDATE_
echo "" >> ${INSTALL_UPDATE_ENVIRONMENT_FILE} 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} echo "xmpp_listener=${xmpp_listener}" >> ${INSTALL_UPDATE_ENVIRONMENT_FILE}
if $xmpp_listener ; then if $xmpp_listener ; then
echo "xmpp_listener_addresses=\"${xmpp_listener_addresses}\"" >> ${INSTALL_UPDATE_ENVIRONMENT_FILE} 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}" 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 if $_new ; then
## - Install reqired debian packages ## - Install reqired debian packages
## - ## -
echo "" echo ""
echo -e "\033[1mInstalling required debian packages\033[m.." 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 .." echononl " Installing libpq5 libpq-dev .."
if ! dpkg -l libpq-dev | grep -e "^ii" | grep libpq-dev > /dev/null ; then if ! dpkg -l libpq-dev 2>/dev/null | grep -e "^ii" | grep libpq-dev > /dev/null ; then
apt-get install libpq5 libpq-dev > ${_log_dir}/debian-install.log 2&>1 apt-get install -y libpq5 libpq-dev >> "${_log_dir}/debian-install.log" 2>&1
if [ "$?" = 0 ]; then if [ "$?" = 0 ]; then
echo -e "$rc_done" echo -e "$rc_done"
else else
echo -e "$rc_failed" echo -e "$rc_failed"
fatal "installing debian package(s) failed" fatal "installing debian package(s) failed - see '${_log_dir}/debian-install.log'"
fi fi
else else
echo -e "$rc_skipped" echo -e "$rc_skipped"
fi fi
echononl " Installing libkrb5-dev .." echononl " Installing libkrb5-dev .."
if ! dpkg -l libkrb5-dev | grep -e "^ii" | grep libkrb5-dev > /dev/null ; then if ! dpkg -l libkrb5-dev 2>/dev/null | grep -e "^ii" | grep libkrb5-dev > /dev/null ; then
apt-get install libkrb5-dev >> ${_log_dir}/debian-install.log 2&>1 apt-get install -y libkrb5-dev >> "${_log_dir}/debian-install.log" 2>&1
if [ "$?" = 0 ]; then if [ "$?" = 0 ]; then
echo -e "$rc_done" echo -e "$rc_done"
else else
echo -e "$rc_failed" echo -e "$rc_failed"
fatal "installing debian package(s) failed" fatal "installing debian package(s) failed - see '${_log_dir}/debian-install.log'"
fi fi
else else
echo -e "$rc_skipped" echo -e "$rc_skipped"
@@ -3424,7 +3826,7 @@ echononl " Add /usr/local/dovecot/bin to PATH variable.."
if grep -Eq '^\s*checkdir="?/usr/local/dovecot/bin"?$' "${_file}"; then if grep -Eq '^\s*checkdir="?/usr/local/dovecot/bin"?$' "${_file}"; then
echo -e "$rc_skipped" echo -e "$rc_skipped"
else else
cp "${_file}" "/tmp/etc_profile.${backup_date}" > "${log_file}" 2<&1 cp "${_file}" "/tmp/etc_profile.${backup_date}" > "${log_file}" 2>&1
if [[ $? -gt 0 ]] ; then if [[ $? -gt 0 ]] ; then
echo -e "$rc_failed" echo -e "$rc_failed"
error "$(cat $log_file)" error "$(cat $log_file)"
@@ -3461,7 +3863,7 @@ fi
echononl " Copy Manpages if not exists.." echononl " Copy Manpages if not exists.."
## - Manpages ## - Manpages
## - ## -
if ! grep /usr/local/dovecot/share/man /etc/manpath.config > /dev/null 2<&1 ; then if ! grep /usr/local/dovecot/share/man /etc/manpath.config > /dev/null 2>&1 ; then
echo >> /etc/manpath.config echo >> /etc/manpath.config
echo "MANDATORY_MANPATH /usr/local/dovecot/share/man /var/cache/man" >> /etc/manpath.config echo "MANDATORY_MANPATH /usr/local/dovecot/share/man /var/cache/man" >> /etc/manpath.config
echo "MANPATH_MAP /usr/local/dovecot/bin /usr/local/dovecot/share/man" >> /etc/manpath.config echo "MANPATH_MAP /usr/local/dovecot/bin /usr/local/dovecot/share/man" >> /etc/manpath.config
@@ -3491,7 +3893,7 @@ cd ${dovecot_pigeonhole_archiv_dir}
echononl " Configure Pigeonhole ManageSieve.." echononl " Configure Pigeonhole ManageSieve.."
./configure \ ./configure \
--prefix=/usr/local/dovecot-${_version} \ --prefix=/usr/local/dovecot-${_version} \
--with-dovecot=/usr/local/dovecot-${_version}/lib/dovecot > ${_log_dir}/${dovecot_pigeonhole_archiv_prefix}-configure.log 2<&1 --with-dovecot=/usr/local/dovecot-${_version}/lib/dovecot > ${_log_dir}/${dovecot_pigeonhole_archiv_prefix}-configure.log 2>&1
if [ "$?" = 0 ]; then if [ "$?" = 0 ]; then
echo -e "$rc_done" echo -e "$rc_done"
else else
@@ -3500,7 +3902,7 @@ else
fi fi
echononl " Compile Pigeonhole ManageSieve.." echononl " Compile Pigeonhole ManageSieve.."
make > ${_log_dir}/${dovecot_pigeonhole_archiv_prefix}-make.log 2<&1 make > ${_log_dir}/${dovecot_pigeonhole_archiv_prefix}-make.log 2>&1
if [ "$?" = 0 ]; then if [ "$?" = 0 ]; then
echo -e "$rc_done" echo -e "$rc_done"
else else
@@ -3509,7 +3911,7 @@ else
fi fi
echononl " Install Pigeonhole ManageSieve.." echononl " Install Pigeonhole ManageSieve.."
make install > ${_log_dir}/${dovecot_pigeonhole_archiv_prefix}-install.log 2<&1 make install > ${_log_dir}/${dovecot_pigeonhole_archiv_prefix}-install.log 2>&1
if [ "$?" = 0 ]; then if [ "$?" = 0 ]; then
echo -e "$rc_done" echo -e "$rc_done"
else else
@@ -3632,7 +4034,38 @@ if [[ $dovecot_major_version -gt 2 ]] \
echo -e "$rc_skipped" echo -e "$rc_skipped"
fi 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 if [[ -n "$ipv6" ]]; then
_listen="$ipv4 $ipv6" _listen="$ipv4 $ipv6"
else else
@@ -3876,7 +4309,10 @@ else
perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(listen\ ?=.*)#\1\#\# \2\n\1listen = $ipv4#g" \ perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(listen\ ?=.*)#\1\#\# \2\n\1listen = $ipv4#g" \
/usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf || _failed=true /usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf || _failed=true
fi 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 /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" \ 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 /usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf || _failed=true
@@ -4284,6 +4720,7 @@ if [[ $dovecot_major_version -gt 2 ]] \
# process_min_avail = 16 # process_min_avail = 16
# } # }
# #
# # only if mail service 'pop3' is selected - otherwise removed
# service pop3-login { # service pop3-login {
# inet_listener pop3 { # inet_listener pop3 {
# address = $pop_listener_adresses # address = $pop_listener_adresses
@@ -4295,16 +4732,8 @@ if [[ $dovecot_major_version -gt 2 ]] \
# } # }
# } # }
# #
# service submission-login { # # 'service submission-login' and 'service submission' are removed:
# # # submission (587/465) is provided by postfix in this mailsystem.
# inet_listener submission {
# #port = 587
# }
#
# inet_listener submissions {
# #port = 465
# }
# }
# #
# service lmtp { # service lmtp {
# #
@@ -4335,6 +4764,7 @@ if [[ $dovecot_major_version -gt 2 ]] \
# #process_limit = 1024 # #process_limit = 1024
# } # }
# #
# # only if mail service 'pop3' is selected - otherwise removed
# service pop3 { # service pop3 {
# #
# # tell imap to do post-login lookup using a socket called "imap-postlogin" # # 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 # #process_limit = 1024
# } # }
# #
# service submission {
#
# # Max. number of SMTP Submission processes (connections)
# #process_limit = 1024
# }
#
# service auth { # service auth {
# #
# # Auth Listener (XMPP - Jabber) # # Auth Listener (XMPP - Jabber)
@@ -4453,6 +4877,13 @@ EOF
_failed=true _failed=true
fi fi
# - service pop3-login
# -
# - Only if mail service 'pop3' is selected (mail_protocols). Otherwise an
# - existing block (e.g. from the shipped example configuration) will be
# - removed.
# -
if mail_protocol_enabled pop3 ; then
read -r -d '' NEW_BLOCK <<EOF read -r -d '' NEW_BLOCK <<EOF
service pop3-login { service pop3-login {
@@ -4472,21 +4903,21 @@ EOF
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
_failed=true _failed=true
fi 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 <<EOF # - service submission-login
service submission-login { # -
# - Dovecot's submission service is NOT used in this mailsystem (submission
inet_listener submission { # - is provided by postfix - see DISABLED_MAIL_PROTOCOLS). So remove an
#port = 587 # - existing block (e.g. from the shipped example configuration).
} # -
delete_code_block_with_comments "service submission-login" "${_conf_file}" >> "${log_file}" 2>&1
inet_listener submissions { if [[ $? -gt 1 ]]; then
#port = 465
}
}
EOF
replace_or_append_code_block "service submission-login" "${NEW_BLOCK}" "${_conf_file}" >> "${log_file}" 2>&1
if [[ $? -gt 0 ]]; then
_failed=true _failed=true
fi fi
@@ -4531,6 +4962,12 @@ EOF
_failed=true _failed=true
fi fi
# - service pop3
# -
# - Only if mail service 'pop3' is selected (mail_protocols), otherwise
# - remove an existing block.
# -
if mail_protocol_enabled pop3 ; then
read -r -d '' NEW_BLOCK <<EOF read -r -d '' NEW_BLOCK <<EOF
service pop3 { service pop3 {
@@ -4545,16 +4982,20 @@ EOF
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
_failed=true _failed=true
fi 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 <<EOF # - service submission
service submission { # -
# - Not used in this mailsystem (see DISABLED_MAIL_PROTOCOLS) - remove an
# Max. number of SMTP Submission processes (connections) # - existing block.
#process_limit = 1024 # -
} delete_code_block_with_comments "service submission" "${_conf_file}" >> "${log_file}" 2>&1
EOF if [[ $? -gt 1 ]]; then
replace_or_append_code_block "service submission" "${NEW_BLOCK}" "${_conf_file}" >> "${log_file}" 2>&1
if [[ $? -gt 0 ]]; then
_failed=true _failed=true
fi fi
@@ -10186,6 +10627,12 @@ EOF
_failed=true _failed=true
fi fi
# - service pop3 (post-login) - only if mail service 'pop3' is selected
# -
# - Otherwise there is nothing to do here: the block was already removed
# - while editing 10-master.conf before (see "service pop3" above).
# -
if mail_protocol_enabled pop3 ; then
read -r -d '' NEW_BLOCK <<EOF read -r -d '' NEW_BLOCK <<EOF
service pop3 { service pop3 {
@@ -10200,6 +10647,7 @@ EOF
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
_failed=true _failed=true
fi fi
fi
read -r -d '' NEW_BLOCK <<'EOF' read -r -d '' NEW_BLOCK <<'EOF'
service post-login { service post-login {