Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This is a script to work with an encrypted gnucash file. It asks for the
- # password, decrypts the file, runs gnucash, and encrypts it back. Logs and
- # backups are shredded at the end.
- # Author: pluton <plutonpluton@mail.ru>
- # Version: 1.0 (Sat Jan 29 2011)
- # License: GNU GPL 3
- CP=/bin/cp
- KDIALOG=/usr/bin/kdialog
- OPENSSL=/usr/bin/openssl
- GNUCASH=/usr/bin/gnucash
- SHRED=/bin/shred
- BASENAME=/usr/bin/basename
- CHMOD=/bin/chmod
- FILE=~/main
- FILETMP="${FILE}.tmp"
- TIMEOUT=2 # seconds
- TITLE=$( $BASENAME $0 )
- notify() {
- [ -n "$1" ] && text="$1" || text="?"
- $KDIALOG --passivepopup "$text" --title "$TITLE" $TIMEOUT
- }
- [ -e "$FILE" ] || { notify "File '$FILE' was not found"; exit 1; }
- pass=$( $KDIALOG --password "Enter the password /GC/" )
- [ "$pass" == "" ] && { notify "The password is empty"; exit 2; }
- if ! $OPENSSL enc -d -aes-256-cbc -in "$FILE" -out "$FILETMP" -pass stdin <<EOF
- ${pass}
- EOF
- then
- notify "The password seems to be wrong"
- exit 3
- fi
- $CHMOD go= "$FILETMP"
- $CP -f "$FILE" "${FILE}.bkp"
- $GNUCASH "$FILETMP"
- if ! $OPENSSL enc -e -aes-256-cbc -in "$FILETMP" -out "$FILE" -pass stdin <<EOF
- ${pass}
- EOF
- then
- notify "An error occured while encoding (code #$?)"
- exit 4
- fi
- unset pass
- $SHRED -zun 2 "${FILETMP}"*
- notify "Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement