2 # Install or copy LetsEncrypt certificates on/from server.
4 # First argument: server
5 # Second argument: either "set" or "get" or "put"
7 # "set" install certbot on remote server and requests a new certificate
8 # for it. This needs two more arguments: an e-mail address for future
9 # communication with LetsEncrypt, and the domain for which to request
10 # the certificate (might plausibly be equivalent to the first argument
11 # though). This needs port 80 open on the server.
13 # "get" copies the server's /etc/letsencrypt to a local letsencrypt.tar.
15 # "set" copies a local letsencrypt.tar to the server's /etc/letsencrypt.
18 # Ensure we have a server name as argument.
20 echo "Need server and action as arguments."
26 # So we only get asked once for decrypting our key.
30 if [ "${action}" = "set" ]; then
31 # Install certificate. This needs port 80 open (443 does not work here).
33 echo "Need mail address and domain as arguments."
38 ssh -t plom@${server} "su -c 'apt update && apt -y install certbot && certbot certonly --standalone --agree-tos -m ${mail} -d ${server}'"
39 elif [ "${action}" = "get" ]; then
40 # Get /etc/letsencrypt/ as tar file.
41 ssh -t plom@${server} 'su -c "cd /etc/ && tar cf letsencrypt.tar letsencrypt && chown plom:plom letsencrypt.tar && mv letsencrypt.tar /home/plom/"'
42 scp plom@${server}:~/letsencrypt.tar .
43 elif [ "${action}" = "put" ]; then
44 # Expand letsencrypt.tar to /etc/letsencrypt/ on server.
45 scp letsencrypt.tar plom@${server}:~/
46 ssh -t plom@${server} 'su -c "rmdir /etc/letsencrypt && mv letsencrypt.tar /etc/ && cd /etc/ && tar xf letsencrypt.tar && rm letsencrypt.tar"'
48 echo "Action must be 'set', 'get', or 'put'."