From 7cc2369ea0d7d601cb1b6658c0b1238865848d83 Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 14 Aug 2025 01:41:47 +0200 Subject: [PATCH] install_update_dovecot-2.4.sh: initial versionm. --- install_update_dovecot-2.4.sh | 639 ++++++++++++++++++++++++---------- 1 file changed, 461 insertions(+), 178 deletions(-) diff --git a/install_update_dovecot-2.4.sh b/install_update_dovecot-2.4.sh index 9411a58..1e5ccb1 100755 --- a/install_update_dovecot-2.4.sh +++ b/install_update_dovecot-2.4.sh @@ -1132,6 +1132,11 @@ else plugin_expire=true fi +if [[ $dovecot_major_version -gt 2 ]] \ + || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then + postmaster_address="${postmaster_address/\\@/@}" +fi + #if $plugin_expire ; then # info "Install plugin 'expire'.." #else @@ -3282,6 +3287,25 @@ EOF echo -e "$rc_skipped" fi + _conf_file="/usr/local/dovecot-${_version}/etc/dovecot/conf.d/20-managesieve.conf" + echononl " Create empty file '$(basename "${_conf_file}")'.." + if [[ ! -f "${_conf_file}" ]] ; then + _failed=false + cat <<'EOF' > "${_conf_file}" 2> "${log_file}" +## +## ManageSieve specific settings +## +EOF + if [ "$?" = 0 ]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + error "Creating file '${_conf_file}' failed!" + fi + else + echo -e "$rc_skipped" + fi + blank_line @@ -3297,19 +3321,54 @@ fi ## - PATH=$PATH:$checkdir ## - fi ## - + +_file="/etc/profile" + +_block='checkdir="/usr/local/dovecot/bin" +if [ -d "$checkdir" ]; then + PATH=${check_dir}:$PATH +fi' + echononl " Add /usr/local/dovecot/bin to PATH variable.." -if ! grep "checkdir=\"/usr/local/dovecot/bin\"" /etc/profile > /dev/null ; then - perl -i -n -p -e "s#^(\s*)(export\ +PATH)#checkdir=\"/usr/local/dovecot/bin\"\nif [ -d \\\$checkdir ]; then\n PATH=\\\$PATH:\\\$checkdir\nfi\n\n\1\2#" /etc/profile -if [ "$?" = 0 ]; then - echo -e "$rc_done" + + +if grep -Eq '^\s*checkdir="?/usr/local/dovecot/bin"?$' "${_file}"; then + echo -e "$rc_skipped" else - echo -e "$rc_failed" - fatal Adjusting /etc/profile failed -fi -else - echo -e "$rc_skipped" + cp "${_file}" "/tmp/etc_profile.${backup_date}" > "${log_file}" 2<&1 + if [[ $? -gt 0 ]] ; then + echo -e "$rc_failed" + error "$(cat $log_file)" + else + awk -v b="${_block}" ' + /^export PATH/ { + print b; + print ""; + } + { print } +' "/tmp/etc_profile.${backup_date}" > "${_file}" + if [[ $? -gt 0 ]] ; then + echo -e "$rc_failed" + error "Adding /usr/local/dovecot/bin to PATH variable failed!" + else + echo -e "$rc_done" + fi + fi fi +#echononl " Add /usr/local/dovecot/bin to PATH variable.." +#if ! grep "checkdir=\"/usr/local/dovecot/bin\"" /etc/profile > /dev/null ; then +# perl -i -n -p -e "s#^(\s*)(export\ +PATH)#checkdir=\"/usr/local/dovecot/bin\"\nif [ -d \\\$checkdir ]; then\n PATH=\\\$PATH:\\\$checkdir\nfi\n\n\1\2#" /etc/profile +#if [ "$?" = 0 ]; then +# echo -e "$rc_done" +#else +# echo -e "$rc_failed" +# fatal Adjusting /etc/profile failed +#fi +#else +# echo -e "$rc_skipped" +#fi + echononl " Copy Manpages if not exists.." ## - Manpages ## - @@ -3427,6 +3486,7 @@ blank_line _failed=false +_conf_file="/usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf" if [[ $dovecot_major_version -gt 2 ]] \ || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then @@ -3456,11 +3516,10 @@ if [[ $dovecot_major_version -gt 2 ]] \ # - key_file = /etc/dovecot/ssl/mailserver.key # - } # - - _conf_file="/usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf" echononl " Delete block 'namespace inbox' in file '$(basename "${_conf_file}")'.." if grep -qE '^\s*namespace\s+inbox\s*{' "${_conf_file}"; then - delete_code_block "namespace inbox" "${_conf_file}" + delete_code_block_with_comments "namespace inbox" "${_conf_file}" if [[ $? -gt 1 ]] ; then echo -e "$rc_failed" error "Deleting block 'namespace inbox' in file '$(basename "${_conf_file}")' failed!" @@ -3471,6 +3530,19 @@ if [[ $dovecot_major_version -gt 2 ]] \ echo -e "$rc_skipped" fi + echononl " Delete block 'passdb pam' in file '$(basename "${_conf_file}")'.." + if grep -qE '^\s*passdb\s+pam\s*{' "${_conf_file}"; then + delete_code_block_with_comments "passdb pam" "${_conf_file}" + if [[ $? -gt 1 ]] ; then + echo -e "$rc_failed" + error "Deleting block 'passdb pam' in file '$(basename "${_conf_file}")' failed!" + else + echo -e "$rc_done" + fi + else + echo -e "$rc_skipped" + fi + _protocols_block="protocols {\n imap = yes\n lmtp = yes\n pop3 = yes\n sieve = yes\n}" if [[ -n "$ipv6" ]]; then _listen="$ipv4 $ipv6" @@ -3538,6 +3610,39 @@ if [[ $dovecot_major_version -gt 2 ]] \ } ' "${_conf_file}" > "${_conf_file}.tmp" && mv "${_conf_file}.tmp" "${_conf_file}" + + + + read -r -d '' NEW_BLOCK <<'EOF' +import_environment { + TZ = :/etc/localtime +} +EOF + if grep -qE "^\s*quota \"User quota\"\s+{" "${_conf_file}"; then + + replace_code_block 'quota "User quota"' "${NEW_BLOCK}" "${_conf_file}" || _failed=true + + else + cat <> "${_conf_file}" || _failed=true + +# TZ (timezone) Environment Variable +# +# The use of the TZ environment variable can dramatically reduce the number +# of system calls and kernel context switches performed by the application. +# +# The localtime() function in glibc checks whether the TZ environment variable +# is set. If it is not set, then glibc will use the stat() system call every +# time localtime() is called, even with vDSO in place. +# +# Setting the TZ environment variable to :/etc/localtime (or some other +# timezone file of your choice) for a process will save glibc from making those +# extra unnecessary system calls (Notice the column : prefix before the file path). +$(echo -e "${NEW_BLOCK}") +EOF + fi + + + if grep -qE '^\s*protocols\s*{' "${_conf_file}"; then sed -i "/^\s*protocols\s*{/,/^}/c\ ${_protocols_block}" ${_conf_file} || _failed=true @@ -3674,7 +3779,7 @@ else ## - expire = $db_driver:/usr/local/dovecot/etc/dovecot/sql-dict.conf.ext ## - } ## - - echononl " Adjust file dovecot.conf.." + echononl " Adjust Main configuration ($(basename "${_conf_file}")).." if [[ -n "$ipv6" ]]; then perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(listen\ ?=.*)#\1\#\# \2\n\1listen = $ipv4 $ipv6#g" \ /usr/local/dovecot-${_version}/etc/dovecot/dovecot.conf || _failed=true @@ -4018,11 +4123,11 @@ fi # edit /usr/local/dovecot/etc/dovecot/conf.d/10-master.conf # _failed=false +_conf_file="/usr/local/dovecot-${_version}/etc/dovecot/conf.d/10-master.conf" : > "${log_file}" if [[ $dovecot_major_version -gt 2 ]] \ || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then - _conf_file="/usr/local/dovecot-${_version}/etc/dovecot/conf.d/10-master.conf" # edit /usr/local/dovecot/etc/dovecot/conf.d/10-master.conf # @@ -4159,7 +4264,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # service auth { # # # Auth Listener (XMPP - Jabber) - # inet_listener { + # inet_listener auth-xmpp { # address = $xmpp_listener_addresses # port = $xmpp_listener_port # } @@ -4195,7 +4300,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # } # } # - echononl " Adjusting file $(basename "${_conf_file}").." + echononl " Adjusting Services ($(basename "${_conf_file}")).." :> "${_conf_file}" _param="default_process_limit" @@ -4369,8 +4474,8 @@ EOF service auth { # Auth Listener (XMPP - Jabber) - inet_listener { - address = $xmpp_listener_addresses + inet_listener auth-xmpp { + listen = $xmpp_listener_addresses port = $xmpp_listener_port } @@ -4599,7 +4704,7 @@ else ## - } ## - } ## - - echononl " Adjusting file 10-master.conf.." + echononl " Adjusting Services ($(basename "${_conf_file}")).." perl -i.ORIG -n -p -e "s#^([ ]*)(unix_listener\ +auth-userdb.*)#\1\2\n\1 mode = 0666\n\1 user = dovecot\n\1 group = dovecot#g" \ /usr/local/dovecot-${_version}/etc/dovecot/conf.d/10-master.conf || _failed=true perl -i -n -p -e "s#^([ ]*)(\#.*Postfix.*smtp-auth.*)#\1\2\n\1unix_listener /var/spool/postfix/private/dovecot-auth {\n\1 mode = 0666\n\1 user = postfix\n\1 group = postfix\n\1}#g" \ @@ -4738,7 +4843,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # min_protocol = TLSv1.2 # } - echononl " Adjusting file $(basename "${_conf_file}").." + echononl " Adjusting SSL ($(basename "${_conf_file}")).." :> "${log_file}" read -r -d '' NEW_BLOCK < "${log_file}" - echononl " Adjusting file $(basename "${_conf_file}").." + echononl " Adjusting SSL ($(basename "${_conf_file}")).." _param="ssl" _val="required" @@ -4997,7 +5102,7 @@ EOF echo -e "$rc_done" else echo -e "$rc_failed" - error "Adjusting '$(basename "${_conf_file}") failed" + error "Adjusting SSL ($(basename "${_conf_file}")) failed" echo "" echononl "continue anyway [yes/no]: " @@ -5043,7 +5148,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # # mailbox_list_index # - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Adjusting base configurations ($(basename "${_conf_file}")).." :> "${log_file}" @@ -5086,10 +5191,6 @@ mail_driver = maildir mail_path = ~/Maildir EOF - if [[ $? -gt 0 ]] ; then - _failed=true - fi - fi if grep -qE '^\s*mail_uid\s*=' "${_conf_file}" \ @@ -5121,10 +5222,6 @@ mail_uid = vmail mail_gid = vmail EOF - if [[ $? -gt 0 ]] ; then - _failed=true - fi - fi if grep -qE '^\s*first_valid_uid\s*=' "${_conf_file}" \ @@ -5156,9 +5253,6 @@ first_valid_uid = ${vmail_uid} last_valid_uid = ${vmail_uid} EOF - if [[ $? -gt 0 ]] ; then - _failed=true - fi fi if grep -qE '^\s*first_valid_gid\s*=' "${_conf_file}" \ @@ -5190,9 +5284,6 @@ first_valid_gid = ${vmail_gid} last_valid_gid = ${vmail_gid} EOF - if [[ $? -gt 0 ]] ; then - _failed=true - fi fi if grep -qE '^\s*mail_temp_dir\s*=' "${_conf_file}" ; then @@ -5213,10 +5304,6 @@ EOF mail_temp_dir = /var/vmail/tmp EOF - if [[ $? -gt 0 ]] ; then - _failed=true - fi - fi if grep -qE '^\s*auth_socket_path\s*=' "${_conf_file}" ; then @@ -5225,9 +5312,6 @@ EOF "/run/dovecot/auth-userdb" \ "${_conf_file}" >> "${log_file}" 2>&1 - if [[ $? -gt 0 ]] ; then - _failed=true - fi else cat <> "${_conf_file}" || _failed=true @@ -5236,35 +5320,28 @@ EOF auth_socket_path = /run/dovecot/auth-userdb EOF - if [[ $? -gt 0 ]] ; then - _failed=true - fi - fi - if grep -qE '^\s*mail_plugins\s*=' "${_conf_file}" ; then - replace_variable \ - "mail_plugins" \ - "quota acl" \ - "${_conf_file}" >> "${log_file}" 2>&1 - if [[ $? -gt 0 ]] ; then - _failed=true - fi + read -r -d '' NEW_BLOCK <<'EOF' +mail_plugins { + acl = yes + quota = yes +} +EOF + if grep -qE "^\s*mail_plugins\s+{" "${_conf_file}"; then + + replace_code_block "mail_plugins" "${NEW_BLOCK}" "${_conf_file}" || _failed=true else cat <> "${_conf_file}" || _failed=true # A list of mail plugins to load. -mail_plugins = quota acl +$(echo -e "${NEW_BLOCK}") EOF - - if [[ $? -gt 0 ]] ; then - _failed=true - fi - fi + if grep -qE '^\s*mailbox_list_index\s*=' "${_conf_file}" ; then replace_variable \ "mailbox_list_index" \ @@ -5287,9 +5364,6 @@ EOF mailbox_list_index = yes EOF - if [[ $? -gt 0 ]] ; then - _failed=true - fi fi @@ -5334,7 +5408,7 @@ else ## - ## - mailbox_list_index = yes ## - - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Adjusting base configurations ($(basename "${_conf_file}")).." perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(mail_location\ +=.*)#\1\#\# \2\n\1mail_location = maildir:/var/vmail/%d/%n/Maildir#g" \ "${_conf_file}" || _failed=true perl -i -n -p -e "s#^([ ]*)\#?\ ?(mail_uid.*)#\1\#\# \2\n\1mail_uid = vmail#g" \ @@ -5885,7 +5959,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # } # } - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Adjusting Mailboxes ($(basename "${_conf_file}"))" read -r -d '' NEW_BLOCK <<'EOF' namespace inbox { @@ -6035,7 +6109,7 @@ else ## - } ## - - echononl " Adjusting file '$(basename "${_conf_file}")'" + echononl " Adjusting Mailboxes ($(basename "${_conf_file}"))" perl -i.ORIG -n -p -e "s#^([ ]*)(mailbox\ +Drafts\ +{.*)#\1\2\n\1 auto = subscribe#g" \ ${_conf_file} || _failed=true if [ "$spam_folder" != "Junk" ]; then @@ -6088,7 +6162,7 @@ _conf_file="/usr/local/dovecot-${_version}/etc/dovecot/conf.d/10-auth.conf" if [[ $dovecot_major_version -gt 2 ]] \ || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Adjusting Authentication ($(basename "${_conf_file}")).." # edit /usr/local/dovecot/etc/dovecot/conf.d/10-auth.conf # @@ -6215,7 +6289,7 @@ else ## - !include auth-sql.conf.ext # comment all other includes ## - auth_username_translation = "%@" ## - - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Adjusting Authentication ($(basename "${_conf_file}")).." perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(disable_plaintext_auth\ +=.*)#\1\#\# \2\n\1disable_plaintext_auth = yes#" \ ${_conf_file} || _failed=true perl -i -n -p -e "s#^([ ]*)\#?\ ?(auth_mechanisms\ +=.*)#\1\#\# \2\n\1auth_mechanisms = $auth_mechanisms#g" \ @@ -6274,7 +6348,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # userdb_driver = sql # userdb_args = /usr/local/dovecot/etc/dovecot/sql-connect.conf.ext - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Adjusting SQL auth '$(basename "${_conf_file}")'.." if [[ "$db_driver" = "pgsql" ]]; then @@ -6490,7 +6564,7 @@ else ## - args = /usr/local/dovecot/etc/dovecot/sql-connect.conf.ext ## - } ## - - echononl " Adjusting file auth-sql.conf.ext" + echononl " Adjusting SQL auth '$(basename "${_conf_file}")'.." perl -i.ORIG -n -p -e "s#^([ ]*)(args\ ?=.*)#\1\#\# \2\n\1args = /usr/local/dovecot/etc/dovecot/sql-connect.conf.ext#g" \ /usr/local/dovecot-${_version}/etc/dovecot/conf.d/auth-sql.conf.ext @@ -6506,10 +6580,11 @@ fi # edit /usr/local/dovecot/etc/dovecot/conf.d/auth-sql.conf.ext # create file /usr/local/dovecot-${_version}/etc/dovecot/sql-connect.conf.ext # _failed=false +_conf_file="/usr/local/dovecot-${_version}/etc/dovecot/sql-connect.conf" if [[ $dovecot_major_version -gt 2 ]] \ || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then - echononl " Create sql configuration file 'sql-connect.conf.ext'.." + echononl " Create sql configuration file '$(basename "${_conf_file}")'.." if [[ "$db_driver" = "pgsql" ]]; then @@ -6597,7 +6672,7 @@ else ## - create sql configuration file ## - - echononl " Create sql configuration file 'sql-connect.conf.ext'.." + echononl " Create sql configuration file '$(basename "${_conf_file}")'.." if [ "$db_driver" = "pgsql" ]; then cat < /usr/local/dovecot-${_version}/etc/dovecot/sql-connect.conf.ext @@ -6686,7 +6761,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # :msg,contains,"stored mail into mailbox"\ # -/var/log/dovecot.lmtp - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Configure logging ($(basename "${_conf_file}")).." if grep -qE "^\s*log_path\s*=" "${_conf_file}"; then @@ -6714,7 +6789,7 @@ if [[ $dovecot_major_version -gt 2 ]] \ # log_path = /var/log/dovecot.log # info_log_path = /var/log/dovecot-info.log # -log_path =syslog +log_path = syslog EOF fi @@ -6811,7 +6886,7 @@ else ## - :msg,contains,"stored mail into mailbox"\ ## - -/var/log/dovecot.lmtp ## - - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Configure logging ($(basename "${_conf_file}")).." perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(log_path\ ?=.*)#\1\#\# \2\n\1log_path = syslog#g" \ ${_conf_file} || _failed=true perl -i -n -p -e "s#^([ ]*)\#?\ ?(syslog_facility\ ?=.*)#\1\#\# \2\n\1syslog_facility = local1#g" \ @@ -6921,11 +6996,14 @@ if [[ $dovecot_major_version -gt 2 ]] \ # lda_mailbox_autocreate = no # # protocol lda { - # mail_plugins = $mail_plugins sieve + # mail_plugins { + # sieve = yes + # quota = yes + # } # } # - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Configure lda ($(basename "${_conf_file}")).." if grep -qE "^\s*postmaster_address\s*=" "${_conf_file}"; then @@ -6983,11 +7061,10 @@ EOF read -r -d '' NEW_BLOCK <<'EOF' protocol lda { - # A list of mail plugins to load. - # - # The boolean list can be configured as a space or comma-separated list, which replaces - # the previous boolean list entirely. - mail_plugins = ${mail_plugins} sieve + mail_plugins { + sieve = yes + quota = yes + } } EOF @@ -7023,7 +7100,7 @@ else ## - lda_mailbox_autocreate = no ## - mail_plugins = $mail_plugins sieve ## - - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Configure lda ($(basename "${_conf_file}")).." perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(postmaster_address\ +=.*)#\1\#\# \2\n\1postmaster_address = $postmaster_address#g" \ "${_conf_file}" || _failed=true perl -i -n -p -e "s#^([ ]*)\#?\ ?(hostname\ +=.*)#\1\#\# \2\n\1hostname = $hostname#g" \ @@ -7058,12 +7135,15 @@ if [[ $dovecot_major_version -gt 2 ]] \ # # protocol lmtp { # postmaster_address = $postmaster_address - # mail_plugins = $mail_plugins sieve + # mail_plugins { + # sieve = yes + # quota = yes + # } # } # : > "${log_file}" - echononl " Adjusting file '$(basename "${_conf_file}")'.." + echononl " Configure lmtp ($(basename "${_conf_file}")).." if grep -qE "^\s*lmtp_save_to_detail_mailbox\s*=" "${_conf_file}"; then @@ -7079,23 +7159,23 @@ lmtp_save_to_detail_mailbox = no EOF fi - read -r -d '' NEW_BLOCK <<'EOF' + postmaster_address="argus@oopen.de" + read -r -d '' NEW_BLOCK <> "${_conf_file}" || _failed=true - -# Enable quota plugin for tracking and enforcing the quota. -$(echo -e "${NEW_BLOCK}") -EOF - fi - - if [[ $? -gt 0 ]] ; then - _failed=true - fi - read -r -d '' NEW_BLOCK <<'EOF' protocol imap { @@ -9590,7 +9660,7 @@ quota user { quota_storage_percentage = 100 # user is no longer over quota threshold = under - execute quota-warning { + execute quota-warn-under { args = below %{user} } } @@ -9646,6 +9716,22 @@ service quota-warning { } } +EOF + + replace_or_append_code_block "service quota-warning" "${NEW_BLOCK}" "${_conf_file}" || _failed=true + + + read -r -d '' NEW_BLOCK <<'EOF' +service quota-warn-under { + executable = script /usr/local/bin/quota-warn-under.sh + # use some unprivileged user for executing the quota warn-under script + user = vmail + unix_listener quota-warn-under { + user = vmail + mode = 0666 + } +} + EOF replace_or_append_code_block "service quota-warning" "${NEW_BLOCK}" "${_conf_file}" || _failed=true @@ -9695,7 +9781,7 @@ else ## - } ## - } ## - - echononl " Adjust file 90-quota.conf" + echononl " Adjust quota file '$(basename "${_conf_file}")'" cp -a /usr/local/dovecot-${_version}/etc/dovecot/conf.d/90-quota.conf \ /usr/local/dovecot-${_version}/etc/dovecot/conf.d/90-quota.conf.ORIG cat <>/usr/local/dovecot-${_version}/etc/dovecot/conf.d/90-quota.conf @@ -9731,7 +9817,100 @@ EOF fi # edit /usr/local/dovecot/etc/dovecot/conf.d/90-quota.conf -if $_new ; then +if [[ $dovecot_major_version -gt 2 ]] \ + || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then + + echononl " Create quota warning script.." + ## - create the user-warning script + ## - + cat </usr/local/bin/quota-warning.sh +#!/usr/bin/env bash + +# author: zhang huangbin +# purpose: send mail to notify user when his mailbox quota exceeds a +# specified limit. +# project: iredmail (http://www.iredmail.org/) + +LANG=en_US.UTF-8 + +percent=\$1 +user=\$2 + +cat << EOF | /usr/local/libexec/dovecot/dovecot-lda-d \${user} -o quota_enforce=no" +Date: \`date +"%a, %e %b %Y %H:%M:%S %z"\` +From: $from_address +Reply-to: $reply_to +To:\${user} +subject: mailbox quota warning: \${percent}% belegt. +content-type: text/plain; + charset=utf-8 + +Hallo! + +Deine Mailbox für das Postfach + \${user} +ist nun zu über \${percent}% voll. Damit Du weiterhin E-Mails +empfangen kannst, lösche bitte vorhandene E-Mails vom Server. + +Dies geht zum Beispiel via Webmailer: + $webmailer + +Viele Grüße + +$salutation +${_EOF:-EOF} +EOF + if [ "$?" = 0 ]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + fatal "Create quota warning script /usr/local/bin/quota-warning.sh failed" + fi + + chmod 755 /usr/local/bin/quota-warning.sh + + echononl " Create quota warn-under script.." + ## - create the user-warning script + ## - + cat </usr/local/bin/quota-warn-under.sh +#!/usr/bin/env bash + +percent=\$1 +user=\$2 + +cat << EOF | /usr/local/libexec/dovecot/dovecot-lda-d \${user} -o quota_enforce=no" +Date: \`date +"%a, %e %b %Y %H:%M:%S %z"\` +From: $from_address +Reply-to: $reply_to +To:\${user} +Subject: mailbox quota \$PERCENT% +content-type: text/plain; + charset=utf-8 + +Hallo! + +Deine Mailbox + \${user} +kann nun wieder E-MAIL empfangen. + +Der Füllstand derzeit beträgt: + \$PERCENT% + +Viele Grüße + +$salutation +${_EOF:-EOF} +EOF + if [ "$?" = 0 ]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + fatal "Create quota warn-under script /usr/local/bin/quota-warn-under.sh failed" + fi + + chmod 755 /usr/local/bin/quota-warning.sh + +else echononl " Create quota warning script.." ## - create the user-warning script @@ -9818,7 +9997,7 @@ _conf_file="/usr/local/dovecot-${_version}/etc/dovecot/conf.d/20-imap.conf" if [[ $dovecot_major_version -gt 2 ]] \ || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then - echononl " Add mail_plugin imap_acl to '20-imap.conf'.." + echononl " Add mail_plugin imap_acl to file '$(basename "${_conf_file}")'.." read -r -d '' NEW_BLOCK <> "${_conf_file}" || _failed=true - -# Enable internal ACL support -${NEW_BLOCK} -EOF - fi + echononl " Configure acl - file '$(basename "${_conf_file}")'.." read -r -d '' NEW_BLOCK <<'EOF' @@ -9991,13 +10155,14 @@ EOF # - per-mailbox: Each mailbox has separate ACL rules. They are stored in a # dovecot-acl file in each mailbox (or mail_control_path) directory. This # is the default. +acl_driver = vfile EOF fi read -r -d '' NEW_BLOCK <<'EOF' - namespace shared { + type = shared separator = / @@ -10006,7 +10171,7 @@ namespace shared { # Changed: 2.4.0 The shared namespaces now use $user, # $username and $domain template variables, rather than # the old %%u, %%n and %%d. - prefix = shared/${user}/ + prefix = shared/$user/ # Mail location setting mail_home = /var/vmail/%{user | domain}/%{user | username} @@ -10083,7 +10248,7 @@ else ## - } ## - _failed=false - echononl " Configure acl (90-acl.conf)" + echononl " Configure acl file '$(basename "${_conf_file}")'" perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(acl\ +=.*)#\1\#\# \2\n\n\1\# Without global ACLs:\n\1acl = vfile\n\n\1\# With global ACLs in /etc/dovecot/acls/ directory:\n\1\#acl = vfile:/etc/dovecot/acls\n\1\#acl = vfile:/etc/dovecot/acls:cache_secs=300#g" \ /usr/local/dovecot-${_version}/etc/dovecot/conf.d/90-acl.conf || _failed=true perl -i -n -p -e "s#^([ ]*)\#?\ ?(acl_shared_dict\ +=.*)#\1\#\# \2\n\1acl_shared_dict = proxy::acl#g" \ @@ -10199,12 +10364,12 @@ _conf_file="/usr/local/dovecot-${_version}/etc/dovecot/sql-dict.conf.ext" if [[ $dovecot_major_version -gt 2 ]] \ || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then - echononl " Renew file '$(basename "${_conf_file}")'.." - echo -e "$rc_not_yet_implemented" + echononl " Renew SQL dict file '$(basename "${_conf_file}")'.." + echo -e "$rc_not_needed_anymore" else - echononl " Renew file '$(basename "${_conf_file}")'.." + echononl " Renew SQL dict file '$(basename "${_conf_file}")'.." if [ "$db_driver" = "pgsql" ]; then @@ -10515,11 +10680,129 @@ fi # edit /usr/local/dovecot/etc/dovecot/conf.d/20-managesieve.conf # _failed=false +_conf_file="/usr/local/dovecot-${_version}/etc/dovecot/conf.d/20-managesieve.conf" if [[ $dovecot_major_version -gt 2 ]] \ || ( [[ $dovecot_major_version -eq 2 ]] && [[ $dovecot_minor_version -gt 3 ]] ); then - echononl " Configure managesieve '20-managesieve.conf'.." - echo -e "$rc_not_yet_implemented" + echononl " Configure managesieve '$(basename "${_conf_file}")'.." + + read -r -d '' NEW_BLOCK <> "${_conf_file}" || _failed=true + +# Used by both the Sieve plugin and the ManageSieve protocol +${NEW_BLOCK} +EOF + fi + + + if ! $_failed ; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + error "Adjusting Adjusting file ${_conf_file} failed" + error "$(cat "${log_file}")" + + echo "" + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Interupted by user" + fi else