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.

75 lines
1.9 KiB

6 years ago
4 years ago
4 years ago
6 years ago
4 years ago
4 years ago
4 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. #Tests if _ssl_path is the mailcow root directory.
  23. if [ -f "${_mailcow_path}/generate_config.sh" ]; then
  24. _ssl_path="${_mailcow_path}/data/assets/ssl/"
  25. else
  26. _ssl_path="${_mailcow_path}"
  27. fi
  28. if [ ! -d "$_ssl_path" ]; then
  29. _err "Cannot find mailcow ssl path: $_ssl_path"
  30. return 1
  31. fi
  32. # ECC or RSA
  33. if [ -z "${Le_Keylength}" ]; then
  34. Le_Keylength=""
  35. fi
  36. if _isEccKey "${Le_Keylength}"; then
  37. _info "ECC key type detected"
  38. _cert_name_prefix="ecdsa-"
  39. else
  40. _info "RSA key type detected"
  41. _cert_name_prefix=""
  42. fi
  43. _info "Copying key and cert"
  44. _real_key="$_ssl_path/${_cert_name_prefix}key.pem"
  45. if ! cat "$_ckey" >"$_real_key"; then
  46. _err "Error: write key file to: $_real_key"
  47. return 1
  48. fi
  49. _real_fullchain="$_ssl_path/${_cert_name_prefix}cert.pem"
  50. if ! cat "$_cfullchain" >"$_real_fullchain"; then
  51. _err "Error: write cert file to: $_real_fullchain"
  52. return 1
  53. fi
  54. DEFAULT_MAILCOW_RELOAD="docker restart $(docker ps -qaf name=postfix-mailcow); docker restart $(docker ps -qaf name=nginx-mailcow); docker restart $(docker ps -qaf name=dovecot-mailcow)"
  55. _reload="${DEPLOY_MAILCOW_RELOAD:-$DEFAULT_MAILCOW_RELOAD}"
  56. _info "Run reload: $_reload"
  57. if eval "$_reload"; then
  58. _info "Reload success!"
  59. fi
  60. return 0
  61. }