2020-10-21 16:16:32 +00:00
|
|
|
#! /bin/bash
|
2015-08-18 11:13:08 +00:00
|
|
|
|
2019-07-29 09:14:36 +00:00
|
|
|
set -e
|
2015-08-18 18:43:42 +00:00
|
|
|
|
2019-07-29 09:14:36 +00:00
|
|
|
# check if FQDN was passed as arguement in setup.sh
|
2020-10-21 16:16:32 +00:00
|
|
|
if [[ -z ${1} ]]
|
|
|
|
then
|
|
|
|
FQDN="$(hostname --fqdn)"
|
2019-07-29 09:14:36 +00:00
|
|
|
else
|
2020-10-21 16:16:32 +00:00
|
|
|
FQDN="${1}"
|
2019-07-29 09:14:36 +00:00
|
|
|
fi
|
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
SSL_CFG_PATH="/tmp/docker-mailserver/ssl"
|
2019-07-29 09:14:36 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
if [[ ! -d ${SSL_CFG_PATH} ]]
|
|
|
|
then
|
|
|
|
mkdir "${SSL_CFG_PATH}"
|
2019-07-29 09:14:36 +00:00
|
|
|
fi
|
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
cd "${SSL_CFG_PATH}" || { echo "cd ${SSL_CFG_PATH} error" ; exit ; }
|
|
|
|
|
2015-08-18 18:43:42 +00:00
|
|
|
# Create CA certificate
|
|
|
|
/usr/lib/ssl/misc/CA.pl -newca
|
2020-10-21 16:16:32 +00:00
|
|
|
|
2015-08-18 18:43:42 +00:00
|
|
|
# Create an unpassworded private key and create an unsigned public key certificate
|
2020-10-21 16:16:32 +00:00
|
|
|
openssl req -new -nodes -keyout "${SSL_CFG_PATH}"/"${FQDN}"-key.pem -out "${SSL_CFG_PATH}"/"${FQDN}"-req.pem -days 3652
|
|
|
|
|
2015-08-18 18:43:42 +00:00
|
|
|
# Sign the public key certificate with CA certificate
|
2020-10-21 16:16:32 +00:00
|
|
|
openssl ca -out "${SSL_CFG_PATH}"/"${FQDN}"-cert.pem -infiles "${SSL_CFG_PATH}"/"${FQDN}"-req.pem
|
|
|
|
|
2015-08-18 18:43:42 +00:00
|
|
|
# Combine certificates for courier
|
2020-10-21 16:16:32 +00:00
|
|
|
cat "${SSL_CFG_PATH}"/"${FQDN}"-key.pem "${SSL_CFG_PATH}"/"${FQDN}"-cert.pem > "${SSL_CFG_PATH}"/"${FQDN}"-combined.pem
|