X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=all_new_2018%2Fsetup_scripts%2Fletsencrypt.sh;fp=all_new_2018%2Fsetup_scripts%2Fletsencrypt.sh;h=29ed3b6276630145fbacd460fe56171e4ab0c485;hb=eafecb0ed8c373dc4f33b6190375fdc3d5c4d841;hp=0000000000000000000000000000000000000000;hpb=60e6aeb6b26bd7b810deb8c53fe696022cb673b4;p=config diff --git a/all_new_2018/setup_scripts/letsencrypt.sh b/all_new_2018/setup_scripts/letsencrypt.sh new file mode 100755 index 0000000..29ed3b6 --- /dev/null +++ b/all_new_2018/setup_scripts/letsencrypt.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Certify current server with LetsEncrypt. +# Uses hostname -f for the domain we want to certify. +set -e + +# Ensure we have a mail address as argument. +if [ $# -lt 1 ]; then + echo "Need mail address as argument." + false +fi +mail_address="$1" + +# We need certbot to get LetsEncrypt certificates. +apt install -y certbot + +# If port 80 blocked by iptables, open it. +set +e +iptables -C INPUT -p tcp --dport 80 -j ACCEPT +open_iptables="$?" +set -e +if [ "${open_iptables}" -eq "1" ]; then + iptables -A INPUT -p tcp --dport 80 -j ACCEPT +fi + +# Create new certificate and copy it to /etc/letsencrypt. +certbot certonly --standalone --agree-tos -m "${mail_address}" -d "$(hostname -f)" + +# Remove iptables rule to open port 80 if we added it. +if [ "${open_iptables}" -eq "1" ]; then + iptables -D INPUT -p tcp --dport 80 -j ACCEPT +fi