2019-07-29 09:14:36 +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
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
FQDN="$(hostname --fqdn)"
|
|
|
|
else
|
|
|
|
FQDN="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ssl_cfg_path="/tmp/docker-mailserver/ssl"
|
|
|
|
|
|
|
|
if [ ! -d "$ssl_cfg_path" ]; then
|
|
|
|
mkdir "$ssl_cfg_path"
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
|
|
|
# Create an unpassworded private key and create an unsigned public key certificate
|
2019-07-29 09:14:36 +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
|
2019-07-29 09:14:36 +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
|
2019-07-29 09:14:36 +00:00
|
|
|
cat "$ssl_cfg_path"/"$FQDN"-key.pem "$ssl_cfg_path"/"$FQDN"-cert.pem > "$ssl_cfg_path"/"$FQDN"-combined.pem
|