3 #Here is a script to deploy cert to mailcow.
5 #returns 0 means success, otherwise error.
7 ######## Public functions #####################
9 #domain keyfile certfile cafile fullchain
17 _debug _cdomain
"$_cdomain"
19 _debug _ccert
"$_ccert"
21 _debug _cfullchain
"$_cfullchain"
23 _getdeployconf DEPLOY_MAILCOW_PATH
24 _getdeployconf DEPLOY_MAILCOW_RELOAD
26 _debug DEPLOY_MAILCOW_PATH
"$DEPLOY_MAILCOW_PATH"
27 _debug DEPLOY_MAILCOW_RELOAD
"$DEPLOY_MAILCOW_RELOAD"
29 if [ -z "$DEPLOY_MAILCOW_PATH" ]; then
30 _err
"Mailcow path is not found, please define DEPLOY_MAILCOW_PATH."
34 _savedeployconf DEPLOY_MAILCOW_PATH
"$DEPLOY_MAILCOW_PATH"
35 [ -n "$DEPLOY_MAILCOW_RELOAD" ] && _savedeployconf DEPLOY_MAILCOW_RELOAD
"$DEPLOY_MAILCOW_RELOAD"
37 _ssl_path
="$DEPLOY_MAILCOW_PATH"
38 if [ -f "$DEPLOY_MAILCOW_PATH/generate_config.sh" ]; then
39 _ssl_path
="$DEPLOY_MAILCOW_PATH/data/assets/ssl/"
42 if [ ! -d "$_ssl_path" ]; then
43 _err
"Cannot find mailcow ssl path: $_ssl_path"
47 _info
"Copying key and cert"
48 _real_key
="$_ssl_path/key.pem"
49 if ! cat "$_ckey" >"$_real_key"; then
50 _err
"Error: write key file to: $_real_key"
54 _real_fullchain
="$_ssl_path/cert.pem"
55 if ! cat "$_cfullchain" >"$_real_fullchain"; then
56 _err
"Error: write cert file to: $_real_fullchain"
60 DEFAULT_MAILCOW_RELOAD
="docker restart \$(docker ps --quiet --filter name=nginx-mailcow --filter name=dovecot-mailcow --filter name=postfix-mailcow)"
61 _reload
="${DEPLOY_MAILCOW_RELOAD:-$DEFAULT_MAILCOW_RELOAD}"
63 _info
"Run reload: $_reload"
64 if eval "$_reload"; then
65 _info
"Reload success!"