OpenDroneMap-WebODM/nginx/letsencrypt-autogen.sh

59 wiersze
1.5 KiB
Bash
Czysty Zwykły widok Historia

2017-11-17 18:42:34 +00:00
#!/bin/bash
__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
2017-11-17 20:46:26 +00:00
# Stop nginx if needed (free the port used by the standalone server)
nginx_was_running="NO"
2017-11-17 21:16:52 +00:00
pgrep nginx > /dev/null
2017-11-17 20:56:18 +00:00
if [ $? -eq 0 ]; then
2017-11-17 20:46:26 +00:00
killall nginx
nginx_was_running="YES"
fi
2017-11-17 18:42:34 +00:00
# Generate/update certificate
certbot certonly --http-01-port 8080 --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
2017-11-17 20:33:55 +00:00
ln -vs "../letsencrypt/live/$DOMAIN/fullchain.pem" ssl/cert.pem
2017-11-17 21:41:41 +00:00
else
echo -e "\033[91mWARN: We couldn't automatically generate the SSL certificate. Review the console log. WebODM will likely be inaccessible.\033[39m"
2017-11-17 20:46:26 +00:00
fi
# Restart nginx if necessary
if [ "$nginx_was_running" = "YES" ]; then
echo "Restarting nginx..."
nginx -c $(pwd)/nginx-ssl.conf
fi