#!/bin/sh
set -e

SOURCE_DIR=$(realpath $(dirname "${0}"))/postfix

# Build Docker container
docker build -t postfix ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/postfix /etc/init.d/postfix
rc-update -u

# Copy existing config files into persistent storage
mkdir -p /srv/postfix/conf /srv/postfix/data
docker run --rm -v /srv/postfix/conf:/mnt/conf postfix cp -rp /etc/postfix/. /mnt/conf

# Configure postfix
cp ${SOURCE_DIR}/srv/postfix/conf/main.cf /srv/postfix/conf/main.cf
