entrypoint 1.67 KB
#!/bin/bash

set -ex

hostuser_home="$(getent passwd hostuser | cut -f 6 -d :)"

if [[ $GID ]]; then
	old_gid=$(getent group hostgroup | cut -f 3 -d :)
	groupmod -g $GID hostgroup
	find "$hostuser_home" -gid $old_gid -print0 | xargs -0r chgrp hostgroup
fi
if [[ $UID ]]; then
	usermod -u $UID hostuser
fi

HOSTNAME=$(hostname -f)

postconf -e \
	"myhostname = ${POSTFIX_MAILNAME:-$HOSTNAME}" \
	"myorigin = app" \
	"mydestination = $HOSTNAME, localhost.localdomain, localhost, app" \
	"mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 10.0.0.0/8 172.0.0.0/8 192.168.0.0/16"\
	"inet_protocols = all" \
	"relayhost = $POSTFIX_RELAYHOST" \
	"virtual_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual-regexp" \
	"home_mailbox = Maildir/" \
	&& true

: > /etc/postfix/virtual
postmap /etc/postfix/virtual

if [[ $POSTFIX_OVERRIDE_FROM ]]; then
	postconf -e smtp_generic_maps=regexp:/etc/postfix/generic-regexp
	echo "/^(root|hostuser)(\\+.*)?@[^.]+$/ $POSTFIX_OVERRIDE_FROM" > /etc/postfix/generic-regexp
else
	postconf -e smtp_generic_maps=
fi

: ${POSTFIX_FORWARD_APP:=hostuser+app@localhost}
: ${POSTFIX_FORWARD_CATCHALL:=hostuser+catchall@localhost}

POSTFIX_FORWARD_APP_quoted="$(echo "$POSTFIX_FORWARD_APP" | sed 's/\([][\\+*.$^()]\)/\\\1/g')"
POSTFIX_FORWARD_CATCHALL_quoted="$(echo "$POSTFIX_FORWARD_CATCHALL" | sed 's/\([][\\+*.$^()]\)/\\\1/g')"
(
	echo "/.+@app/ $POSTFIX_FORWARD_APP"
	if [[ $POSTFIX_CATCHALL ]]; then
		echo "if !/^($POSTFIX_FORWARD_APP_quoted|$POSTFIX_FORWARD_CATCHALL_quoted)/"
		echo "/.+@.+/ $POSTFIX_FORWARD_CATCHALL"
		echo "endif"
	fi
) > /etc/postfix/virtual-regexp

cp /etc/resolv.conf /etc/services /var/spool/postfix/etc

/etc/init.d/rsyslog start
exec "$@"