#!/bin/sh
#
# Univention Mail Postfix
#
# SPDX-FileCopyrightText: 2015-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

restart=""
for file in transport virtual canonical access relocated; do
	fn="/etc/postfix/$file"
	if [ ! -e "$fn" ]; then
		touch "$fn"
		echo "$(basename "$0"): missing file $fn has been created"
		restart=1
	fi
	if [ ! -e "${fn}.db" ]; then
		echo "$(basename "$0"): recreating missing file ${fn}.db via postmap"
		postmap "$fn"
		restart=1
	fi
done

# workaround for incomplete alias that has been set during container creation
eval "$(ucr shell)"
if [ "$mail_alias_root" = "systemmail@." ] ; then
	ucr set "mail/alias/root=systemmail@${hostname}.${domainname}"
	newaliases
fi

[ -n "$restart" ] && invoke-rc.d postfix restart

exit 0
