-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.sh
More file actions
executable file
·93 lines (93 loc) · 2.84 KB
/
decrypt.sh
File metadata and controls
executable file
·93 lines (93 loc) · 2.84 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
usage="$(basename "$0") [-h] [-d|-n] [-a] [-s] -- decrypts files stored on dropbox (kills dropbox process)
-h show this help text
-d kills dropbox if it is running (default)
-n does not kill dropbox (not default)
-a executes decrypt on all files of this directory (not default)
-s execute everything in silent mode"
#--------------------------------
verbose_on="1" #means true
_print()
{
[ "${verbose_on}" -ne "0" ] && $@
}
#--------------------------------
encrypt_all_files=false
do_not_kill_dropbox=false
while getopts 'sahdn' option; do
case "$option" in
s) verbose_on="0" #verbose goes off
;;
a) encrypt_all_files=true
_print echo "Will do this for all files in this DIR."
;;
h) echo "$usage"
exit
;;
d) _print echo "Will stop Dropbox"
kill $(pgrep Dropbox)
;;
n) do_not_kill_dropbox=true
_print echo "warning: Will NOT stop Dropbox"
;;
\?) printf "illegal options." >&2
echo "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
#--------------------------------
if [[ $do_not_kill_dropbox = false ]]
then
_print echo "Stopping Dropbox"
kill $(pgrep Dropbox)
if [[ $? == 0 ]]
then
_print echo "Dropbox process was killed succuessfully"
else
_print echo "Dropbox process was not killed succuessfully (perhaps not running, see below)"
ps -A | grep Dropbox
_print echo "If output above has only one line and says grep Dropbox, dropbox is not running."
fi
fi
#--------------------------------
if [[ $encrypt_all_files = true ]]
then #decrypt all files from this folder
read -s -p "Enter Password: " mypassword
_print echo "Again..."
read -s -p "Enter Password: " mypasswordz
if [[ $mypassword = $mypasswordz ]]
then
_print echo "Passwords match. Proceeding."
else
_print echo "Passwords do not match. Sorry. "
exit
fi
FILES=`find * -name '*.gpg'`
echo "$FILES"
for f in $FILES
do
#echo "Processing $f"
EXT=`echo "$f" | cut -d'.' -f2`
FILENAME=`echo "$f" | cut -d'.' -f1`
_print echo "$FILENAME.$EXT"
gpg --batch --yes --passphrase "$mypassword" -d -o $FILENAME.$EXT $FILENAME.$EXT.gpg
done
#--------------------------------
read -p "Remove files? [Yy]" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
find * -name '*.gpg' | xargs rm
fi
else
#decrypt a single file
gpg "$1" #beware with files with spaces
#--------------------------------
read -p "Remove files? [Yy]" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
find * -name "$1" | xargs rm
fi
fi
#--------------------------------