From 76a46ee1730b9ceb4b50d93ea819357a8d06fe58 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 9 Oct 2017 03:09:40 +0200 Subject: [PATCH] - Add systemd support. - Improve adjusting /etc/postfix/main.cf. --- README.dovecot.systemd | 3 + conf/install_update_dovecot.conf.sample | 7 ++ install_update_dovecot.sh | 145 +++++++++++++++++++++--- 3 files changed, 142 insertions(+), 13 deletions(-) diff --git a/README.dovecot.systemd b/README.dovecot.systemd index 93a0de1..6d2aeaa 100644 --- a/README.dovecot.systemd +++ b/README.dovecot.systemd @@ -15,4 +15,7 @@ https://github.com/dovecot/core/blob/master/dovecot.service.in That's what I missed, thank you a lot. And service seems to handle correctly restarts +Also use: + --with-rundir=/var/run/dovecot + -- diff --git a/conf/install_update_dovecot.conf.sample b/conf/install_update_dovecot.conf.sample index bcbe3da..7234057 100644 --- a/conf/install_update_dovecot.conf.sample +++ b/conf/install_update_dovecot.conf.sample @@ -23,6 +23,13 @@ _version=2.2.28 _pigeonhole=dovecot-2.2-pigeonhole-0.4.16 +# - Install dovecot with systemd support +# - +# - Defaults to 'true' if systemd is present, otherwise to 'false' +# - +systemd_support="" + + # - postmaster_address # - # - Example: diff --git a/install_update_dovecot.sh b/install_update_dovecot.sh index 494afc7..12f90c9 100755 --- a/install_update_dovecot.sh +++ b/install_update_dovecot.sh @@ -25,6 +25,7 @@ curdir=`pwd` log_file="$(mktemp)" +backup_date="$(date +%Y-%m-%d-%H%M)" rc_done="\033[71G[ \033[32mdone\033[m ]" rc_failed="\033[71G[ \033[31m\033[1mfailed\033[m ]" @@ -60,6 +61,21 @@ error(){ echo "" } +warn(){ + echo "" + echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" + echo "" +} + +# - Support systemd ? +# - +if [[ "X$(which systemd)" = "X" ]]; then + SYSTEMD_EXISTS=false +else + SYSTEMD_EXISTS=true +fi + + echo echononl "\tInclude Configuration file.." if [[ ! -f $conf_file ]]; then @@ -70,6 +86,14 @@ else echo -e "$rc_done" fi +if [[ -z "$systemd_support" ]] ; then + if $SYSTEMD_EXISTS ; then + systemd_support=true + else + systemd_support=false + fi +fi + _log_dir=${_src_base_dir}/log-dovecot-$_version @@ -91,6 +115,8 @@ echo "" echo -e "\tDovecot (new) version.........: $_version" echo -e "\t(Sieve) pigeonhole version....: $_pigeonhole" echo "" +echo -e "\tSystemd support...............: $systemd_support" +echo "" echo -e "\tSFolder containing sources....: $_src_base_dir" echo "" echo -e "\tPostmaser adress..............: $postmaster_address" @@ -135,6 +161,10 @@ if $xmpp_listener ; then fi echo "" +if ! $_update ;then + warn "Take care, your PostgreSQL configuration (pg_hba.conf) contains the following line:\n\n\t pg_hba.conf:\n\t \033[1mlocal all postfix trust\033[m" +fi + echononl "Sind die Angaben richtig [ja/nein]: " read OK while [ "X$OK" != "Xyes" -a "X$OK" != "XYes" -a "X$OK" != "Xja" -a "X$OK" != "XJa" \ @@ -219,6 +249,49 @@ if $_new ; then fi export PGPASSWORD=$dbpassword + + +echo "Doing some backups.." + +echononl "\tBackup existing installation log directory.." +if [[ -d "${_log_dir}" ]]; then + mv "${_log_dir}" "${_log_dir}.${backup_date}" + if [ "$?" = 0 ]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + error "Cannot Backup (move) directory '${_log_dir}'" + fi +else + echo -e "$rc_skipped" +fi + +echononl "\tBackup existing installation directory.." +if [[ -d "/usr/local/dovecot-${_version}" ]]; then + mv "/usr/local/dovecot-${_version}" "/usr/local/dovecot-${_version}.${backup_date}" + if [ "$?" = 0 ]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + error "Cannot Backup (move) directory '${_log_dir}'" + fi +else + echo -e "$rc_skipped" +fi + +echononl "\tBackup existing source directory.." +if [[ -d "${_src_base_dir}/dovecot-${_version}" ]]; then + mv "${_src_base_dir}/dovecot-${_version}" "${_src_base_dir}/dovecot-${_version}.${backup_date}" + if [ "$?" = 0 ]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + fatal "Cannot Backup (move) directory '${_src_base_dir}/dovecot-${_version}'" + fi +else + echo -e "$rc_skipped" +fi + mkdir -p $_log_dir @@ -227,6 +300,7 @@ mkdir -p $_log_dir cd ${_src_base_dir} +echo "" echo "Download sources.." ## - Downloud Dovecot 2.2.x @@ -376,14 +450,27 @@ fi cd dovecot-${_version} -echononl "\tConfigure Dovecot.." -./configure \ +config_params=" --prefix=/usr/local/dovecot-${_version} \ --with-${db_driver} \ - --with-gssapi=yes > ${_log_dir}/dovecot-${_version}-configure.log 2>&1 + --with-gssapi=yes + --with-rundir=/var/run/dovecot" +if $systemd_support ; then + config_params="$config_params \ + --with-systemdsystemunitdir=/etc/systemd/system/" +fi + +echononl "\tConfigure Dovecot.." +#./configure \ +# --prefix=/usr/local/dovecot-${_version} \ +# --with-${db_driver} \ +# --with-gssapi=yes > ${_log_dir}/dovecot-${_version}-configure.log 2>&1 #--with-systemdsystemunitdir=/etc/systemd/system \ +LDFLAGS="-s" \ +./configure $config_params > ${_log_dir}/dovecot-${_version}-configure.log 2>&1 + if [ "$?" = 0 ]; then echo -e "$rc_done" else @@ -1438,7 +1525,7 @@ fi ## - _failed=false echononl "\tAdjusting file 20-imap.conf" -perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(protocol imap {)#\1\2\n\n\1 ssl_cert = <$imap_cert\n\1 ssl_key = <$imap_key\n#g" \ +perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(protocol imap \{)#\1\2\n\n\1 ssl_cert = <$imap_cert\n\1 ssl_key = <$imap_key\n#g" \ /usr/local/dovecot-${_version}/etc/dovecot/conf.d/20-imap.conf || _failed=true perl -i -n -p -e "s#^([ ]*)\#?\ ?(mail_max_userip_connections\ +=.*)#\1\#\# \2\n\1mail_max_userip_connections = $max_userip_connections#g" \ /usr/local/dovecot-${_version}/etc/dovecot/conf.d/20-imap.conf || _failed=true @@ -1464,7 +1551,7 @@ fi ## - _failed=false echononl "\tAdjusting file 20-pop3.conf" -perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(protocol pop3 {)#\1\2\n\n\1 ssl_cert = <$pop_cert\n\1 ssl_key = <$pop_key\n#g" \ +perl -i.ORIG -n -p -e "s#^([ ]*)\#?\ ?(protocol pop3 \{)#\1\2\n\n\1 ssl_cert = <$pop_cert\n\1 ssl_key = <$pop_key\n#g" \ /usr/local/dovecot-${_version}/etc/dovecot/conf.d/20-pop3.conf || _failed=true perl -i -n -p -e "s#^([ ]*)\#?\ ?(mail_max_userip_connections\ +=.*)#\1\#\# \2\n\1mail_max_userip_connections = 10#g" \ /usr/local/dovecot-${_version}/etc/dovecot/conf.d/20-pop3.conf || _failed=true @@ -1799,7 +1886,11 @@ EOF ## - Make dovecot start at boot time ## - echononl "\tMake dovecot start at boottime.." - update-rc.d dovecot defaults > /dev/null 2>&1 + if $systemd_support ; then + systemctl enable dovecot > /dev/null 2>&1 + else + update-rc.d dovecot defaults > /dev/null 2>&1 + fi if [ "$?" = 0 ]; then echo -e "$rc_done" else @@ -1817,7 +1908,7 @@ EOF ## - dovecot unix - n n - - pipe ## - flags=drhu user=vmail:vmail argv=/usr/local/dovecot/libexec/dovecot/dovecot-lda -f ${sender} -d ${user}@${nexthop} if ! grep -e dovecot-lda /etc/postfix/master.cf > /dev/null ; then - cp /etc/postfix/master.cf /etc/postfix/master.cf.`date +%Y-%m-%d-%H%M` + cp -a "/etc/postfix/master.cf" "/etc/postfix/master.cf.$backup_date" echononl "\tConfigure /etc/postfix/master.cf to play with dovecot lda" echo -e "\ndovecot unix - n n - - pipe\n flags=drhu user=vmail:vmail argv=/usr/local/dovecot/libexec/dovecot/dovecot-lda -f \${sender} -d \${user}@\${nexthop}" >> /etc/postfix/master.cf if [ "$?" = 0 ]; then @@ -1833,6 +1924,9 @@ EOF ## - ## - add/uncomment: ## - + ## - smtpd_sasl_type = dovecot + ## - smtpd_sasl_path = private/dovecot-auth + ## - ## - virtual_transport = dovecot ## - dovecot_destination_recipient_limit = 1 ## - @@ -1843,8 +1937,17 @@ EOF ## - _failed=false echononl "\tAdjust /etc/postfix/main.cf" - perl -i.`date +%Y-%m-%d-%H%M` -n -p -e "s#^(\s*)(virtual_transport\ *=.*)#\1\#\2\n\1virtual_transport = dovecot\ndovecot_destination_recipient_limit = 1#" \ + + perl -i.$backup_date -n -p -e "s#^(\s*)(smtpd_sasl_auth_enable\ *=.*)#smtpd_sasl_auth_enable = no#" \ /etc/postfix/main.cf || _failed=true + perl -i -n -p -e "s#^(\s*)(smtpd_sasl_type\ *=.*)#smtpd_sasl_type = dovecot#" \ + /etc/postfix/main.cf || _failed=true + perl -i -n -p -e "s#^(\s*)(smtpd_sasl_path\ *=.*)#smtpd_sasl_path = private/dovecot-auth#" \ + /etc/postfix/main.cf || _failed=true + + perl -i -n -p -e "s#^(\s*)(virtual_transport\ *=.*)#virtual_transport = dovecot\ndovecot_destination_recipient_limit = 1#" \ + /etc/postfix/main.cf || _failed=true + perl -i-n -p -e "s#^(\s*)\#?(permit_sasl_authenticated)#\1\2#" /etc/postfix/main.cf || _failed=true if ! $_failed ; then echo -e "$rc_done" @@ -1928,19 +2031,27 @@ if $_new ; then ## - #virtual_transport = dovecot ## - ## - change: + ## - smtpd_sasl_auth_enable = yes ## - smtpd_sasl_type = dovecot ## - smtpd_sasl_path = private/dovecot-auth ## - virtual_transport = lmtp:unix:private/dovecot-lmtp _failed=false echononl "\tAdjust /etc/postfix/main.cf" - perl -i -n -p -e "s#^(\s*)(smtpd_sasl_type\ *=.*)#\1\#\2\n\1smtpd_sasl_type = dovecot#" \ + perl -i -n -p -e "s#^(\s*)(smtpd_sasl_auth_enable\ *=.*)#smtpd_sasl_auth_enable = yes#" \ /etc/postfix/main.cf || _failed=true - perl -i -n -p -e "s#^(\s*)(smtpd_sasl_path\ *=.*)#\1\#\2\n\1smtpd_sasl_path = private/dovecot-auth#" \ + #perl -i -n -p -e "s#^(\s*)(smtpd_sasl_type\ *=.*)#\1\#\2\n\1smtpd_sasl_type = dovecot#" \ + perl -i -n -p -e "s#^(\s*)(smtpd_sasl_type\ *=.*)#smtpd_sasl_type = dovecot#" \ + /etc/postfix/main.cf || _failed=true + #perl -i -n -p -e "s#^(\s*)(smtpd_sasl_path\ *=.*)#\1\#\2\n\1smtpd_sasl_path = private/dovecot-auth#" \ + # /etc/postfix/main.cf || _failed=true + perl -i -n -p -e "s#^(\s*)(smtpd_sasl_path\ *=.*)#smtpd_sasl_path = private/dovecot-auth#" \ /etc/postfix/main.cf || _failed=true - perl -i -n -p -e "s#^(\s*)(virtual_transport\ *=.*)#\1\#\2\n\1virtual_transport = lmtp:unix:private/dovecot-lmtp#" \ + #perl -i -n -p -e "s#^(\s*)(virtual_transport\ *=.*)#\1\#\2\n\1virtual_transport = lmtp:unix:private/dovecot-lmtp#" \ + # /etc/postfix/main.cf || _failed=true + perl -i -n -p -e "s#^(\s*)(virtual_transport\ *=.*)#virtual_transport = lmtp:unix:private/dovecot-lmtp#" \ /etc/postfix/main.cf || _failed=true perl -i-n -p -e "s#^(\s*)(dovecot_destination_recipient_limit.*)#\1\#\2#" /etc/postfix/main.cf || _failed=true if ! $_failed ; then @@ -3067,7 +3178,11 @@ echo -e -n "Restart services (dovecot/postfix)? [y/n]: " read _restart if [ "y" = "$_restart" -o "Y" = "$_restart" -o "Yes" = "$_restart" -o "yes" = "$_restart" ];then echononl "\tRestart dovecot.." - /etc/init.d/dovecot restart > /dev/null 2>&1 + if $systemd_support ; then + systemctl start dovecot + else + /etc/init.d/dovecot restart > /dev/null 2>&1 + fi if [ "$?" = 0 ]; then echo -e "$rc_done" else @@ -3075,7 +3190,11 @@ if [ "y" = "$_restart" -o "Y" = "$_restart" -o "Yes" = "$_restart" -o "yes" = "$ fatal "Restarting dovecot failed" fi echononl "\tRestart postfix.." - /etc/init.d/postfix restart > /dev/null 2>&1 + if $SYSTEMD_EXISTS ; then + systemctl restart postfix + else + /etc/init.d/postfix restart > /dev/null 2>&1 + fi if [ "$?" = 0 ]; then echo -e "$rc_done" else