bunkerweb/scripts/certbot-renew.sh
2020-03-28 23:05:05 +01:00

31 lines
975 B
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
function replace_in_file() {
# escape slashes
pattern=$(echo "$2" | sed "s/\//\\\\\//g")
replace=$(echo "$3" | sed "s/\//\\\\\//g")
sed -i "s/$pattern/$replace/g" "$1"
}
# check if HTTP to HTTPS is enabled
# then disable it temporarily
if [ grep -q "include /etc/nginx/redirect-http-to-https.conf;" "/etc/nginx/nginx.conf" ] ; then
replace_in_file "/etc/nginx/nginx.conf" "include /etc/nginx/redirect-http-to-https.conf;" "#include /etc/nginx/redirect-http-to-https.conf;"
if [ -f /run/nginx/nginx.pid ] ; then
/usr/sbin/nginx -s reload
fi
fi
# ask a new certificate if needed
certbot renew
# enable HTTP to HTTPS if needed
if [ grep -q "#include /etc/nginx/redirect-http-to-https.conf;" "/etc/nginx/nginx.conf" ] ; then
replace_in_file "/etc/nginx/nginx.conf" "#include /etc/nginx/redirect-http-to-https.conf;" "include /etc/nginx/redirect-http-to-https.conf;"
fi
# reload nginx
if [ -f /run/nginx/nginx.pid ] ; then
/usr/sbin/nginx -s reload
fi