home · contact · privacy
Fix encoding bug.
[config] / all_new_2018 / letsencrypt.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 # We need certbot to get LetsEncrypt certificates.
12 apt install -y certbot
13
14 # If port 80 blocked by iptables, open it.
15 set +e
16 iptables -C INPUT -p tcp --dport 80 -j ACCEPT
17 open_iptables="$?"
18 set -e
19 if [ "${open_iptables}" -eq "1" ]; then
20     iptables -A INPUT -p tcp --dport 80 -j ACCEPT
21 fi
22
23 # Create new certificate and copy it to /etc/letsencrypt.
24 certbot certonly --standalone --agree-tos -m "${mail_address}" -d "$(hostname -f)"
25
26 # Remove iptables rule to open port 80 if we added it.
27 if [ "${open_iptables}" -eq "1" ]; then
28     iptables -D INPUT -p tcp --dport 80 -j ACCEPT
29 fi