]> git.proxmox.com Git - mirror_acme.sh.git/blob - deploy/cpanel_uapi.sh
Merge pull request #1490 from AlexeyStolyarov/master
[mirror_acme.sh.git] / deploy / cpanel_uapi.sh
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
8 #export DEPLOY_CPANEL_USER=myusername
9
10 ######## Public functions #####################
11
12 #domain keyfile certfile cafile fullchain
13
14 cpanel_uapi_deploy() {
15 _cdomain="$1"
16 _ckey="$2"
17 _ccert="$3"
18 _cca="$4"
19 _cfullchain="$5"
20
21 _debug _cdomain "$_cdomain"
22 _debug _ckey "$_ckey"
23 _debug _ccert "$_ccert"
24 _debug _cca "$_cca"
25 _debug _cfullchain "$_cfullchain"
26
27 if ! _exists uapi; then
28 _err "The command uapi is not found."
29 return 1
30 fi
31 if ! _exists php; then
32 _err "The command php is not found."
33 return 1
34 fi
35 # read cert and key files and urlencode both
36 _certstr=$(cat "$_ccert")
37 _keystr=$(cat "$_ckey")
38 _cert=$(php -r "echo urlencode(\"$_certstr\");")
39 _key=$(php -r "echo urlencode(\"$_keystr\");")
40
41 _debug _cert "$_cert"
42 _debug _key "$_key"
43
44 if [ "$(id -u)" = 0 ]; then
45 if [ -z "$DEPLOY_CPANEL_USER" ]; then
46 _err "It seems that you are root, please define the target user name: export DEPLOY_CPANEL_USER=username"
47 return 1
48 fi
49 _savedomainconf DEPLOY_CPANEL_USER "$DEPLOY_CPANEL_USER"
50 _response=$(uapi --user="$DEPLOY_CPANEL_USER" SSL install_ssl domain="$_cdomain" cert="$_cert" key="$_key")
51 else
52 _response=$(uapi SSL install_ssl domain="$_cdomain" cert="$_cert" key="$_key")
53 fi
54 error_response="status: 0"
55 if test "${_response#*$error_response}" != "$_response"; then
56 _err "Error in deploying certificate:"
57 _err "$_response"
58 return 1
59 fi
60
61 _debug response "$_response"
62 _info "Certificate successfully deployed"
63 return 0
64 }