You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import glob
|
|
import jinja2
|
|
import pathlib
|
|
|
|
def jinja_render_file(in_path, data, out_path):
|
|
render_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(in_path)))
|
|
output = render_environment.get_template(os.path.basename(in_path)).render(**data)
|
|
|
|
with open(out_path, 'w', encoding='utf-8') as rf:
|
|
rf.write(output)
|
|
|
|
|
|
def is_valid_postconf_line(line):
|
|
return not line.startswith("#") \
|
|
and not line == ''
|
|
|
|
if "MESSAGE_SIZE_LIMIT" not in os.environ:
|
|
os.environ["MESSAGE_SIZE_LIMIT"] = 52428800
|
|
|
|
if "DOVECOT_HOST" not in os.environ:
|
|
os.environ['DOVECOT_HOST'] = 'dovecot.mail.svc.cluster.local'
|
|
|
|
if "DOVECOT_LMTP_PORT" not in os.environ:
|
|
os.environ['DOVECOT_LMTP_PORT'] = '2525'
|
|
|
|
if "DOVECOT_AUTH_PORT" not in os.environ:
|
|
os.environ['DOVECOT_AUTH_PORT'] = '12345'
|
|
|
|
if "RELAY_NETS" not in os.environ:
|
|
os.environ['RELAY_NETS'] = ''
|
|
|
|
for postfix_file in glob.glob("/conf/**/**.cf", recursive=True):
|
|
p = pathlib.Path(postfix_file)
|
|
p = p.relative_to(*p.parts[:2])
|
|
p = p.joinpath('/etc/postfix', *p.parts)
|
|
if not p.parent.is_dir():
|
|
p.parent.mkdir()
|
|
|
|
destination = str(p)
|
|
shutil.copyfile(postfix_file, destination)
|
|
|
|
for postfix_file in glob.glob("/conf/**/**.cf.jinja", recursive=True):
|
|
p = pathlib.Path(postfix_file)
|
|
p = p.relative_to(*p.parts[:2])
|
|
p = p.joinpath('/etc/postfix', *p.parts)
|
|
if not p.parent.is_dir():
|
|
p.parent.mkdir()
|
|
|
|
destination = str(p)
|
|
destination = destination[0:-6] # Remove .jinja from the output path
|
|
jinja_render_file(postfix_file, os.environ, destination)
|
|
|
|
if os.path.exists("/overrides/postfix.cf"):
|
|
for line in open("/overrides/postfix.cf").read().strip().split("\n"):
|
|
if is_valid_postconf_line(line):
|
|
os.system('postconf -e "{}"'.format(line))
|
|
|
|
if os.path.exists("/overrides/postfix.master"):
|
|
for line in open("/overrides/postfix.master").read().strip().split("\n"):
|
|
if is_valid_postconf_line(line):
|
|
os.system('postconf -Me "{}"'.format(line))
|
|
|
|
os.system("/usr/lib/postfix/sbin/post-install meta_directory=/etc/postfix create-missing")
|
|
# Before starting postfix, we need to check permissions on /queue
|
|
# in the event that postfix,postdrop id have changed
|
|
os.system("postfix set-permissions")
|
|
os.system("postfix start-fg")
|