X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=debian%2Fpostinst;h=0b0086bb218b84c3ead90049eadc076f26446d0c;hb=64207e10024398b2031499706b9580fd979c1d15;hp=25e9f5ab601c0636d33fc1c4e09593deea2819bc;hpb=6fad1369335c749ebd2807053cb6727f2d0a5fd9;p=dovecot-cn.git diff --git a/debian/postinst b/debian/postinst index 25e9f5a..0b0086b 100755 --- a/debian/postinst +++ b/debian/postinst @@ -1,4 +1,6 @@ -#!/bin/sh -e +#!/bin/sh + +set -e [ "$1" = "configure" ] || exit 0 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx @@ -7,51 +9,193 @@ . /usr/share/carnet-tools/functions.sh -cp_check_and_sed '^protocols' \ - 's/protocols.*$/protocols = imap imaps pop3 pop3s/g' \ - /etc/dovecot/dovecot.conf || true +move_certs() { + if [ -f /etc/dovecot/private/dovecot.pem -a ! -f /etc/dovecot/private/dovecot.key ]; then + mv -f /etc/dovecot/private/dovecot.pem /etc/dovecot/private/dovecot.key || true + fi + + if [ -f /etc/dovecot/dovecot.pem ]; then + mv -f /etc/dovecot/dovecot.pem /etc/dovecot/private/dovecot.pem || true + fi +} + +put_new_certs() { +# postavlja cert i key na nove putanje iz bustera + cp_check_and_sed '#ssl_key = lenny) -cp_check_and_sed '^mail_extra_groups' \ - 's/^mail_extra_groups/mail_privileged_group/g' \ - /etc/dovecot/dovecot.conf || true +# trazio zelja +cp_check_and_sed '#ssl =' \ + 's/^#ssl =/ssl =/g' \ + /etc/dovecot/conf.d/10-ssl.conf || true +# trazio zelja +cp_check_and_sed 'ssl = no' \ + 's/^ssl = no/ssl = yes/g' \ + /etc/dovecot/conf.d/10-ssl.conf || true -# restart -if [ -x /usr/sbin/invoke-rc.d ]; then - [ -x /etc/init.d/dovecot ] && invoke-rc.d dovecot restart + +dovecert="$(doveconf ssl_cert)" +dovekey="$(doveconf ssl_key)" + +if [ -n "$dovecert" -a -n "$dovekey" ]; then + echo -n "CN: Opcije ssl_cert i ssl_key su pronađene" + + cfile=$(grep -l ^ssl_cert /etc/dovecot/conf.d/*.conf | tail -1) + kfile=$(grep -l ^ssl_key /etc/dovecot/conf.d/*.conf | tail -1) + + if grep -q ^ssl_cert $cfile && grep -q ^ssl_key $kfile; then + if [ "$cfile" != "/etc/dovecot/conf.d/10-ssl.conf" -o "$kfile" != "/etc/dovecot/conf.d/10-ssl.conf" ]; then + echo " izvan 10-ssl.conf (u $cfile), preskačem rekonfiguraciju..." + else + echo " u /etc/dovecot/conf.d/10-ssl.conf. Postavljam default vrijednosti iz Debiana 10..." + put_new_certs + move_certs + fi + fi else - [ -x /etc/init.d/dovecot ] && /etc/init.d/dovecot restart + echo "CN: ssl_cert i ssl_key nisu definirani, postavljam default vrijednosti iz Debiana 10!" + # ako postoji, pomaknut ćemo stari certifikat na novo mjesto i preimenovati kljuc + # ako ne postoje certifikati generiraj ih i postavi na prava mjesta + + move_certs + + if [ ! -f /etc/dovecot/private/dovecot.pem -a ! -f /etc/dovecot/private/dovecot.key ]; then + echo "CN: Pravim certifikat i kljuc i postavljam ih u /etc/dovecot/private..." + /usr/share/dovecot-cn/mkcert.sh || true + fi + put_new_certs +fi + + + +### buster ima ssl_min_protocol umjesto ssl_protocols +# ne radimo ništa ako već postoji ^ssl_min_protocol = TLS*, možda je sistemac smanjivao level TLS-a + +if ! grep -q "^ssl_min_protocol = TLS" /etc/dovecot/conf.d/10-ssl.conf; then + # postavlja minimalni TLS protokol i mijenja ime varijable + cp_check_and_sed '#ssl_protocols =' \ + 's/^#ssl_protocols.*/ssl_min_protocol = TLSv1.2/g' \ + /etc/dovecot/conf.d/10-ssl.conf || true + + # postavlja minimalni TLS protokol ako je varijabla već uključena + cp_check_and_sed 'ssl_protocols =' \ + 's/^ssl_protocols.*/ssl_min_protocol = TLSv1.2/g' \ + /etc/dovecot/conf.d/10-ssl.conf || true + + # samo popravlja inačicu protokola i uključuje varijablu + cp_check_and_sed '#ssl_min_protocol =' \ + 's/^#ssl_min_protocol.*/ssl_min_protocol = TLSv1.2/g' \ + /etc/dovecot/conf.d/10-ssl.conf || true + + # popravlja inačicu protokola ako je varijabla već uključena (ako je zaostao SSLv2 i SSLv3) + cp_check_and_sed 'ssl_min_protocol =' \ + 's/^ssl_min_protocol.*/ssl_min_protocol = TLSv1.2/g' \ + /etc/dovecot/conf.d/10-ssl.conf || true +fi + +### buster ima DH ključ koji se nalazi u paketu dovecot-core +# ne radimo ništa ako već postoji ^ssl_dh koji nije prazan + +if ! grep -q "^ssl_dh = /" /etc/dovecot/conf.d/10-ssl.conf; then + # postavlja DH i uključuje varijablu + cp_check_and_sed '#ssl_dh =' \ + 's,^#ssl_dh.*,ssl_dh =