From 4ece4f35be91fa5f7dac644e9038070239302ba9 Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Wed, 4 Apr 2018 19:49:14 -0600 Subject: Implemented scheduled writeback Now we write back to encrypted storage on a loop every 15 seconds. We also catch SIGINT (Ctrl + c) and execute a clean shutdown process. This will reduce the likelihood of data loss. --- gpgsecure.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/gpgsecure.sh b/gpgsecure.sh index 0544671..b9796c2 100755 --- a/gpgsecure.sh +++ b/gpgsecure.sh @@ -19,6 +19,7 @@ export KEY=${KEY:-} # GPG key to encrypt the container with export DIR # Directory path to present the gpg archive to export TMP # Temp directory in memory to decrypt to +trap shutdown SIGINT shutdown() { printf '\nRe-encrypting for shutdown\n' @@ -30,6 +31,21 @@ shutdown() { rm "${DIR}" # Delete the temp dir from memory rm -rf "${TMP}" + sync + exit +} + +writeback() { + while [ 0 ]; do + printf '%s Syncing back to encrypted storage\n' "$(date '+%F %T')" + tar -C "${TMP}" -c . | gpg -e --recipient "${KEY}" > "${DIR}.tar.gpg" + if [ $? -gt 0 ]; then + printf 'WARNING: Something went wrong syncing back to encrypted storage\n' + printf 'Your data is likely in danger.\n' + printf 'If you see this message more than once, take a manual backup\n' + fi + sleep 15 + done } main() { @@ -65,11 +81,10 @@ main() { gpg -d ${DIR}.tar.gpg | tar -C "${TMP}" -x fi - printf 'Do some secure work and press enter to re-encrypt when done\n' - read - + writeback shutdown return $? } main ${@} + -- cgit v1.2.3