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.

77 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_type="ecdsa"
  39. _cert_name_prefix="ecdsa-"
  40. else
  41. _info "RSA key type detected"
  42. _cert_type="rsa"
  43. _cert_name_prefix=""
  44. fi
  45. _info "Copying key and cert"
  46. _real_key="$_ssl_path/${_cert_name_prefix}key.pem"
  47. if ! cat "$_ckey" >"$_real_key"; then
  48. _err "Error: write key file to: $_real_key"
  49. return 1
  50. fi
  51. _real_fullchain="$_ssl_path/${_cert_name_prefix}cert.pem"
  52. if ! cat "$_cfullchain" >"$_real_fullchain"; then
  53. _err "Error: write cert file to: $_real_fullchain"
  54. return 1
  55. fi
  56. 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)"
  57. _reload="${DEPLOY_MAILCOW_RELOAD:-$DEFAULT_MAILCOW_RELOAD}"
  58. _info "Run reload: $_reload"
  59. if eval "$_reload"; then
  60. _info "Reload success!"
  61. fi
  62. return 0
  63. }