Commit | Line | Data |
---|---|---|
21c4e167 H |
1 | #!/bin/sh |
2 | #Binaries: | |
3 | EDITOR='/usr/bin/nano'; | |
4 | ccrypt='/usr/bin/ccrypt' | |
5 | LAZYTEE='./tee-lazy' | |
6 | ||
7 | #code############################################## | |
8 | #if [[ -z "$EDITOR" ]]; then EDITOR='/usr/bin/nano'; fi; | |
9 | CRYPTFILE="$1" | |
10 | TMPPIPE="/tmp/ccrypt-nano-pipe-$UID-$$" | |
11 | ||
12 | if [[ -z "$CRYPTFILE" ]]; then | |
13 | echo Usage: "$0" file.txt.cpt; | |
14 | echo " | |
15 | This script allows you to create/edit ccenrypted textfiles using nano. | |
16 | There is no copy of unencrypted file on filesystem everything is in pipes. | |
17 | You can use this as secure way to keep your passwords or phone numbers (etc...). | |
18 | Check man ccrypt & man nano for more informations." | |
19 | exit; | |
20 | fi; | |
21 | ||
22 | if [[ -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; | |
29 | else | |
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; | |
37 | fi; | |
38 | ||
39 | handle_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 | ||
52 | handle_crypt_pipe "$CRYPTFILE" "$TMPPIPE" "$KEY" & | |
53 | $EDITOR "$TMPPIPE" | |
54 | rm -rf "$TMPPIPE" | |
55 | kill -s SIGINT $(jobs -p); > /dev/null 2>&1 | |
56 | kill -s SIGKILL $(jobs -p); > /dev/null 2>&1 | |
57 |