From: Christian Heller <c.heller@plomlompom.de>
Date: Tue, 11 Mar 2025 17:34:39 +0000 (+0100)
Subject: Further improve borg script.
X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/foo.html?a=commitdiff_plain;h=24576f6e78a07ed351db7abc009d8a6d451d1a3c;p=config

Further improve borg script.
---

diff --git a/testing/aptmark/user b/testing/aptmark/user
index 2bd0811..6d421f4 100644
--- a/testing/aptmark/user
+++ b/testing/aptmark/user
@@ -1,5 +1,7 @@
 # for secrets
 pmount
+# ping won't work for user without this
+linux-sysctl-defaults
 # generally useful
 ack
 vim
diff --git a/testing/home/desktop/.local/bin/borgplom b/testing/home/desktop/.local/bin/borgplom
index a09db58..95dd580 100755
--- a/testing/home/desktop/.local/bin/borgplom
+++ b/testing/home/desktop/.local/bin/borgplom
@@ -5,28 +5,37 @@ PATH_BORGKEYS="${HOME}/.config/borg/keys"
 NAME_REPO=borg
 NAME_ARCHIVE=orgdir
 
-if [ -z "${BORG_PASSPHRASE}" ]; then
-    stty -echo
-    printf "Borg passphrase: "
-    read passphrase
-    stty echo
-    printf "\n"
-    export BORG_PASSPHRASE="${passphrase}"
-fi
-
 if [ "$1" = "orgpull" ]; then
     ls -1 "${PATH_BORGKEYS}/" | while read FILENAME; do
         NAME_SERVER=$(echo "${FILENAME}" | sed 's/.*@//')
         if ! ping -c1 -W2 "${NAME_SERVER}" > /dev/null 2>&1; then
             echo "Cannot reach ${NAME_SERVER}, skipping."
-	    continue
+            continue
         fi
         REPO="${NAME_SERVER}:${NAME_REPO}"
-	ARCHIVES=$(borg list "${REPO}")  # separate step so we may fail early on bad passphrase
+        while true; do
+            set +e
+            ARCHIVES=$(borg list "${REPO}")  # separate step so we may fail early on bad passphrase
+            RESULT=$?
+            set -e
+            if [ "${RESULT}" = "0" ]; then
+                break
+            elif [ "${RESULT}" != "2" ]; then
+                echo "Aborting due to unexpected ${NAME_BORGAPP} error."
+                exit 1
+            else
+                stty -echo
+                printf "Borg passphrase: "
+                read passphrase
+                stty echo
+                printf "\n"
+                export BORG_PASSPHRASE="${passphrase}"
+            fi
+        done
         ARCHIVE=$(echo "${ARCHIVES}" | grep "${NAME_ARCHIVE}" | tail -1 | cut -f1 -d' ')
         echo "Pulling archive: ${ARCHIVE}"
         cd /
         borg extract --verbose "${REPO}::${ARCHIVE}"
-	break
+        break
     done
 fi