-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt
More file actions
executable file
·59 lines (50 loc) · 1.54 KB
/
decrypt
File metadata and controls
executable file
·59 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#TODO: add --in-place option to replace encrypted file with non-encrypted
#TODO: when decrypting file, also create or append to .gitignore file to avoid accidental tracking
yel="\e[33m"
red="\e[31m"
bold="\e[1m"
none="\e[0m"
key="O──┬┬"
main(){
print_help_if_no_args "$@"
for file in $@; do
is_exist $file
_decrypt $file
done
}
print_help_if_no_args() {
[[ $# -eq 0 ]] && echo -e "$yel""To decrypt files:$bold decrypt [options] <file>...$none"
}
# verify that file exists, return 1 if not exists, 0 if it does
# FIXME: if file not exists, should continue instead of dead stop
is_exist() {
if [[ ! -e "$1" ]]; then
>&2 echo -e "$yel""file $1 does not exist, following files ignored (BUG:FIXME)$none"
# return 1 # experimental
exit 1
fi
return 0
}
# sending to tmp outside of repo is safer to avoid accidental tracking. To decrypt inplace, must
# add file to .gitignore
_decrypt() {
# send output to tmpfile
tmp_file=$(mktemp -t decrypted.XXXX)
gpg --decrypt --quiet "$file" > $tmp_file
if [[ $? -eq 0 ]]; then
>&2 echo -e "$bold$file $none $yel$key $none $bold$tmp_file $none"
else
>&2 echo -e "$red$bold""fail""$none"
fi
}
_decrypt_in_place() {
# decrypt and output to file minus '.gpg' extension
# then add same file to .gitignore
encrypted_file="$1"
decrypted_file="$(remove_gpg_extension \"$encrypted_file\")"
gpg --decrypt --quiet "$encrypted_file" > "$decrypted_file"
add_to_gitignore "$decrypted_file"
echo "{\"error\":\"not implemented\",\"args\":\"$@\"}"
}
main "$@"