Last active
December 23, 2021 11:21
-
-
Save williamdes/7a63ba6af24ea91edaf988ba8078b0fa to your computer and use it in GitHub Desktop.
Add a certificate to an existing certificate using acme.sh
This file contains hidden or 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/sh | |
# Source: https://gist.github.com/williamdes/7a63ba6af24ea91edaf988ba8078b0fa | |
set -eu | |
if [ -z "${1:-}" ]; then | |
echo "Missing the domain name to add" | |
echo "Use: ~/add-cert.sh mynewdomain.tld" | |
echo "To add multiple domains you can use: ~/add-cert.sh \"mynewdomain.tld -d www.mynewdomain.tld\"" | |
exit 1 | |
fi | |
CERT_DOMAIN="foo.tld" | |
# Fetch domain name list, select the interesting part, make it multi line to remove duplicates | |
DOMAINS="$(~/.acme.sh/acme.sh --list --listraw | grep -F "${CERT_DOMAIN}" | cut -d '|' -f 3 | tr ',' '\n' | sort -t '.' | uniq)" | |
echo "Domain list:" | |
echo "${DOMAINS}" | |
echo "-------------------" | |
# build it back but removing the trailing ',' the rebuild operation did | |
DOMAINS="$(echo "${DOMAINS}" | tr '\n' ',' | sed 's/.$//' | sed 's/,/ -d /g')" | |
echo "Waiting 3 seconds so you can check the list" | |
sleep 3 | |
~/.acme.sh/acme.sh --issue -d "${CERT_DOMAIN}" \ | |
-d ${DOMAINS} \ | |
-d $1 \ | |
-w /var/www/ssl-challenges/ --server letsencrypt --reloadcmd "service apache2 reload" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment