Last active
February 27, 2017 12:09
-
-
Save giulianoriccio/ab6ed3157bce7a6d35cb4de057ff1a93 to your computer and use it in GitHub Desktop.
let's encrypt on plesk using certbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# -eq 0 ]] ; then | |
echo "You need to specify the domain name" | |
exit 1 | |
fi | |
host $1 2>&1 > /dev/null | |
if [[ $? != 0 ]] ; then | |
echo "$1 is not a valid domain name" | |
exit 1 | |
fi | |
path=$(mysql -N -uadmin -p`cat /etc/psa/.psa.shadow` -Dpsa -se'select www_root from domains join hosting on hosting.dom_id = domains.id where name = "'"$1"'"') | |
if [[ $path == "" ]] ; then | |
echo "$1 is not on this server" | |
exit 1 | |
fi | |
host "www.$1" 2>&1 > /dev/null | |
if [[ $? != 0 ]] ; then | |
certbot-auto certonly -n --agree-tos --email certificates@rifraf.it --webroot -w $path -d $1 | |
else | |
certbot-auto certonly -n --agree-tos --email certificates@rifraf.it --webroot -w $path -d $1 -d "www.$1" | |
fi | |
if [[ $? != 0 ]] ; then | |
echo "The certificate creation for $1 has failed on Let's Encrypt" | |
exit 1 | |
fi | |
timestamp=$(date +"%Y-%m-%d %H:%M:%S") | |
/usr/local/psa/bin/certificate -c "$1 $timestamp" -domain $1 -key-file /etc/letsencrypt/live/$1/privkey.pem -cert-file /etc/letsencrypt/live/$1/cert.pem -cacert-file /etc/letsencrypt/live/$1/chain.pem | |
if [[ $? != 0 ]] ; then | |
echo "The certificate creation for $1 has failed on Plesk" | |
exit 1 | |
fi | |
/usr/local/psa/bin/subscription -u $1 -certificate-name "$1 $timestamp" | |
if [[ $? != 0 ]] ; then | |
echo "The certificate could not be assigned to $1 on Plesk" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment