2017-11-17 18:42:34 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -eo pipefail
|
|
|
|
__dirname=$(cd $(dirname "$0"); pwd -P)
|
|
|
|
cd ${__dirname}
|
|
|
|
|
|
|
|
hash certbot 2>/dev/null || not_found=true
|
|
|
|
if [ $not_found ]; then
|
|
|
|
echo "Certbot not found. You need to install certbot to use this script."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-11-17 19:43:06 +00:00
|
|
|
if [ "$WO_SSL" = "NO" ] || [ ! -z "$WO_SSL_KEY" ]; then
|
2017-11-17 18:42:34 +00:00
|
|
|
echo "SSL not enabled, or manual SSL key specified, exiting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-11-17 19:43:06 +00:00
|
|
|
DOMAIN="${WO_HOST:=$1}"
|
2017-11-17 18:42:34 +00:00
|
|
|
if [ -z $DOMAIN ]; then
|
|
|
|
echo "Usage: $0 <my.domain.com>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Generate/update certificate
|
2017-11-17 20:18:17 +00:00
|
|
|
certbot certonly --tls-sni-01-port $WO_PORT --work-dir ./letsencrypt --config-dir ./letsencrypt --logs-dir ./letsencrypt --standalone -d $DOMAIN --register-unsafely-without-email --agree-tos --keep
|
2017-11-17 18:42:34 +00:00
|
|
|
|
|
|
|
# Create ssl dir if necessary
|
|
|
|
if [ ! -e ssl/ ]; then
|
|
|
|
mkdir ssl
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update symlinks
|
|
|
|
if [ -e ssl/key.pem ]; then
|
|
|
|
rm ssl/key.pem
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e ssl/cert.pem ]; then
|
|
|
|
rm ssl/cert.pem
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e "letsencrypt/live/$DOMAIN" ]; then
|
2017-11-17 20:18:17 +00:00
|
|
|
ln -vs "../letsencrypt/live/$DOMAIN/privkey.pem" ssl/key.pem
|
|
|
|
ln -vs "../letsencrypt/live/$DOMAIN/chain.pem" ssl/cert.pem
|
2017-11-17 18:42:34 +00:00
|
|
|
fi
|