You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

6 years ago
6 years ago
  1. #!/usr/bin/env sh
  2. #Here is a script to deploy cert to mailcow.
  3. #returns 0 means success, otherwise error.
  4. ######## Public functions #####################
  5. #domain keyfile certfile cafile fullchain
  6. mailcow_deploy() {
  7. _cdomain="$1"
  8. _ckey="$2"
  9. _ccert="$3"
  10. _cca="$4"
  11. _cfullchain="$5"
  12. _debug _cdomain "$_cdomain"
  13. _debug _ckey "$_ckey"
  14. _debug _ccert "$_ccert"
  15. _debug _cca "$_cca"
  16. _debug _cfullchain "$_cfullchain"
  17. _mailcow_path="${DEPLOY_MAILCOW_PATH}"
  18. if [ -z "$_mailcow_path" ]; then
  19. _err "Mailcow path is not found, please define DEPLOY_MAILCOW_PATH."
  20. return 1
  21. fi
  22. _ssl_path="${_mailcow_path}/data/assets/ssl/"
  23. if [ ! -d "$_ssl_path" ]; then
  24. _err "Cannot find mailcow ssl path: $_ssl_path"
  25. return 1
  26. fi
  27. _info "Copying key and cert"
  28. _real_key="$_ssl_path/key.pem"
  29. if ! cat "$_ckey" >"$_real_key"; then
  30. _err "Error: write key file to: $_real_key"
  31. return 1
  32. fi
  33. _real_fullchain="$_ssl_path/cert.pem"
  34. if ! cat "$_cfullchain" >"$_real_fullchain"; then
  35. _err "Error: write cert file to: $_real_fullchain"
  36. return 1
  37. fi
  38. DEFAULT_MAILCOW_RELOAD="cd ${_mailcow_path} && docker-compose restart postfix-mailcow dovecot-mailcow nginx-mailcow"
  39. _reload="${DEPLOY_MAILCOW_RELOAD:-$DEFAULT_MAILCOW_RELOAD}"
  40. _info "Run reload: $_reload"
  41. if eval "$_reload"; then
  42. _info "Reload success!"
  43. fi
  44. return 0
  45. }