-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.sh
executable file
·76 lines (62 loc) · 1.73 KB
/
encrypt.sh
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
#! /bin/bash
# layout variables
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
BLUE="\033[0;34m"
MAGENTA="\033[0;35m"
CYAN="\033[0;36m"
GREY="\033[0;37m"
COLORRESET="\033[0m"
SPACER=" "
###############################################################################################
function absolute_path()
{
# remove trailing slash
path=$( echo "$1" | sed -e "s/\/*$//" )
# make absolute
[ "${path/#\//}" != "$path" ] || path="$PWD/$path"
# return
echo $path
}
##########################################################################################
function encrypt_file()
{
file=$1
filedir=${file%/*}
filename=$(basename $file)
tar -C $filedir -jcf $file.tbz2 $filename && openssl des3 -a -pass "env:pw" -in $file.tbz2 -out $file.encrypted && rm $file.tbz2
return 1
}
##########################################################################################
function encrypt()
{
prefix=$1
if [ $(find $prefix -name '*.private' | wc -l) != 0 ]; then
echo -e "$GREEN-$COLORRESET found some private files in $prefix, start locking"
else
echo -e "$RED-$COLORRESET found no .private files, nothing to do"
exit
fi
echo -e "$SPACER$YELLOW-$COLORRESET Requesting encryption password..."
read -p "password: " pw
read -p "verify : " pw_verif
if [ $pw != $pw_verif ]; then
echo -e "$RED ERROR: Verification failed"
return 1
fi
export pw
for file in $(find $prefix -name '*.private'); do
encrypt_file $file
echo -e "$SPACER$GREEN+$COLORRESET $file.encrypted"
done
return 0
}
##########################################################################################
# main execution
if [ ! -z "$1" ]; then
prefix=$(absolute_path "$1")
else
prefix=$PWD
fi
encrypt $prefix