Skip to content

Instantly share code, notes, and snippets.

@jyntran
Last active July 10, 2022 19:10
Show Gist options
  • Save jyntran/7d128004306198e83cb8118c2dba2148 to your computer and use it in GitHub Desktop.
Save jyntran/7d128004306198e83cb8118c2dba2148 to your computer and use it in GitHub Desktop.
Set up/renew Let's Encrypt certificate using certbot
#!/bin/bash
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
case "$KEY" in
--domain) domain="${VALUE}" ;;
--wildcard) wildcard="true" ;;
--help) help="true" ;;
*)
esac
done
if [ -n "$help" ]; then
echo "USAGE: certbot-setup --domain=DOMAIN.COM [--wildcard] [--help]"
elif [ -n "$domain" ]; then
if [ -n "$wildcard" ]; then
sudo certbot certonly --config /etc/letsencrypt/config.ini --agree-tos -d "*.$domain" -d $domain --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
else
sudo certbot certonly --config /etc/letsencrypt/config.ini --agree-tos -d $domain --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
fi
else
echo "ERROR: missing domain - please enter it as domain=YOURDOMAINHERE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment