From 638ca1a8a28830427ee86251c214384853486730 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 6 May 2019 23:06:04 +0200
Subject: [PATCH] Enhance secrets setup.

---
 buster/setup_scripts/setup_secrets.sh | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/buster/setup_scripts/setup_secrets.sh b/buster/setup_scripts/setup_secrets.sh
index e33a52d..25a49bb 100755
--- a/buster/setup_scripts/setup_secrets.sh
+++ b/buster/setup_scripts/setup_secrets.sh
@@ -1,19 +1,25 @@
 #!/bin/sh
 set -e
 
-if [ "$#" -ne 1 ]; then
-    echo 'Need exactly one argument (directory).'
-    false
-fi
-directory="$1"
+dev="sdb"
+source_dir="/media/${dev}/to_usb"
+target_dir="${HOME}/tmp_to_usb"
 borgkeys_dir=~/.config/borg/keys
 ssh_dir=~/.ssh
-
-cd "${directory}"
+while [ ! -e /dev/"${dev}" ]; do
+    echo "Put secrets drive into slot for /dev/${dev}, then hit Return."
+    read
+done
+sudo pmount /dev/"${dev}"
+cp -a "${source_dir}" "${target_dir}"
+sudo pumount "${dev}"
+echo "You can remove /dev/${dev} now."
+cd "${target_dir}"
 mkdir -p "${ssh_dir}"
 cp id_rsa ~/.ssh
 ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
 tar xf borg_keyfiles.tar
 mkdir -p "${borgkeys_dir}"
 mv borg_keyfiles/* "${borgkeys_dir}"
-rmdir borg_keyfiles
+cd
+rm -rf "${target_dir}"
-- 
2.30.2