Advertisement
Guest User

Untitled

a guest
Dec 27th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.72 KB | None | 0 0
  1. #!/bin/bash
  2. dir=~/
  3. dir="$dir/Documents/Journal"
  4.  
  5. #Cleanup function run on exit and disowned so as not to tie up the shell with Shred for five minutes
  6. cleanup() {
  7.     #Check if encrypted file is present before proceeding to avoid errors
  8.     if [ -f "$dir"/journal.gpg ]
  9.     then
  10.         shred -u "$dir"/journal/titled/*
  11.         rmdir "$dir"/journal/titled
  12.         shred -u "$dir"/journal/dated/*
  13.         rmdir "$dir"/journal/dated
  14.         rmdir "$dir"/journal
  15.     fi
  16. }
  17.  
  18. #Check that 1) encrypted file is present and 2) unencrypted directory is not
  19. if [ ! -f "$dir"/journal.gpg ] || [ -d "$dir"/journal ]
  20. then
  21.     echo Error. Clean up the directory before proceeding
  22.     exit
  23. fi
  24.  
  25. gpg --decrypt --no-symkey-cache "$dir"/journal.gpg | tar xz -C "$dir"
  26.  
  27. if [ ! -d "$dir"/journal ]
  28. then
  29.     echo Wrong password
  30.     exit
  31. fi
  32.  
  33. #If an argument was given, use it for a file title in journal/titled. Otherwise, filename is date in journal/dated
  34. if [ "$1" != "" ]
  35. then
  36.     FILE="$dir/journal/titled/$1"
  37. else
  38.     FILE="$dir/journal/dated/$(date +'%a-%b-%d-%Y')"
  39. fi
  40. clear
  41. date
  42. echo
  43. #If file does not exist, write date to file. Otherwise, skip this and append
  44. if [ ! -f "$FILE" ]
  45. then
  46.     echo $(date +'%a-%b-%d-%Y') > "$FILE"
  47. fi
  48.  
  49. echo >> "$FILE"
  50. echo $(date +'%H:%M') >> "$FILE"
  51. echo >> "$FILE"
  52.  
  53. #Append stdout to file. CTRL+D when done
  54. cat >> "$FILE"
  55. clear
  56.  
  57. echo >> "$FILE"
  58. echo >> "$FILE"
  59.  
  60. cd "$dir"
  61.  
  62. #Confirm journal directory is present before overwriting encrypted file
  63. if [ -d "$dir"/journal ]
  64. then
  65.     rm journal.gpg
  66.     tar -czf - journal | gpg --output "$dir"/journal.gpg --symmetric --no-symkey-cache
  67. fi
  68.  
  69. cd -
  70. clear
  71. cp "$dir"/journal.gpg "$dir"/.backup.gpg
  72. #Create a backup of the latest journal.gpg, start cleanup script and disown
  73. cleanup &
  74. disown cleanup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement