Last active
February 9, 2017 15:30
-
-
Save slokhorst/0fe3d702a97706c7990a14a910ccfe34 to your computer and use it in GitHub Desktop.
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 | |
##### Fill out the following ##### | |
# Your domains | |
domain="example.com" | |
additional_domains="www.$domain" # colon-separated (:) | |
# DirectAdmin login | |
user="debXXX" | |
password="" | |
# For Let's Encrypt notifications | |
email="admin@example.com" | |
################################## | |
acme_client_version="v0.2.10" | |
acme_data_dir="$HOME/acme-data" | |
acme_cert_dir="$acme_data_dir/certs/acme-v01.api.letsencrypt.org.directory/$domain" | |
html_dir="$HOME/domains/$domain/public_html" | |
if [ -z $additional_domains ] | |
then | |
acme_domains="$domain" | |
else | |
acme_domains="$domain:$additional_domains" | |
fi | |
function setup () { | |
echo "##### downloading acme-client #####" | |
wget https://github.com/kelunik/acme-client/releases/download/$acme_client_version/acme-client.phar | |
chmod +x ./acme-client.phar | |
echo "##### running acme-client setup #####" | |
./acme-client.phar setup -s letsencrypt --storage $acme_data_dir --email $email || exit 1 | |
} | |
function issue () { | |
echo "##### obtaining certificate from Let's Encrypt #####" | |
./acme-client.phar issue -s letsencrypt --storage $acme_data_dir -d $acme_domains -p $html_dir || exit 1 | |
cat $acme_cert_dir/key.pem $acme_cert_dir/fullchain.pem > everything.pem | |
echo "##### uploading certificate to DirectAdmin #####" | |
curl -k "https://localhost:2223/CMD_API_SSL" \ | |
--user "$user:$password" \ | |
--data-urlencode "domain=$domain" \ | |
--data-urlencode "action=save" \ | |
--data-urlencode "type=paste" \ | |
--data-urlencode "certificate@everything.pem" \ | |
|| exit 1 | |
rm everything.pem | |
echo "##### done! #####" | |
} | |
case $1 in | |
"setup") | |
setup | |
;; | |
"issue") | |
issue | |
;; | |
*) | |
if [ ! -x "./acme-client.phar" ] || [ ! -d "$acme_data_dir" ] | |
then | |
setup | |
fi | |
issue | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jij absolute baas. Dank hiervoor!