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.

53 lines
1.3 KiB

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