Home > Back-end >  Add a progress bar when deciphering files gpg
Add a progress bar when deciphering files gpg

Time:10-28

For the ease of use for ciphering and deciphering files and folder, and also to get some clues about when it's going to finish, I would like to set up some king of progress bar with gpg. I'm using pv to do so, which works well for ciphering as I do not need a password. However, I don't know how to do it for deciphering, as it may ask for the password of my private key. Here is what I tried:

#!/bin/bash

if [ "$#" -ne 1 ] || ! [ -f "$1" ]; then
  echo "Usage: $0 CIPHERED_FOLDER" >&2
  exit 1
fi

echo "Deciphering $1"
pv $1 | gpg -d | tar -xz

It works well if the passphrase is already cached, but fails if it's not. So I used a workaround, replacing the last line with gpg -d $1 | pv -W | tar -xz However, as I can't know the exact size of the deciphered file, I can't have a percentage.

Is there a way to get this working? I tried looking at ways to manually ask in the script for the passphrase before trying to decipher to get it in the cache, but I couldn't find how to do so.

Thanks

Edit: I'm ciphering the files only for myself for security storage, and gpg doesn't ask me for a recipient anymore because I've set up default-recipient-self

CodePudding user response:

I managed to find a workaround. I first sign a short text and throw the output directly in /dev/null. This way, it makes sure that the passphrase is cached before the main deciphering. It looks like this:

gpg -o /dev/null --sign <(echo "1234")

echo "Deciphering $1"
pv $1 | gpg -d -q | tar -xz
  • Related