home · contact · privacy
Move encryption key addition to separate script.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 15 Dec 2018 18:19:30 +0000 (19:19 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 15 Dec 2018 18:19:30 +0000 (19:19 +0100)
all_new_2018/setup_scripts/add_encryption_key.sh [new file with mode: 0644]

diff --git a/all_new_2018/setup_scripts/add_encryption_key.sh b/all_new_2018/setup_scripts/add_encryption_key.sh
new file mode 100644 (file)
index 0000000..71a9488
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+set -e
+
+# Ensure we have a GPG target to encrypt to.
+if [ $# -lt 1 ]; then
+    echo "Need public key ID as argument."
+    false
+fi
+gpg_key="$1"
+
+config_tree_prefix="${HOME}/config/all_new_2018"
+apt -y install gnupg dirmngr
+keyservers='sks-keyservers.net/ keys.gnupg.net'
+set +e
+while true; do
+    do_break=0
+    for keyserver in $(echo "${keyservers}"); do
+        su plom -c "gpg --no-tty --keyserver $keyserver --recv-key ${gpg_key}"
+        if [ $? -eq "0" ]; then
+            do_break=1
+            break
+        fi
+        echo "Attempt with keyserver ${keyserver} unsuccessful, trying other."
+    done
+    if [ "${do_break}" -eq "1" ]; then
+        break
+    fi
+done
+set -e
+# TODO: We may remove dirmngr here if only this script installed it.