diff options
-rwxr-xr-x | gpgsecure.sh | 21 |
1 files 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 ${@} + |