/encryptCalcurse.sh
https://bitbucket.org/oz123/encryptcalcurse · Shell · 113 lines · 59 code · 20 blank · 34 comment · 4 complexity · 793ae57405c6589f1936e105d116fa03 MD5 · raw file
- #!/bin/bash
- # ENCRYPTCALCURSE.SH
- # Written by Oz Nahum <nahumoz__at_you_know_where_no_spam_is_gmail.com>
- # This script is distributed under the terms of the GNU Public License
- # Version 3 or later.
- # You can obtaion copies of this license at:
- # http://www.gnu.org/licenses/gpl.html
- # A script to decrypt the calcurse_date dir, open it in
- # /home/<user>/calcurse_data
- # then launch calcurse pointing to it,
- # and upon closing calcurse, encrypt the data, move it to usb stick,
- # and delete all data from /home/<user>/calcurse_data
- ### Begin of Script
- INPUT_FILE="calcurse_d.tar.enc"
- OUTPUT_FILE="calcurse_d.tar.enc"
- #name of directory to encrypt (e.g. ~.calcurse)
- CALCURSE_DATA_DIR="~/.calcurse/"
- # usage:
- # $ bash encryptCalcurse.sh
- # $ bash encryptCalcurse.sh [ecnrypted_data_in.enc] [encrypted_data_out.enc]
- #TODO: test that modified script !
- ### Begin of Script
- #make files readable only by owner
- umask 077
- function Config {
- USB=`pwd`
- tar -cf calcurse_data.tar $CALCURSE_DATA_DIR
- openssl aes-256-cbc -salt -in calcurse_data.tar -out calcurse_d.tar.enc
- clc=`which calcurse`
- cp -v $clc $USB
-
- }
- function cleanUp {
- find /dev/shm/calcurse_data -type f | xargs shred -fuz;
- if [ -f /dev/shm/cdt.tar ]; then
- shred -fuz /dev/shm/cdt.tar
- fi
- if [ -f /dev/shm/calcurse_data_tmp.tar ]; then
- shred -fuz /dev/shm/calcurse_data_tmp.tar
- fi
- rmdir /dev/shm/calcurse_data/notes
- rmdir /dev/shm/calcurse_data
- }
- function readData {
- #first decrypt the data
- openssl enc -d -aes-256-cbc -salt -in $INPUT_FILE -out /dev/shm/calcurse_data_tmp.tar
- echo "extracting data"
- #silently extract data, no need for verbose output (v flag)
- tar -C /dev/shm -xf /dev/shm/calcurse_data_tmp.tar
- #note unpacking removes the original tar
- }
- function encryptData {
- openssl aes-256-cbc -salt -in /dev/shm/cdt.tar -out calcurse_d.tar.enc
- }
- case "$1" in
- "")
- echo "expecting parameter input... see header of script for usage"
- ;;
- "--config")
- CALCURSE_DATA_DIR=$2
- Config
- ;;
- "--read")
- trap "cleanUp" SIGHUP SIGINT SIGQUIT SIGKILL SIGABRT SIGTERM EXIT
- # when calcurse is done tar the direcotry
- readData
- calcurse -D /dev/shm/calcurse_data
- tar -cf /dev/shm/cdt.tar -C /dev/shm/ calcurse_data/
-
- # then encrypt
- # if encryption failed $? == 1 so repeat it again ...
- encryptData
- es=$?
- while [ "$es" = "1" ]; do
- echo "encrypting data"
- encryptData
- es=$?
- done
- ;;
- "--decrypt")
- readData
- ;;
- "--encrypt")
- tar -cvf /dev/shm/cdt.tar -C /dev/shm/ calcurse_data/
- encryptData
- ;;
- #if encryption succeeded clean up by calling the function
- #cleanUp
-
- esac
- #note about the salt option note found in openssl man page[1],[2]
- #note about lack of compresion with ssl [3]
- #sources:
- #[1]http://ubuntuforums.org/showpost.php?p=8287351&postcount=9
- #[2]http://linux.die.net/man/1/enc
- #[3]http://serverfault.com/questions/17855/can-i-compr:ess-an-encrypted-file