Skip to content

Commit

Permalink
feat: do not encrypt a text file if it is older than its encrypted co…
Browse files Browse the repository at this point in the history
…unterpart

This indicates that a new version of the text file was encrypted, so
encrypting the older one may cause loss of new text.
  • Loading branch information
sanjayankur31 committed May 6, 2022
1 parent 3d4a95c commit 92a0ec9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions calliope.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,21 @@ encrypt ()
then
if [ -f "$1" ]
then
echo "Encrypting $1 with $encryptionId"
$GPG_COMMAND --batch --yes --encrypt --sign -r "$encryptionId" "$1" && rm "$1" -f || exit -1
if [ "${1: -4}" == ".gpg" ]
then
echo "File $1 is already encrypted. Not re-encrypting."
exit 1
else
echo "Encrypting $1 with $encryptionId"
if [ "$1" -ot "${1}.gpg" ]
then
echo "WARNING: Encrypted file newer than text file found."
echo "WARNING: Not encrypting, since this may overwrite a newer encrypted file."
exit 1
else
$GPG_COMMAND --batch --yes --encrypt --sign -r "$encryptionId" "$1" && rm "$1" -f || exit -1
fi
fi
else
echo "File $1 not found"
exit 1
Expand Down

0 comments on commit 92a0ec9

Please sign in to comment.