-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.sh
More file actions
executable file
·81 lines (80 loc) · 2.29 KB
/
encrypt.sh
File metadata and controls
executable file
·81 lines (80 loc) · 2.29 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
#!/bin/bash
dropbox_exec="/Applications/Dropbox.app/Contents/MacOS/Dropbox"
usage="$(basename "$0") [-h] [-r] [-a] [-s] -- encrypts files stored on dropbox (kills dropbox process)
-h show this help text
-r restarts dropbox after command one (not default)
-a executes encrypt 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
restart_dropbox=false
while getopts 'sahr' 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
;;
r) _print echo "Will start Dropbox after commands are done"
restart_dropbox=true
;;
\?) printf "illegal options." >&2
echo "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
#--------------------------------
if [[ $encrypt_all_files = true ]]
then #decrypt all files from this folder
read -s -p "Enter Password: " mypassword
echo "Again..."
read -s -p "Enter Password: " mypasswordz
if [[ $mypassword = $mypasswordz ]]
then
echo "Passwords match. Proceeding."
else
echo "Passwords do not match. Sorry. "
exit
fi
#--------------------------------
FILES=`find * -type f -not -name '*gpg' -not -name '*sh'`
echo "$FILES"
for f in $FILES
do
echo "Processing $f"
#gpg -c $f
gpg --batch --yes --passphrase "$mypassword" -c $f
done
#--------------------------------
read -p "Remove files [Yy]?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
find * -type f -not -name '*gpg' -not -name '*sh' | xargs rm
fi
else
#decrypt a single file
gpg -c "$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
#--------------------------------
if [[ $restart_dropbox = true ]]
then
echo "Restarting Dropbox"
$dropbox_exec &
fi