Some checks are pending
continuous-integration/drone/push Build is running
Closes: #36
74 lines
2.4 KiB
Bash
74 lines
2.4 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
echo "Starting happyDeliver container..."
|
|
|
|
# Get environment variables with defaults
|
|
[ -n "${HOSTNAME}" ] || HOSTNAME=$(hostname)
|
|
HAPPYDELIVER_DOMAIN="${HAPPYDELIVER_DOMAIN:-happydeliver.local}"
|
|
|
|
echo "Hostname: $HOSTNAME"
|
|
echo "Domain: $HAPPYDELIVER_DOMAIN"
|
|
|
|
# Create socket directories
|
|
mkdir -p /var/spool/postfix/authentication_milter
|
|
chown mail:mail /var/spool/postfix/authentication_milter
|
|
chmod 750 /var/spool/postfix/authentication_milter
|
|
|
|
mkdir -p /var/spool/postfix/rspamd
|
|
chown rspamd:mail /var/spool/postfix/rspamd
|
|
chmod 750 /var/spool/postfix/rspamd
|
|
|
|
# Create log directory
|
|
mkdir -p /var/log/happydeliver /var/cache/authentication_milter /var/spool/authentication_milter /var/lib/authentication_milter /run/authentication_milter
|
|
chown happydeliver:happydeliver /var/log/happydeliver
|
|
chown mail:mail /var/cache/authentication_milter /run/authentication_milter /var/spool/authentication_milter /var/lib/authentication_milter
|
|
|
|
# Replace placeholders in Postfix configuration
|
|
echo "Configuring Postfix..."
|
|
sed -i "s/__HOSTNAME__/${HOSTNAME}/g" /etc/postfix/main.cf
|
|
sed -i "s/__DOMAIN__/${HAPPYDELIVER_DOMAIN}/g" /etc/postfix/main.cf
|
|
|
|
# Add certificates to postfix
|
|
[ -n "${POSTFIX_CERT_FILE}" ] && [ -n "${POSTFIX_KEY_FILE}" ] && {
|
|
cat <<EOF >> /etc/postfix/main.cf
|
|
smtpd_tls_cert_file = ${POSTFIX_CERT_FILE}
|
|
smtpd_tls_key_file = ${POSTFIX_KEY_FILE}
|
|
smtpd_tls_security_level = may
|
|
EOF
|
|
}
|
|
|
|
# Replace placeholders in configurations
|
|
sed -i "s/__HOSTNAME__/${HOSTNAME}/g" /etc/authentication_milter.json
|
|
|
|
# Initialize Postfix aliases
|
|
if [ -f /etc/postfix/aliases ]; then
|
|
echo "Initializing Postfix aliases..."
|
|
postalias /etc/postfix/aliases || true
|
|
fi
|
|
|
|
# Compile transport maps
|
|
if [ -f /etc/postfix/transport_maps ]; then
|
|
echo "Compiling transport maps..."
|
|
postmap /etc/postfix/transport_maps
|
|
fi
|
|
|
|
# Update SpamAssassin rules
|
|
echo "Updating SpamAssassin rules..."
|
|
sa-update || echo "SpamAssassin rules update failed (might be first run)"
|
|
|
|
# Compile SpamAssassin rules
|
|
sa-compile || echo "SpamAssassin compilation skipped"
|
|
|
|
# Initialize database if it doesn't exist
|
|
if [ ! -f /var/lib/happydeliver/happydeliver.db ]; then
|
|
echo "Database will be initialized on first API startup..."
|
|
fi
|
|
|
|
# Set proper permissions
|
|
chown -R happydeliver:happydeliver /var/lib/happydeliver
|
|
|
|
echo "Configuration complete, starting services..."
|
|
|
|
# Execute the main command (supervisord)
|
|
exec "$@"
|