From 259b05ff33a3ab099e11a1ff3b90a9ad739d1ff5 Mon Sep 17 00:00:00 2001 From: deajan Date: Thu, 29 Dec 2016 00:44:33 +0100 Subject: [PATCH] Improved GPG v >= 2.1 batch support --- dev/n_obackup.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/dev/n_obackup.sh b/dev/n_obackup.sh index 7d2da43..1742582 100755 --- a/dev/n_obackup.sh +++ b/dev/n_obackup.sh @@ -10,7 +10,7 @@ PROGRAM="obackup" AUTHOR="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr" PROGRAM_VERSION=2.1-dev -PROGRAM_BUILD=2016122803 +PROGRAM_BUILD=2016122804 IS_STABLE=no include #### OFUNCTIONS FULL SUBSET #### @@ -1152,6 +1152,9 @@ function DecryptFiles { local secret local successCounter=0 local errorCounter=0 + local cryptToolVersion + local cryptToolMajorVersion + local cryptToolSubVersion local cryptFileExtension="$CRYPT_FILE_EXTENSION" if [ ! -w "$filePath" ]; then @@ -1159,6 +1162,16 @@ function DecryptFiles { exit 1 fi + # Detect if GnuPG >= 2.1 that does not allow automatic pin entry anymore + cryptToolVersion=$($CRYPT_TOOL --version | head -1 | awk '{print $3}') + cryptToolMajorVersion={$cryptToolVersion%%.*} + cryptToolSubVersion=${cryptToolVersion#*.} + cryptToolSubVersion=${cryptToolSubVersion%.*} + + if [ $cryptToolMajorVersion -eq 2 ] && [ $cryptToolsubVersion -ge 1 ]; then + additionalParameters="--pinentry-mode loopback" + fi + if [ -f "$passphraseFile" ]; then secret="--passphrase-file $passphraseFile" elif [ "$passphrase" != "" ]; then @@ -1176,7 +1189,7 @@ function DecryptFiles { while IFS= read -r -d $'\0' encryptedFile; do Logger "Decrypting [$encryptedFile]." "VERBOSE" - $CRYPT_TOOL $options --out "${encryptedFile%%$cryptFileExtension}" $secret --decrypt "$encryptedFile" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2>&1 + $CRYPT_TOOL $options --out "${encryptedFile%%$cryptFileExtension}" $additionalParameters $secret --decrypt "$encryptedFile" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2>&1 if [ $? != 0 ]; then Logger "Cannot decrypt [$encryptedFile]." "ERROR" Logger "Command output\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP)" "DEBUG"