From 50f2ea66c81711b6f48556d0ee173dfc05d663d2 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Mon, 4 Jun 2018 21:41:18 +0200 Subject: [PATCH] Switch to Python for rainloop startup script and fix #93 --- webmails/rainloop/Dockerfile | 6 +++--- webmails/rainloop/default.ini | 6 +++--- webmails/rainloop/start.py | 21 +++++++++++++++++++++ webmails/rainloop/start.sh | 20 -------------------- 4 files changed, 27 insertions(+), 26 deletions(-) create mode 100755 webmails/rainloop/start.py delete mode 100755 webmails/rainloop/start.sh diff --git a/webmails/rainloop/Dockerfile b/webmails/rainloop/Dockerfile index 625f1b3f..714390d8 100644 --- a/webmails/rainloop/Dockerfile +++ b/webmails/rainloop/Dockerfile @@ -1,7 +1,7 @@ FROM php:5-apache RUN apt-get update && apt-get install -y \ - unzip + unzip python3 python3-jinja2 ENV RAINLOOP_URL https://github.com/RainLoop/rainloop-webmail/releases/download/v1.12.0/rainloop-community-1.12.0.zip @@ -22,6 +22,6 @@ COPY php.ini /usr/local/etc/php/conf.d/rainloop.ini COPY config.ini /config.ini COPY default.ini /default.ini -COPY start.sh /start.sh +COPY start.py /start.py -CMD ["/start.sh"] +CMD /start.py diff --git a/webmails/rainloop/default.ini b/webmails/rainloop/default.ini index b77281f4..be9a0969 100644 --- a/webmails/rainloop/default.ini +++ b/webmails/rainloop/default.ini @@ -1,13 +1,13 @@ -imap_host = "%FRONT_ADDRESS%" +imap_host = "{{ FRONT_ADDRESS }}" imap_port = 10143 imap_secure = "None" imap_short_login = Off sieve_use = On sieve_allow_raw = Off -sieve_host = "%IMAP_ADDRESS%" +sieve_host = "{{ IMAP_ADDRESS }}" sieve_port = 4190 sieve_secure = "None" -smtp_host = "%FRONT_ADDRESS%" +smtp_host = "{{ FRONT_ADDRESS }}" smtp_port = 10025 smtp_secure = "None" smtp_short_login = Off diff --git a/webmails/rainloop/start.py b/webmails/rainloop/start.py new file mode 100755 index 00000000..a9f5da32 --- /dev/null +++ b/webmails/rainloop/start.py @@ -0,0 +1,21 @@ +#!/usr/bin/python3 + +import jinja2 +import os +import shutil + +convert = lambda src, dst: open(dst, "w").write(jinja2.Template(open(src).read()).render(**os.environ)) + +# Actual startup script +os.environ["FRONT_ADDRESS"] = os.environ.get("FRONT_ADDRESS", "front") +os.environ["IMAP_ADDRESS"] = os.environ.get("IMAP_ADDRESS", "imap") + +base = "/data/_data_/_default_/" +shutil.rmtree(base + "domains/", ignore_errors=True) +os.makedirs(base + "domains", exist_ok=True) +os.makedirs(base + "configs", exist_ok=True) + +convert("/default.ini", "/data/_data_/_default_/domains/default.ini") +convert("/config.ini", "/data/_data_/_default_/configs/config.ini") + +os.execv("/usr/local/bin/apache2-foreground", ["apache2-foreground"]) diff --git a/webmails/rainloop/start.sh b/webmails/rainloop/start.sh deleted file mode 100755 index f43983d0..00000000 --- a/webmails/rainloop/start.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -template(){ - sed \ - -e "s/%FRONT_ADDRESS%/$FRONT_ADDRESS/g" \ - -e "s/%IMAP_ADDRESS%/$IMAP_ADDRESS/g" -} - -# There is no cleaner way to setup the default SMTP/IMAP server or to -# override the configuration -rm -f /data/_data_/_default_/domains/* -mkdir -p /data/_data_/_default_/domains/ /data/_data_/_default_/configs/ -template /data/_data_/_default_/domains/default.ini -template /data/_data_/_default_/configs/config.ini - -# Fix some permissions -chown -R www-data:www-data /data - -# Run apache -exec apache2-foreground