Advertisement
Guest User

GnuCash files encryption script

a guest
Jan 31st, 2011
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. # This is a script to work with an encrypted gnucash file. It asks for the
  3. # password, decrypts the file, runs gnucash, and encrypts it back. Logs and
  4. # backups are shredded at the end.
  5. # Author: pluton <plutonpluton@mail.ru>
  6. # Version: 1.0 (Sat Jan 29 2011)
  7. # License: GNU GPL 3
  8.  
  9. CP=/bin/cp
  10. KDIALOG=/usr/bin/kdialog
  11. OPENSSL=/usr/bin/openssl
  12. GNUCASH=/usr/bin/gnucash
  13. SHRED=/bin/shred
  14. BASENAME=/usr/bin/basename
  15. CHMOD=/bin/chmod
  16.  
  17. FILE=~/main
  18. FILETMP="${FILE}.tmp"
  19. TIMEOUT=2   # seconds
  20. TITLE=$( $BASENAME $0 )
  21.  
  22. notify() {
  23.     [ -n "$1" ] && text="$1" || text="?"
  24.     $KDIALOG --passivepopup "$text" --title "$TITLE" $TIMEOUT
  25. }
  26.  
  27. [ -e "$FILE" ] || { notify "File '$FILE' was not found"; exit 1; }
  28.  
  29. pass=$( $KDIALOG --password "Enter the password /GC/" )
  30. [ "$pass" == "" ] && { notify "The password is empty"; exit 2; }
  31.  
  32. if ! $OPENSSL enc -d -aes-256-cbc -in "$FILE" -out "$FILETMP" -pass stdin <<EOF
  33. ${pass}
  34. EOF
  35. then
  36.     notify "The password seems to be wrong"
  37.     exit 3
  38. fi
  39. $CHMOD go= "$FILETMP"
  40. $CP -f "$FILE" "${FILE}.bkp"
  41. $GNUCASH "$FILETMP"
  42. if ! $OPENSSL enc -e -aes-256-cbc -in "$FILETMP" -out "$FILE" -pass stdin <<EOF
  43. ${pass}
  44. EOF
  45. then
  46.     notify "An error occured while encoding (code #$?)"
  47.     exit 4
  48. fi
  49. unset pass
  50. $SHRED -zun 2 "${FILETMP}"*
  51. notify "Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement