rendered paste body#!/bin/sh
SSL_CERT="/etc/ssl/certs/dovecot.pem"
SSL_KEY="/etc/ssl/private/dovecot.pem"
rm $SSL_CERT $SSL_KEY
echo "Creating generic self-signed certificate: $SSL_CERT"
echo "(replace with hand-crafted or authorized one if needed)."
cd /etc/ssl/certs
# DEFAULTS
PATH=$PATH:/usr/bin/ssl
HOSTNAME=`hostname -s`
DOMAINNAME=`hostname -d`
FQDN=`hostname -f`
MAILNAME=`cat /etc/mailname 2> /dev/null || hostname -f`
ORGANIZATION="Dovecot mail server"
# OVER-RIDES
HOSTNAME="mail"
DOMAINNAME="alvinpotter.com"
FQDN="mail.alvinpotter.com"
MAILNAME="mail.alvinpotter.com"
ORGANIZATION="Alvin Potter's mail server"
# SHOW
echo "PATH=[$PATH]"
echo "HOSTNAME=[$HOSTNAME]"
echo "DOMAINNAME=[$DOMAINNAME]"
echo "FQDN=[$FQDN]"
echo "MAILNAME=[$MAILNAME]"
# GENERATE
(openssl req -new -x509 -days 365 -nodes -out $SSL_CERT -keyout $SSL_KEY > /dev/null 2>&1 <<+
.
.
.
$ORGANIZATION
$HOSTNAME.$DOMAINNAME
$FQDN
root@$MAILNAME
+
) || echo "Warning : Bad SSL config, can't generate certificate"
chown root:dovecot $SSL_CERT || true
chmod 0644 $SSL_CERT || true
chown root:dovecot $SSL_KEY || true
chmod 0600 $SSL_KEY || true
ls -l $SSL_CERT $SSL_KEY