home · contact · privacy
a308ddcc444c58eba27d9ca7130ea393e2fab729
[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 1 ]; then
6     echo "Need mail address as argument."
7     false
8 fi
9 mail_address="$1"
10
11 # If port 80 blocked by iptables, open it.
12 set +e
13 iptables -C INPUT -p tcp --dport 80 -j ACCEPT
14 open_iptables="$?"
15 set -e
16 if [ "${open_iptables}" -eq "1" ]; then
17     iptables -A INPUT -p tcp --dport 80 -j ACCEPT
18 fi
19
20 # Create new certificate and copy it to /etc/letsencrypt.
21 certbot certonly --standalone --agree-tos -m "${mail_address}" -d "$(hostname -f)"
22
23 # Remove iptables rule to open port 80 if we added it.
24 if [ "${open_iptables}" -eq "1" ]; then
25     iptables -D INPUT -p tcp --dport 80 -j ACCEPT
26 fi