Browse Source

Wrote missing cpanel.sh

This script I wrote works for me on GoDaddy, but I don't have any other hosting services or cpanel version to test it. Hope it's better than nothing for you. Thanks for your great script!
Cheers,
Santeri
cron
2globalnomads 8 years ago
committed by GitHub
parent
commit
6c3430b6e5
  1. 40
      deploy/cpanel.sh

40
deploy/cpanel.sh

@ -1,8 +1,9 @@
#!/usr/bin/env sh
#Here is the script to deploy the cert to your cpanel account by the cpanel APIs.
#returns 0 means success, otherwise error.
#!/bin/bash
# Here is the script to deploy the cert to your cpanel using the cpanel API.
# Uses command line uapi. Cpanel username is needed only when run as root.
# Returns 0 when success, otherwise error.
# Written by Santeri Kannisto <santeri.kannisto@2globalnomads.info>
# Public domain, 2017
#export DEPLOY_CPANEL_USER=myusername #export DEPLOY_CPANEL_USER=myusername
#export DEPLOY_CPANEL_PASSWORD=PASSWORD #export DEPLOY_CPANEL_PASSWORD=PASSWORD
@ -10,6 +11,7 @@
######## Public functions ##################### ######## Public functions #####################
#domain keyfile certfile cafile fullchain #domain keyfile certfile cafile fullchain
cpanel_deploy() { cpanel_deploy() {
_cdomain="$1" _cdomain="$1"
_ckey="$2" _ckey="$2"
@ -23,7 +25,33 @@ cpanel_deploy() {
_debug _cca "$_cca" _debug _cca "$_cca"
_debug _cfullchain "$_cfullchain" _debug _cfullchain "$_cfullchain"
_err "Not implemented yet"
# read cert and key files and urlencode both
_certstr=`cat "$_ccert"`
_keystr=`cat "$_ckey"`
_cert=$(php -r "echo urlencode(\"$_certstr\");")
_key=$(php -r "echo urlencode(\"$_keystr\");")
_debug _cert "$_cert"
_debug _key "$_key"
if [[ $EUID -eq 0 ]]
then
_opt="--user=$DEPLOY_CPANEL_USER SSL install_ssl"
else
_opt="SSL install_ssl"
fi
_debug _opt "$_opt"
response=$(uapi $_opt domain="$_cdommain" cert="$_cert" key="$_key")
if [ $? -ne 0 ]
then
_err "Error in deploying certificate:"
_err "$response"
return 1 return 1
fi
_debug response "$response"
_info "Certificate successfully deployed"
} }
Loading…
Cancel
Save