X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=all_new_2018%2Fletsencrypt.sh;h=18f9aa4f0d50d9aa494d97aef328d045ff78387b;hb=dbb2ad6d064a1037213d4631729c08953d43ed87;hp=01f8a813c02f4b66ea675e9af7257e672737bce3;hpb=395d9b2fbde8811206b26fab39eee609c14f4fd1;p=config diff --git a/all_new_2018/letsencrypt.sh b/all_new_2018/letsencrypt.sh index 01f8a81..18f9aa4 100755 --- a/all_new_2018/letsencrypt.sh +++ b/all_new_2018/letsencrypt.sh @@ -1,9 +1,17 @@ #!/bin/sh +# Install or copy LetsEncrypt certificates on/from server. +# +# First argument: server +# Second argument: "get" or "put" +# +# "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" @@ -13,10 +21,7 @@ action="$2" 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}$'" -elif [ "${action}" = "get" ]; then +if [ "${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/"' scp plom@${server}:~/letsencrypt.tar . @@ -25,7 +30,6 @@ elif [ "${action}" = "put" ]; then scp letsencrypt.tar plom@${server}:~/ ssh -t plom@${server} 'su -c "rmdir /etc/letsencrypt && mv letsencrypt.tar /etc/ && cd /etc/ && tar xf letsencrypt.tar && rm letsencrypt.tar"' else - echo "Action must be 'set', 'get', or 'put'." + echo "Action must be 'get', or 'put'." false fi -