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.

79 lines
2.0 KiB

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