Skip to content

Commit

Permalink
feat: improve failure when encryption fails
Browse files Browse the repository at this point in the history
also some typo fixes
  • Loading branch information
sanjayankur31 committed May 3, 2022
1 parent 93249a2 commit 2e0f695
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions calliope.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ encrypt ()
if [ -f "$1" ]
then
echo "Encrypting $1 with $encryptionId"
$GPG_COMMAND --encrypt --sign -r "$encryptionId" "$1" && rm "$1" -f
$GPG_COMMAND --encrypt --sign -r "$encryptionId" "$1" && rm "$1" -f || exit -1
else
echo "File $1 not found"
exit 1
Expand All @@ -234,10 +234,7 @@ encrypt_all ()
directory="$(dirname $f)"
file="$(basename $f)"
pushd $directory
if ! $GPG_COMMAND --encrypt --sign -r "$encryptionId" "$file"
then
exit -1
fi
encrypt "$file" || exit -1
popd
done
fi
Expand Down Expand Up @@ -445,14 +442,14 @@ search_diary ()
fi
}
remove_unencrpyted ()
remove_unencrypted ()
{
# if encryption is enabled, delete all unencrypted pdf files before committing
if [ -z ${encryptionId} ]
then
echo "Encryption is not enabled"
else
echo "Deleting all unencrpyted files"
echo "Deleting all unencrypted files"
find pdfs/ diary/ -not -name "*.gpg" -and -type f -and -not -type l -delete
fi
}
Expand All @@ -464,8 +461,8 @@ commit_changes ()
echo "git is not installed."
exit -1
else
encrypt_all && remove_unencrpyted
echo "Committing changes to repository with commit message ${commit_message:-$default_commit_message}"
encrypt_all && remove_unencrypted || exit -1
echo "Committing changes to repository with commit message \"${commit_message:-$default_commit_message}\""
git add .
if ! git commit -m "${commit_message:-$default_commit_message}"
then
Expand Down Expand Up @@ -629,7 +626,7 @@ do
exit 0
;;
x)
remove_unencrpyted
remove_unencrypted
exit 0
;;
?)
Expand Down

0 comments on commit 2e0f695

Please sign in to comment.