Handle service upgrades.
authorValentin Vidic <Valentin.Vidic@CARNet.hr>
Thu, 17 Oct 2013 07:04:01 +0000 (09:04 +0200)
committerValentin Vidic <Valentin.Vidic@CARNet.hr>
Thu, 17 Oct 2013 07:04:01 +0000 (09:04 +0200)
src/actions/main.queue
src/functions.sh

index 313bcf0..27e03f6 100644 (file)
@@ -32,10 +32,12 @@ pkg munin-cn                        upgrade_munin
 pkg freeradius-aai             upgrade_freeradius
 pkg openldap-aai               pkgadd openldap-aai
 pkg amavisd-new                        upgrade_amavis
+pkg mysql-server-5.1           upgrade_mysql
 pkg apache2-cn                 upgrade_apache2
 pkg postfix-cn                 upgrade_postfix
+pkg dovecot-cn                 upgrade_dovecot
 pkg bind9-cn                   upgrade_bind
-pkg mysql-cn                   upgrade_mysql
+pkg fail2ban-cn                        upgrade_fail2ban
 true                           upgrade_postgresql
 true                           upgrade first           # neki paketi moraju rucno
 true                           upgrade second          # neke pakete zelimo ranije
index 7037e0d..1e831f4 100644 (file)
@@ -979,6 +979,44 @@ upgrade_postfix () {
   fi
 }
 
+# upgrade the IMAP server
+upgrade_dovecot() {
+  if [ ! -f /etc/dovecot/conf.d/95-local ]; then
+     pkgrm dovecot-cn
+
+     # restore config
+     if [ ! -f /etc/dovecot/dovecot.conf.$backup_ext ]; then
+        mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.$backup_ext
+        cp /usr/share/dovecot/dovecot.conf /etc/dovecot/dovecot.conf
+     fi
+
+     # copy SSL certificates
+     OLD_SSL_CERT="/etc/ssl/certs/dovecot.pem"
+     OLD_SSL_KEY="/etc/ssl/private/dovecot.pem"
+     SSL_CERT="/etc/dovecot/dovecot.pem"
+     SSL_KEY="/etc/dovecot/private/dovecot.pem"
+     if [ -f $OLD_SSL_CERT -a -f $OLD_SSL_KEY -a ! -f $SSL_CERT -a ! -f $SSL_KEY ]; then
+        if [ ! -e /etc/dovecot/private ]; then
+           install -d -o root -g root -m0700 /etc/dovecot/private
+        fi
+
+        cp -av $OLD_SSL_CERT $SSL_CERT
+        cp -av $OLD_SSL_KEY $SSL_KEY
+
+        chown root:dovecot $SSL_CERT
+        chmod 0644 $SSL_CERT
+        chown root:dovecot $SSL_KEY
+        chmod 0600 $SSL_KEY
+     fi
+
+     # install new version and restore local changes
+     pkgadd dovecot-core
+     doveconf -n -c /etc/dovecot/dovecot.conf.$backup_ext > /etc/dovecot/conf.d/95-local
+
+     pkgadd dovecot-cn
+  fi
+}
+
 # upgrade bind separately so DNS is not down for too long
 # or breaks postinst scripts of other cn packages that depend on
 # working resolver
@@ -986,6 +1024,16 @@ upgrade_bind() {
   pkgadd bind9-cn
 }
 
+# handle fail2ban upgrade due to error:
+# trying to overwrite '/etc/fail2ban/filter.d/dovecot.conf', which is also in package fail2ban-cn
+upgrade_fail2ban() {
+  if pkg fail2ban-cn && dpkg -L fail2ban-cn | grep -qF dovecot.conf; then
+    pkgrm fail2ban-cn
+    pkgadd fail2ban
+    pkgadd fail2ban-cn
+  fi
+}
+
 get_variable () {
   local name=$1 file=$2 val