-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·105 lines (88 loc) · 2.12 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·105 lines (88 loc) · 2.12 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh
set -eu
write_dma_conf () {
[ -f /etc/dma/dma.conf ] && return
{
echo "# config automatically generated from DMA_* env vars"
echo
printenv \
| grep ^DMA_ \
| sed -E 's/^DMA_//; /^[^=]*=(false)?$/d; s/^([^=]*)=true$/\1/; s/^([^=]*)=/\1 /'
} > /etc/dma/dma.conf
}
verify_dma_conf () {
dma 2>&1 | grep -v 'no recipients$' >&2 && {
echo
echo "Generated config:"
echo
nl -b a -s ': ' -w 2 /etc/dma/dma.conf
exit 1
} >&2 || true
}
write_dma_auth () {
grep -Evq '^\s*(#|$)' /etc/dma/auth.conf && return
if [ -n "${AUTH_CONTENTS:+1}" ]; then
printenv AUTH_CONTENTS > /etc/dma/auth.conf
elif [ -n "${AUTH_PASS:+1}${AUTH_PASS_FILE:+1}" ]; then
{
printf '%s|%s:' "${AUTH_USER:?}" "${AUTH_HOST:-$DMA_SMARTHOST}"
if [ -n "${AUTH_PASS_FILE-}" ]; then
{
cat "$AUTH_PASS_FILE"
# make sure there's a newline
echo
} | head -n 1
else
printenv AUTH_PASS
fi
} > /etc/dma/auth.conf
else
return 0
fi
}
setup_utils () {
test -d /utils-export || return 0
echo "Setting up /utils-export/"
cp -Rpv /utils/* /utils-export/
}
: \
${DMA_MAILNAME=${MAILNAME-}} \
${DMA_MASQUERADE=${MASQUERADE-}} \
${DMA_SMARTHOST=${SMARTHOST-}} \
${DMA_PORT=${SMARTHOST_PORT-}} \
${DMA_AUTHPATH="/etc/dma/auth.conf"}
export DMA_MAILNAME DMA_SMARTHOST DMA_SMARTHOST DMA_PORT DMA_AUTHPATH
# set default command if flags passed
[ "${1#-}" = "$1" ] || set -- msmtpd "$@"
SLEEP_ONLY=
if [ -n "${NO_NETWORK-}" ] && [ $# -eq 1 ] && [ "$1" = "msmtpd" ]; then
SLEEP_ONLY=1
fi
[ "$1" = "msmtpd" ] && setup_utils
write_dma_conf
case "$1" in
dma|mailq|msmtpd|newaliases|sendmail) verify_dma_conf ;;
esac
write_dma_auth
if [ "$1" = "msmtpd" ]; then
shift
if [ -z "$SLEEP_ONLY" ]; then
set -- tini -- msmtpd \
--interface 0.0.0.0 \
--log /dev/stdout \
--command 'dma -f %F --' \
"$@"
else
set -- tini -- sleep inf
fi
# start syslogd to handle dma logging
test -s /dev/log || ( syslogd -nSO - & )
# flush the queue every 15 mins
( sh -c 'while sleep 15m; do dma -q1; done' & )
if [ -z "$SLEEP_ONLY" ]; then
echo "Starting msmtpd..."
else
echo "Waiting for signal..."
fi
fi
exec "$@"