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.

51 lines
1.3 KiB

8 years ago
8 years ago
8 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. # Written by Santeri Kannisto <santeri.kannisto@2globalnomads.info>
  6. # Public domain, 2017
  7. #export DEPLOY_CPANEL_USER=myusername
  8. ######## Public functions #####################
  9. #domain keyfile certfile cafile fullchain
  10. cpanel_uapi() {
  11. _cdomain="$1"
  12. _ckey="$2"
  13. _ccert="$3"
  14. _cca="$4"
  15. _cfullchain="$5"
  16. _debug _cdomain "$_cdomain"
  17. _debug _ckey "$_ckey"
  18. _debug _ccert "$_ccert"
  19. _debug _cca "$_cca"
  20. _debug _cfullchain "$_cfullchain"
  21. # read cert and key files and urlencode both
  22. _certstr=$(cat "$_ccert")
  23. _keystr=$(cat "$_ckey")
  24. _cert=$(php -r "echo urlencode(\"$_certstr\");")
  25. _key=$(php -r "echo urlencode(\"$_keystr\");")
  26. _debug _cert "$_cert"
  27. _debug _key "$_key"
  28. if [ "$(id -u)" = 0 ]; then
  29. _response=$(uapi --user="$DEPLOY_CPANEL_USER" SSL install_ssl domain="$_cdomain" cert="$_cert" key="$_key")
  30. else
  31. _response=$(uapi SSL install_ssl domain="$_cdomain" cert="$_cert" key="$_key")
  32. fi
  33. if [ $? -ne 0 ]; then
  34. _err "Error in deploying certificate:"
  35. _err "$_response"
  36. return 1
  37. fi
  38. _debug response "$_response"
  39. _info "Certificate successfully deployed"
  40. return 0
  41. }