Your IP : 216.73.216.170


Current Path : /var/lib/dpkg/info/
Upload File :
Current File : //var/lib/dpkg/info/dovecot-common.postinst

#!/bin/sh
set -e

if [ "$1" = "configure" ]; then

  for conffile in dovecot.conf dovecot-ldap.conf dovecot-sql.conf ; do
    # Tell ucf that the file in /usr/share/dovecot is the latest
    # maintainer version, and let it handle how to manage the real
    # configuration file in /etc/dovecot.
    ucf --three-way /usr/share/dovecot/$conffile /etc/dovecot/$conffile
    ucfr dovecot-common /etc/dovecot/$conffile
    if [ "$conffile" != "dovecot.conf" ] && [ -f "/etc/dovecot/$conffile" ]; then
      chmod 0600 /etc/dovecot/$conffile
    fi
  done

  if [ -n "`id -u imapd 2> /dev/null`" ]; then
    deluser imapd || true
    delgroup imapd || true
  fi

  if [ -z "`id -u dovecot 2> /dev/null`" ]; then
    adduser --system --group --home /usr/lib/dovecot --gecos "Dovecot mail server" \
            --no-create-home --disabled-password --quiet dovecot || true
  fi

  ## SSL Certs
  # Certs and key file
  SSL_CERT="/etc/ssl/certs/dovecot.pem"
  SSL_KEY="/etc/ssl/private/dovecot.pem"
  
  # Generate new certs if needed
  if [ -e $SSL_CERT ] || [ -e $SSL_KEY ]; then
    echo "You already have ssl certs for dovecot."
  else
    echo "Creating generic self-signed certificate: $SSL_CERT"
    echo "This certificate will expire in 10 years."
    echo "(replace with hand-crafted or authorized one if needed)."
    cd /etc/ssl/certs
    PATH=$PATH:/usr/bin/ssl
    if ! FQDN="$(hostname -f)"; then
        FQDN="$(hostname)"
        echo WARNING: Could not get FQDN, using \"$FQDN\".
    fi
    MAILNAME="$(cat /etc/mailname 2> /dev/null || echo "$FQDN")"
    (openssl req -newkey rsa:2048  -x509 -days 3652.5 -nodes \
	-rand /dev/urandom -out $SSL_CERT -keyout $SSL_KEY > /dev/null 2>&1 <<+
.
.
.
Dovecot mail server
$FQDN
$FQDN
root@$MAILNAME
+
    ) || echo "Warning : Bad SSL config, can't generate certificate."

    if [ -e $SSL_CERT ] && [ -e $SSL_KEY ]; then
      ucfr dovecot-common $SSL_CERT
      ucfr dovecot-common $SSL_KEY
    
      chown root $SSL_CERT || true
      chgrp dovecot $SSL_CERT || true
      chmod 0644 $SSL_CERT || true
      chown root $SSL_KEY || true
      chgrp dovecot $SSL_KEY || true
      chmod 0600 $SSL_KEY || true
    fi
  fi

  # migration hooks
  if [ -f /etc/dovecot/dovecot.conf ] && grep -q default_mail_env /etc/dovecot/dovecot.conf; then
    sed -i -e 's/^default_mail_env/mail_location/' /etc/dovecot/dovecot.conf
  fi

fi

# Automatically added by dh_installinit
if [ -x "/etc/init.d/dovecot" ]; then
	update-rc.d dovecot defaults 20 >/dev/null
	if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
		invoke-rc.d dovecot start || exit $?
	else
		/etc/init.d/dovecot start || exit $?
	fi
fi
# End automatically added section