#!/usr/bin/env bash

set -e

. ${0%/*}/_functions.sh

ok "* haraka installation..."

adduser --uid 88 --system delivery --ingroup mail > /dev/null

# spool
mkdir /var/spool/haraka
chown delivery:mail /var/spool/haraka


# we link dkim domains during warmup
mkdir -p /opt/haraka-smtp/config/dkim
chown mail:mail -R /opt/haraka-smtp/config/dkim
mkdir -p /opt/haraka-submission/config/
ln -s /opt/haraka-smtp/config/dkim /opt/haraka-submission/config/dkim
chown mail:mail -R /opt/haraka-submission/config/dkim

# spamassassin want to create loc files in user home
change "s~/home/smtpd~/tmp~" /etc/passwd

# spool_dir:
mkdir /tmp/qpsmtpd
chmod 777 /tmp/qpsmtpd

touch /opt/haraka-smtp/config/host_list
touch /opt/haraka-submission/config/host_list

chown mail:mail /opt/haraka-smtp/config/host_list
chown mail:mail /opt/haraka-submission/config/host_list

ln -s /data/server.ini /opt/haraka-smtp/config/server.ini
ln -s /data/server.ini /opt/haraka-submission/config/server.ini

ln -s /opt/haraka-smtp/plugins /opt/haraka-submission/plugins

##############################################################################################################

