]>
Commit | Line | Data |
---|---|---|
6c3430b6 | 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 | |
04e0f87c | 7 | |
8 | #export DEPLOY_CPANEL_USER=myusername | |
9 | #export DEPLOY_CPANEL_PASSWORD=PASSWORD | |
10 | ||
11 | ######## Public functions ##################### | |
12 | ||
13 | #domain keyfile certfile cafile fullchain | |
6c3430b6 | 14 | |
04e0f87c | 15 | cpanel_deploy() { |
16 | _cdomain="$1" | |
17 | _ckey="$2" | |
18 | _ccert="$3" | |
19 | _cca="$4" | |
20 | _cfullchain="$5" | |
21 | ||
22 | _debug _cdomain "$_cdomain" | |
23 | _debug _ckey "$_ckey" | |
24 | _debug _ccert "$_ccert" | |
25 | _debug _cca "$_cca" | |
26 | _debug _cfullchain "$_cfullchain" | |
27 | ||
6c3430b6 | 28 | # read cert and key files and urlencode both |
29 | _certstr=`cat "$_ccert"` | |
30 | _keystr=`cat "$_ckey"` | |
31 | _cert=$(php -r "echo urlencode(\"$_certstr\");") | |
32 | _key=$(php -r "echo urlencode(\"$_keystr\");") | |
33 | ||
34 | _debug _cert "$_cert" | |
35 | _debug _key "$_key" | |
36 | ||
37 | if [[ $EUID -eq 0 ]] | |
38 | then | |
39 | _opt="--user=$DEPLOY_CPANEL_USER SSL install_ssl" | |
40 | else | |
41 | _opt="SSL install_ssl" | |
42 | fi | |
43 | ||
44 | _debug _opt "$_opt" | |
45 | ||
46 | response=$(uapi $_opt domain="$_cdommain" cert="$_cert" key="$_key") | |
47 | ||
48 | if [ $? -ne 0 ] | |
49 | then | |
50 | _err "Error in deploying certificate:" | |
51 | _err "$response" | |
52 | return 1 | |
53 | fi | |
04e0f87c | 54 | |
6c3430b6 | 55 | _debug response "$response" |
56 | _info "Certificate successfully deployed" | |
04e0f87c | 57 | } |