/encryptCalcurse.sh
Shell | 113 lines | 59 code | 20 blank | 34 comment | 4 complexity | 793ae57405c6589f1936e105d116fa03 MD5 | raw file
1#!/bin/bash 2 3# ENCRYPTCALCURSE.SH 4 5# Written by Oz Nahum <nahumoz__at_you_know_where_no_spam_is_gmail.com> 6# This script is distributed under the terms of the GNU Public License 7# Version 3 or later. 8# You can obtaion copies of this license at: 9# http://www.gnu.org/licenses/gpl.html 10 11# A script to decrypt the calcurse_date dir, open it in 12# /home/<user>/calcurse_data 13# then launch calcurse pointing to it, 14# and upon closing calcurse, encrypt the data, move it to usb stick, 15# and delete all data from /home/<user>/calcurse_data 16 17### Begin of Script 18 19INPUT_FILE="calcurse_d.tar.enc" 20OUTPUT_FILE="calcurse_d.tar.enc" 21 22#name of directory to encrypt (e.g. ~.calcurse) 23CALCURSE_DATA_DIR="~/.calcurse/" 24 25# usage: 26# $ bash encryptCalcurse.sh 27# $ bash encryptCalcurse.sh [ecnrypted_data_in.enc] [encrypted_data_out.enc] 28 29#TODO: test that modified script ! 30### Begin of Script 31#make files readable only by owner 32umask 077 33 34function Config { 35 USB=`pwd` 36 tar -cf calcurse_data.tar $CALCURSE_DATA_DIR 37 openssl aes-256-cbc -salt -in calcurse_data.tar -out calcurse_d.tar.enc 38 clc=`which calcurse` 39 cp -v $clc $USB 40 41} 42 43function cleanUp { 44 find /dev/shm/calcurse_data -type f | xargs shred -fuz; 45 if [ -f /dev/shm/cdt.tar ]; then 46 shred -fuz /dev/shm/cdt.tar 47 fi 48 if [ -f /dev/shm/calcurse_data_tmp.tar ]; then 49 shred -fuz /dev/shm/calcurse_data_tmp.tar 50 fi 51 rmdir /dev/shm/calcurse_data/notes 52 rmdir /dev/shm/calcurse_data 53} 54 55function readData { 56#first decrypt the data 57openssl enc -d -aes-256-cbc -salt -in $INPUT_FILE -out /dev/shm/calcurse_data_tmp.tar 58echo "extracting data" 59#silently extract data, no need for verbose output (v flag) 60tar -C /dev/shm -xf /dev/shm/calcurse_data_tmp.tar 61#note unpacking removes the original tar 62} 63 64function encryptData { 65openssl aes-256-cbc -salt -in /dev/shm/cdt.tar -out calcurse_d.tar.enc 66} 67 68 69case "$1" in 70 "") 71 echo "expecting parameter input... see header of script for usage" 72 ;; 73 "--config") 74 CALCURSE_DATA_DIR=$2 75 Config 76 ;; 77 78 "--read") 79 trap "cleanUp" SIGHUP SIGINT SIGQUIT SIGKILL SIGABRT SIGTERM EXIT 80 # when calcurse is done tar the direcotry 81 readData 82 calcurse -D /dev/shm/calcurse_data 83 tar -cf /dev/shm/cdt.tar -C /dev/shm/ calcurse_data/ 84 85 # then encrypt 86 # if encryption failed $? == 1 so repeat it again ... 87 encryptData 88 es=$? 89 while [ "$es" = "1" ]; do 90 echo "encrypting data" 91 encryptData 92 es=$? 93 done 94 ;; 95 "--decrypt") 96 readData 97 ;; 98 "--encrypt") 99 tar -cvf /dev/shm/cdt.tar -C /dev/shm/ calcurse_data/ 100 encryptData 101 ;; 102 103 #if encryption succeeded clean up by calling the function 104 #cleanUp 105 106esac 107#note about the salt option note found in openssl man page[1],[2] 108#note about lack of compresion with ssl [3] 109 110#sources: 111#[1]http://ubuntuforums.org/showpost.php?p=8287351&postcount=9 112#[2]http://linux.die.net/man/1/enc 113#[3]http://serverfault.com/questions/17855/can-i-compr:ess-an-encrypted-file