#!/bin/bash cat <$TEMPDIR/data.txt 2>$TEMPDIR/log.txt if [ "$?" != "0" ] ; then rm -rf $TEMPDIR echo echo "Aborting." exit 1 fi if [ "$ENCRYPT_FLAGS" = "-c" ]; then USERID_HINT=$(grep 'USERID_HINT' $TEMPDIR/log.txt |cut -d\ -f 3) if [ "$USERID_HINT" != "" ]; then ENCRYPT_FLAGS="-e -r $USERID_HINT" fi fi cp -a $TEMPDIR/data.txt $TEMPDIR/orig else touch $TEMPDIR/orig $TEMPDIR/data.txt fi # Edit the unencrypted data... # $VISUAL $TEMPDIR/data.txt # Clear screen, to avoid leaving sensitive data in scrollback buffers. # clear # If the file has changed, re-encrypt and overwrite the original. # if ! diff $TEMPDIR/data.txt $TEMPDIR/orig >/dev/null; then echo -n "File changed, encrypt new data and save? [YES/no] " read YESNO case $YESNO in n*|N*) echo "Discarding changes." ;; *) while ! gpg $ENCRYPT_FLAGS -a <$TEMPDIR/data.txt >$TEMPDIR/data.gpg; do clear echo "Uh, please try again..." echo done cat <>$TEMPDIR/data.gpg ## Edited by gpg-edit: http://bre.klaki.net/programs/gpg-edit.txt ## tac cat $TEMPDIR/data.gpg > $FILE \ && echo "OK, wrote new data to $FILE" \ || echo 'Save failed, discarding changes!' esac else echo "Nothing was changed." fi # Cleanup: overwrite temporary files with random(ish) data and then delete the # entire temporary directory. We use /dev/urandom rather than # /dev/random so we won't block if the machine runs out of entropy. # # Note that the wiping may be incomplete if the file shrinks by more than 12k # during editing or backup/swap files are created which are much larger than # the unencrypted data. Oh well... the number 12 is arbitrary. # echo -n "Wiping and erasing temporary files " BLOCKS=$(/bin/ls -1s $TEMPDIR/data.txt |awk '{print 12+$1;}') for a in $(seq 1 25); do echo -n . find $TEMPDIR -type f -exec \ dd if=/dev/urandom of=\{\} \ count=$BLOCKS bs=1024 >/dev/null 2>&1 \; # This sync is (probably) necessary, otherwise kernel buffering may make # the whole wiping exercise futile. # sync done rm -rf $TEMPDIR echo " done."