1

I have a directory, lets call it foo, and inside of foo there are N directories, bar1..barN. Inside of each directory there can be 1..N files all files are gpg encrypted. What I want is to decrypt all of the files in each folder.

#!/bin/bash

for d in *; do
   cd $d
   pwd
   mkdir gpg
   for fn in *.gpg; do
      n=${fn##*/}
      f=${n%.gpg}
      gpg --homedir ~/Documents/gpg/ -u MY_PVT_KEY_NAME -do $f.txt $fn
      mv $fn gpg
   done
   cd ..
done

For some reason the only directory that is processed properly is the first one the rest of them fail to decrypt, the files are moved into the gpg directory, but files are not decrypted.

Thanks for any help.

1 Answers1

0

You may use a bash function and find to make this job easy :

gpgdecrypt()
{
tofile="${@%.gpg}.txt"
gpg --homedir ~/Documents/gpg/ -u MY_PVT_KEY_NAME -do "${tofile}" "${@}"
}

# Export the function 
export -f gpgdecrypt
# Then  fetch the files using find and feed the files to the gpgdecrypt fn.
find /base/path -type f -name "*.gpg" -exec bash -c 'gpgdecrypt $1' _ {} \;
sjsam
  • 21,411
  • 5
  • 55
  • 102