home · contact · privacy
d4ca0d15d9d9f2812d120b1fccbcd4fe34f84cf2
[config] / all_new_2018 / letsencrypt_local_set.sh
1 #!/bin/sh
2 set -e
3
4 # Ensure we have a mail address as argument.
5 if [ $# -lt 2 ]; then
6     echo "Need target domain and mail address as argument."
7     false
8 fi
9 domain="$1"
10 mail_address="$2"
11
12 # If port 80 blocked by iptables, open it.
13 set +e
14 iptables -C INPUT -p tcp --dport 80 -j ACCEPT
15 open_iptables="$?"
16 set -e
17 if [ "${open_iptables}" -eq "1" ]; then
18     iptables -A INPUT -p tcp --dport 80 -j ACCEPT
19 fi
20
21 # Create new certificate and copy it to /etc/letsencrypt.
22 certbot certonly --standalone --agree-tos -m "${mail_address}" -d "${domain}"
23
24 # Remove iptables rule to open port 80 if we added it.
25 if [ "${open_iptables}" -eq "1" ]; then
26     iptables -D INPUT -p tcp --dport 80 -j ACCEPT
27 fi