]> gitweb.fluxo.info Git - borger.git/commitdiff
Ask the passphrase only once and be verbose when asking
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 8 Aug 2019 20:13:50 +0000 (17:13 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 8 Aug 2019 20:13:50 +0000 (17:13 -0300)
borger

diff --git a/borger b/borger
index 05d8d2bb5219566f2484b05204f27cf061dfb6c8..531e32aa44853b14ef5628236e6cc4c4eafb6ba8 100755 (executable)
--- a/borger
+++ b/borger
@@ -254,7 +254,8 @@ function borger_single {
   # Convert the pass command to passphrase otherwise
   # the user would be interrupted by a passphrase prompt
   # at every iteration
-  if [ ! -z "$BORG_PASSCOMMAND" ]; then
+  if [ ! -z "$BORG_PASSCOMMAND" ] && [ -z "$BORG_PASSPHRASE" ]; then
+    info "Asking passphrase for borg key used at $DESTINATION"
     export BORG_PASSPHRASE="`$BORG_PASSCOMMAND`"
     export BORG_PASSCOMMAND=""
   fi
@@ -281,9 +282,13 @@ function borger_multiple {
   for config in `ls $CONFIG`; do
     # Include BORG_PASSPHRASE config for each destination in an array
     if grep -q "BORG_PASSCOMMAND" $CONFIG/$config; then
-      COMMAND="`grep BORG_PASSCOMMAND $CONFIG/$config | cut -d = -f 2 | sed -e "s/^'//" -e "s/'$//" -e 's/^"//' -e 's/"$//'`"
-      #BORG_PASSPHRASES[$config]="BORG_PASSPHRASE=`$COMMAND`"
-      BORG_PASSPHRASES[$config]="`$COMMAND`"
+      # Ask the passphrase only once
+      if [ -z "${BORG_PASSPHRASES[$config]}" ]; then
+        info "Asking passphrase for borg key used at $config"
+        COMMAND="`grep BORG_PASSCOMMAND $CONFIG/$config | cut -d = -f 2 | sed -e "s/^'//" -e "s/'$//" -e 's/^"//' -e 's/"$//'`"
+        #BORG_PASSPHRASES[$config]="BORG_PASSPHRASE=`$COMMAND`"
+        BORG_PASSPHRASES[$config]="`$COMMAND`"
+      fi
     else
       BORG_PASSPHRASES[$config]=""
     fi