]> git.proxmox.com Git - mirror_acme.sh.git/blob - deploy/cpanel_uapi.sh
fix formatting
[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 #
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/
8 #
9 # Written by Santeri Kannisto <santeri.kannisto@webseodesigners.com>
10 # Public domain, 2017-2018
11
12 #export DEPLOY_CPANEL_USER=myusername
13
14 ######## Public functions #####################
15
16 #domain keyfile certfile cafile fullchain
17
18 cpanel_uapi_deploy() {
19 _cdomain="$1"
20 _ckey="$2"
21 _ccert="$3"
22 _cca="$4"
23 _cfullchain="$5"
24
25 _debug _cdomain "$_cdomain"
26 _debug _ckey "$_ckey"
27 _debug _ccert "$_ccert"
28 _debug _cca "$_cca"
29 _debug _cfullchain "$_cfullchain"
30
31 if ! _exists uapi; then
32 _err "The command uapi is not found."
33 return 1
34 fi
35 # read cert and key files and urlencode both
36 _cert=$(_url_encode <"$_ccert")
37 _key=$(_url_encode <"$_ckey")
38
39 _debug _cert "$_cert"
40 _debug _key "$_key"
41
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"
45 return 1
46 fi
47 _savedomainconf DEPLOY_CPANEL_USER "$DEPLOY_CPANEL_USER"
48 _response=$(uapi --user="$DEPLOY_CPANEL_USER" SSL install_ssl domain="$_cdomain" cert="$_cert" key="$_key")
49 else
50 _response=$(uapi SSL install_ssl domain="$_cdomain" cert="$_cert" key="$_key")
51 fi
52 error_response="status: 0"
53 if test "${_response#*$error_response}" != "$_response"; then
54 _err "Error in deploying certificate:"
55 _err "$_response"
56 return 1
57 fi
58
59 _debug response "$_response"
60 _info "Certificate successfully deployed"
61 return 0
62 }