home · contact · privacy
Further improve borg script.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 11 Mar 2025 17:34:39 +0000 (18:34 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 11 Mar 2025 17:34:39 +0000 (18:34 +0100)
testing/aptmark/user
testing/home/desktop/.local/bin/borgplom

index 2bd0811f6450e04a6fd9c72e367bf79c52ae4d47..6d421f41d68752dc19e6374aba64dfe0554aca43 100644 (file)
@@ -1,5 +1,7 @@
 # for secrets
 pmount
+# ping won't work for user without this
+linux-sysctl-defaults
 # generally useful
 ack
 vim
index a09db585ab369478a3a809b616ff14a93d2a27c2..95dd580e6a691e828722caa8dcf5b0dedcaa0aaa 100755 (executable)
@@ -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