docs
[mirrors/Programs.git] / bash / nano-crypt / ccrypt-nano
CommitLineData
21c4e167
H
1#!/bin/sh
2#Binaries:
3EDITOR='/usr/bin/nano';
4ccrypt='/usr/bin/ccrypt'
5LAZYTEE='./tee-lazy'
6
7#code##############################################
8#if [[ -z "$EDITOR" ]]; then EDITOR='/usr/bin/nano'; fi;
9CRYPTFILE="$1"
10TMPPIPE="/tmp/ccrypt-nano-pipe-$UID-$$"
11
12if [[ -z "$CRYPTFILE" ]]; then
13 echo Usage: "$0" file.txt.cpt;
14 echo "
15This script allows you to create/edit ccenrypted textfiles using nano.
16There is no copy of unencrypted file on filesystem everything is in pipes.
17You can use this as secure way to keep your passwords or phone numbers (etc...).
18Check man ccrypt & man nano for more informations."
19 exit;
20fi;
21
22if [[ -a "$CRYPTFILE" ]]; then
23 false;
24 while [[ $? != 0 ]]; do
25 echo -ne '\nEnter password: '
26 stty -echo; read KEY; stty echo;
27 $ccrypt -c "$CRYPTFILE" -K "$KEY" > /dev/null;
28 done;
29else
30 KEY=a; KEYY=b;
31 while [[ "$KEY" != "$KEYY" ]]; do
32 echo -ne '\n\nEnter password: '
33 stty -echo; read KEY; stty echo;
34 echo -ne '\nEnter password (again): '
35 stty -echo; read KEYY; stty echo;
36 done;
37fi;
38
39handle_crypt_pipe() {
40 rm -rf "$2";
41 mkfifo "$2";
42 chmod a-rwx "$2";
43 chmod u+rw "$2";
44
45 $ccrypt -d -c -K "$3" "$1" > "$2";
46
47 while [[ -a "$2" ]]; do
48 cat "$2" | $ccrypt -e -K "$3" | $LAZYTEE "$1";
49 done;
50}
51
52handle_crypt_pipe "$CRYPTFILE" "$TMPPIPE" "$KEY" &
53$EDITOR "$TMPPIPE"
54rm -rf "$TMPPIPE"
55kill -s SIGINT $(jobs -p); > /dev/null 2>&1
56kill -s SIGKILL $(jobs -p); > /dev/null 2>&1
57
This page took 0.204411 seconds and 4 git commands to generate.