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.

57 lines
1.3 KiB

8 years ago
8 years ago
8 years ago
8 years ago
  1. #!/bin/bash
  2. # Here is the script to deploy the cert to your cpanel using the cpanel API.
  3. # Uses command line uapi. Cpanel username is needed only when run as root.
  4. # Returns 0 when success, otherwise error.
  5. # Written by Santeri Kannisto <santeri.kannisto@2globalnomads.info>
  6. # Public domain, 2017
  7. #export DEPLOY_CPANEL_USER=myusername
  8. #export DEPLOY_CPANEL_PASSWORD=PASSWORD
  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 [[ $EUID -eq 0 ]]
  30. then
  31. _opt="--user=$DEPLOY_CPANEL_USER SSL install_ssl"
  32. else
  33. _opt="SSL install_ssl"
  34. fi
  35. _debug _opt "$_opt"
  36. response=$(uapi $_opt domain="$_cdommain" cert="$_cert" key="$_key")
  37. if [ $? -ne 0 ]
  38. then
  39. _err "Error in deploying certificate:"
  40. _err "$response"
  41. return 1
  42. fi
  43. _debug response "$response"
  44. _info "Certificate successfully deployed"
  45. }