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.

62 lines
1.8 KiB

8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
  1. #!/usr/bin/env sh
  2. # Here is the script to deploy the cert to your cpanel using the cpanel API.
  3. # Uses command line uapi. --user option is needed only if run as root.
  4. # Returns 0 when success.
  5. #
  6. # Please note that I am no longer using Github. If you want to report an issue
  7. # or contact me, visit https://forum.webseodesigners.com/web-design-seo-and-hosting-f16/
  8. #
  9. # Written by Santeri Kannisto <santeri.kannisto@webseodesigners.com>
  10. # Public domain, 2017-2018
  11. #export DEPLOY_CPANEL_USER=myusername
  12. ######## Public functions #####################
  13. #domain keyfile certfile cafile fullchain
  14. cpanel_uapi_deploy() {
  15. _cdomain="$1"
  16. _ckey="$2"
  17. _ccert="$3"
  18. _cca="$4"
  19. _cfullchain="$5"
  20. _debug _cdomain "$_cdomain"
  21. _debug _ckey "$_ckey"
  22. _debug _ccert "$_ccert"
  23. _debug _cca "$_cca"
  24. _debug _cfullchain "$_cfullchain"
  25. if ! _exists uapi; then
  26. _err "The command uapi is not found."
  27. return 1
  28. fi
  29. # read cert and key files and urlencode both
  30. _cert=$(_url_encode < "$_ccert")
  31. _key=$(_url_encode < "$_ckey")
  32. _debug _cert "$_cert"
  33. _debug _key "$_key"
  34. if [ "$(id -u)" = 0 ]; then
  35. if [ -z "$DEPLOY_CPANEL_USER" ]; then
  36. _err "It seems that you are root, please define the target user name: export DEPLOY_CPANEL_USER=username"
  37. return 1
  38. fi
  39. _savedomainconf DEPLOY_CPANEL_USER "$DEPLOY_CPANEL_USER"
  40. _response=$(uapi --user="$DEPLOY_CPANEL_USER" SSL install_ssl domain="$_cdomain" cert="$_cert" key="$_key")
  41. else
  42. _response=$(uapi SSL install_ssl domain="$_cdomain" cert="$_cert" key="$_key")
  43. fi
  44. error_response="status: 0"
  45. if test "${_response#*$error_response}" != "$_response"; then
  46. _err "Error in deploying certificate:"
  47. _err "$_response"
  48. return 1
  49. fi
  50. _debug response "$_response"
  51. _info "Certificate successfully deployed"
  52. return 0
  53. }