This week was a learning experience.
#!/usr/bin/env bash
source "/home/datatransfer/company/master.sh"
encryptedFolderPath="/home/datatransfer/company/in /"
decryptedFolderPath="/home/datatransfer/company/out"
archiveFolderPath="/home/datatransfer/company/archive"
for i in $(ls $encryptedFolderPath.pgp)
do
gpg --batch --passphrase $PASS --list-only --list-packets --yes $i | grep -q "encrypted"
if [ $? != 0 ]; then
echo "$i is not a pgp file"
continue
fi
v=${i%.}
encryptedFile="$v"
fileName=${encryptedFile##/}
timeNow=$(date +%Y%m%d%H%M)
extension=${fileName##.}
newFileName=${fileName%.*}
fileWithTimestamp="$newFileName""_""$timeNow.$extension"
gpg --batch –passphrase $PASS --yes --decrypt $i > $decryptedFolderPath/$fileWithTimestamp
ls -lr $decryptedFolderPath/$fileWithTimestamp
if [ $? != 0 ]; then
echo "$fileWithTimestamp is not a readable file"
continue
fi
mv $i $archiveFolderPath
done
Thanks to @scottalanmiller @stacksofplates and my friend Erik