forked from lblod/file-encryption-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt.sh
executable file
·47 lines (40 loc) · 1.11 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
#!/usr/bin/env bash
# Convenience logging function.
info() {
now=$(date +%Y%m%dT%H%M%S)
echo "[INFO] $now: $@";
}
encrypt_files() {
for gl in $ENCRYPT_GLOB;do
for file in $gl;do
if [ -f "$file" ]; then
#Checks if the file is a file not a directory
fileTime=$(stat --printf "%Y" "$file")
curTime=$(date +%s)
if (( ( ($curTime - $fileTime) / 60 ) > $ENCRYPT_AFTER_MINUTES ))
then
info "encrypting $file"
gpg --encrypt -o "$ENCRYPTED_DIR/$(basename "$file").gpg" --recipient "$ENCRYPT_RECIPIENT" --trust-model always "$file" && rm "$file"
fi
fi
done
done
}
info "importing GPG keys"
for x in /keys/*;do
gpg --import "$x";
done
if [ -z $ENCRYPT_RECIPIENT ]; then
info "ENCRYPT_RECIPIENT environment variable not set!"
info "This is a required setting!"
exit -1
fi
if [ -z $ENCRYPT_INTERVAL ];then
encrypt_files
else
while true
do
encrypt_files
sleep "$ENCRYPT_INTERVAL"
done
fi