-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·53 lines (40 loc) · 1.25 KB
/
entrypoint.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
#!/bin/bash
set -o errexit
CMD="/usr/bin/imapfilter"
ARGS=""
if [[ -n $IMAPFILTER_CONFIG_DIR ]];then
export IMAPFILTER_HOME=$IMAPFILTER_CONFIG_DIR
fi
if [[ -n $IMAPFILTER_CONFIG ]];then
ARGS="-c $IMAPFILTER_CONFIG "
fi
if [[ -n $IMAPFILTER_VERBOSE ]];then
ARGS="$ARGS -v "
fi
if [[ -n $IMAPFILTER_DEBUG_FILE ]];then
ARGS="$ARGS -d $IMAPFILTER_DEBUG_FILE "
fi
if [[ -n $IMAPFILTER_DRY_RUN ]];then
ARGS="$ARGS -n "
fi
if [[ -n $IMAPFILTER_EXTRA_ARGS ]];then
ARGS="$ARGS $IMAPFILTER_EXTRA_ARGS "
fi
exec 3>&1
# https://www.linuxjournal.com/content/bash-redirections-using-exec
if [[ -n $IMAPFILTER_LOG_DIR ]];then
npipe_stdout=/tmp/imapfilter-stdout-$$-${RANDOM}.tmp
npipe_stderr=/tmp/imapfilter-stderr-$$-${RANDOM}.tmp
mknod $npipe_stdout p
mknod $npipe_stderr p
echo "Redirecting stdout to ${IMAPFILTER_LOG_DIR}/imapfilter-stdout.log"
echo "Redirecting stderr to ${IMAPFILTER_LOG_DIR}/imapfilter-errors.log"
ts "%Y-%m-%d %H:%M:%S: " <$npipe_stdout >> ${IMAPFILTER_LOG_DIR}/imapfilter-stdout.log &
ts "%Y-%m-%d %H:%M:%S: " <$npipe_stderr >> ${IMAPFILTER_LOG_DIR}/imapfilter-errors.log &
exec 1>&-
exec 1>$npipe_stdout
exec 2>&-
exec 2>$npipe_stderr
fi
echo "Running: $CMD $ARGS" >&3
exec $CMD $ARGS