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.
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/
9 # Written by Santeri Kannisto <santeri.kannisto@webseodesigners.com>
10 # Public domain, 2017-2018
12 #export DEPLOY_CPANEL_USER=myusername
14 ######## Public functions #####################
16 #domain keyfile certfile cafile fullchain
18 cpanel_uapi_deploy
() {
25 _debug _cdomain
"$_cdomain"
27 _debug _ccert
"$_ccert"
29 _debug _cfullchain
"$_cfullchain"
31 if ! _exists uapi
; then
32 _err
"The command uapi is not found."
35 # read cert and key files and urlencode both
36 _cert
=$
(_url_encode
<"$_ccert")
37 _key
=$
(_url_encode
<"$_ckey")
42 if [ "$(id -u)" = 0 ]; then
43 if [ -z "$DEPLOY_CPANEL_USER" ]; then
44 _err
"It seems that you are root, please define the target user name: export DEPLOY_CPANEL_USER=username"
47 _savedomainconf DEPLOY_CPANEL_USER
"$DEPLOY_CPANEL_USER"
48 _response
=$
(uapi
--user="$DEPLOY_CPANEL_USER" SSL install_ssl domain
="$_cdomain" cert
="$_cert" key
="$_key")
50 _response
=$
(uapi SSL install_ssl domain
="$_cdomain" cert
="$_cert" key
="$_key")
52 error_response
="status: 0"
53 if test "${_response#*$error_response}" != "$_response"; then
54 _err
"Error in deploying certificate:"
59 _debug response
"$_response"
60 _info
"Certificate successfully deployed"