forked from edyounis/docker-cryfs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·50 lines (33 loc) · 1.04 KB
/
run.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
#!/bin/bash
set -e
ENC_PATH=/encrypted
DEC_PATH=/decrypted
function sigterm_handler {
echo "sending SIGTERM to child pid"
kill -SIGTERM ${pid}
echo "Unmounting: cryfs_mount ${DEC_FOLDER} at: $(date +%Y.%m.%d-%T)"
cryfs_unmount "${DEC_PATH}"
echo "exiting container now"
exit $?
}
function sighup_handler {
echo "sending SIGHUP to child pid"
kill -SIGHUP ${pid}
wait ${pid}
}
trap sigterm_handler SIGINT SIGTERM
trap sighup_handler SIGHUP
[[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o cryfsuser
[[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o cryfs
unset pid
if [ ! -z "$PASSWD" ]; then
echo "${PASSWD}" | su-exec cryfsuser cryfs ${CRYFS_OPTIONS} -o ${MOUNT_OPTIONS} -f encrypted decrypted & pid=($!)
else
su-exec cryfsuser cryfs ${CRYFS_OPTIONS} -o ${MOUNT_OPTIONS} -f encrypted decrypted & pid=($!)
fi
wait "${pid}"
echo "cryfs crashed at: $(date +%Y.%m.%d-%T)"
echo "Unmounting: cryfs_mount ${DEC_FOLDER} at: $(date +%Y.%m.%d-%T)"
cryfs_unmount "${DEC_PATH}"
echo "exiting container now"
exit $?