Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- dir=~/
- dir="$dir/Documents/Journal"
- #Cleanup function run on exit and disowned so as not to tie up the shell with Shred for five minutes
- cleanup() {
- #Check if encrypted file is present before proceeding to avoid errors
- if [ -f "$dir"/journal.gpg ]
- then
- shred -u "$dir"/journal/titled/*
- rmdir "$dir"/journal/titled
- shred -u "$dir"/journal/dated/*
- rmdir "$dir"/journal/dated
- rmdir "$dir"/journal
- fi
- }
- #Check that 1) encrypted file is present and 2) unencrypted directory is not
- if [ ! -f "$dir"/journal.gpg ] || [ -d "$dir"/journal ]
- then
- echo Error. Clean up the directory before proceeding
- exit
- fi
- gpg --decrypt --no-symkey-cache "$dir"/journal.gpg | tar xz -C "$dir"
- if [ ! -d "$dir"/journal ]
- then
- echo Wrong password
- exit
- fi
- #If an argument was given, use it for a file title in journal/titled. Otherwise, filename is date in journal/dated
- if [ "$1" != "" ]
- then
- FILE="$dir/journal/titled/$1"
- else
- FILE="$dir/journal/dated/$(date +'%a-%b-%d-%Y')"
- fi
- clear
- date
- echo
- #If file does not exist, write date to file. Otherwise, skip this and append
- if [ ! -f "$FILE" ]
- then
- echo $(date +'%a-%b-%d-%Y') > "$FILE"
- fi
- echo >> "$FILE"
- echo $(date +'%H:%M') >> "$FILE"
- echo >> "$FILE"
- #Append stdout to file. CTRL+D when done
- cat >> "$FILE"
- clear
- echo >> "$FILE"
- echo >> "$FILE"
- cd "$dir"
- #Confirm journal directory is present before overwriting encrypted file
- if [ -d "$dir"/journal ]
- then
- rm journal.gpg
- tar -czf - journal | gpg --output "$dir"/journal.gpg --symmetric --no-symkey-cache
- fi
- cd -
- clear
- cp "$dir"/journal.gpg "$dir"/.backup.gpg
- #Create a backup of the latest journal.gpg, start cleanup script and disown
- cleanup &
- disown cleanup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement