home · contact · privacy
WIP.
[config] / all_new_2018 / letsencrypt.sh
index 01f8a813c02f4b66ea675e9af7257e672737bce3..c89e37f660afabe10a5df008a06a3d5fdaee2824 100755 (executable)
@@ -1,9 +1,23 @@
 #!/bin/sh
+# Install or copy LetsEncrypt certificates on/from server.
+#
+# First argument: server
+# Second argument: either "set" or "get" or "put"
+#
+# "set" install certbot on remote server and requests a new certificate
+# for it. This needs two more arguments: an e-mail address for future
+# communication with LetsEncrypt, and the domain for which to request
+# the certificate (might plausibly be equivalent to the first argument
+# though). This needs port 80 open on the server.
+#
+# "get" copies the server's /etc/letsencrypt to a local letsencrypt.tar.
+#
+# "set" copies a local letsencrypt.tar to the server's /etc/letsencrypt.
 set -e
 
 # Ensure we have a server name as argument.
-if [ ! $# -eq 2 ]; then
-    echo "Need server and action as argument."
+if [ $# -lt 2 ]; then
+    echo "Need server and action as arguments."
     false
 fi
 server="$1"
@@ -14,8 +28,14 @@ eval $(ssh-agent)
 ssh-add ~/.ssh/id_rsa
 
 if [ "${action}" = "set" ]; then
-    # Install certificate.
-    ssh -t plom@${server} "su -c 'apt -y install certbot && certbot certonly --standalone -d ${server}$'"
+    # Install certificate. This needs port 80 open (443 does not work here).
+    if [ $# -lt 4 ]; then
+        echo "Need mail address and domain as arguments."
+        false
+    fi
+    mail="$3"
+    domain="$4"
+    ssh -t plom@${server} "su -c 'apt -y install certbot && certbot certonly --standalone --agree-tos -m ${mail} -d ${server}'"
 elif [ "${action}" = "get" ]; then
     # Get /etc/letsencrypt/ as tar file.
     ssh -t plom@${server} 'su -c "cd /etc/ && tar cf letsencrypt.tar letsencrypt && chown plom:plom letsencrypt.tar && mv letsencrypt.tar /home/plom/"'
@@ -28,4 +48,3 @@ else
     echo "Action must be 'set', 'get', or 'put'."
     false
 fi
-