]> git.proxmox.com Git - mirror_acme.sh.git/blob - deploy/mailcow.sh
Merge pull request #4441 from plummer86/bugfix/_wget_out_fix
[mirror_acme.sh.git] / deploy / mailcow.sh
1 #!/usr/bin/env sh
2
3 #Here is a script to deploy cert to mailcow.
4
5 #returns 0 means success, otherwise error.
6
7 ######## Public functions #####################
8
9 #domain keyfile certfile cafile fullchain
10 mailcow_deploy() {
11 _cdomain="$1"
12 _ckey="$2"
13 _ccert="$3"
14 _cca="$4"
15 _cfullchain="$5"
16
17 _debug _cdomain "$_cdomain"
18 _debug _ckey "$_ckey"
19 _debug _ccert "$_ccert"
20 _debug _cca "$_cca"
21 _debug _cfullchain "$_cfullchain"
22
23 _getdeployconf DEPLOY_MAILCOW_PATH
24 _getdeployconf DEPLOY_MAILCOW_RELOAD
25
26 _debug DEPLOY_MAILCOW_PATH "$DEPLOY_MAILCOW_PATH"
27 _debug DEPLOY_MAILCOW_RELOAD "$DEPLOY_MAILCOW_RELOAD"
28
29 if [ -z "$DEPLOY_MAILCOW_PATH" ]; then
30 _err "Mailcow path is not found, please define DEPLOY_MAILCOW_PATH."
31 return 1
32 fi
33
34 _savedeployconf DEPLOY_MAILCOW_PATH "$DEPLOY_MAILCOW_PATH"
35 [ -n "$DEPLOY_MAILCOW_RELOAD" ] && _savedeployconf DEPLOY_MAILCOW_RELOAD "$DEPLOY_MAILCOW_RELOAD"
36
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/"
40 fi
41
42 if [ ! -d "$_ssl_path" ]; then
43 _err "Cannot find mailcow ssl path: $_ssl_path"
44 return 1
45 fi
46
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"
51 return 1
52 fi
53
54 _real_fullchain="$_ssl_path/cert.pem"
55 if ! cat "$_cfullchain" >"$_real_fullchain"; then
56 _err "Error: write cert file to: $_real_fullchain"
57 return 1
58 fi
59
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}"
62
63 _info "Run reload: $_reload"
64 if eval "$_reload"; then
65 _info "Reload success!"
66 fi
67 return 0
68
69 }