1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-14 10:53:30 +02:00
Mailu/webmails/roundcube/start.py

62 lines
2.0 KiB
Python
Raw Normal View History

2018-10-23 10:58:36 +02:00
#!/usr/bin/python3
import os
import logging as log
import sys
from socrate import conf
2019-11-21 14:46:38 +02:00
import subprocess
2018-12-07 13:37:40 +02:00
2019-01-08 05:16:05 +02:00
log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING"))
2021-06-18 23:21:24 +02:00
os.environ["MAX_FILESIZE"] = str(int(int(os.environ.get("MESSAGE_SIZE_LIMIT")) * 0.66 / 1048576))
2018-12-07 13:37:40 +02:00
2021-06-18 23:21:24 +02:00
db_flavor = os.environ.get("ROUNDCUBE_DB_FLAVOR", "sqlite")
if db_flavor == "sqlite":
os.environ["DB_DSNW"] = "sqlite:////data/roundcube.db"
elif db_flavor == "mysql":
os.environ["DB_DSNW"] = "mysql://%s:%s@%s/%s" % (
os.environ.get("ROUNDCUBE_DB_USER", "roundcube"),
2019-11-19 13:22:09 +02:00
os.environ.get("ROUNDCUBE_DB_PW"),
2021-06-19 09:20:23 +02:00
os.environ.get("ROUNDCUBE_DB_HOST", "database"),
2021-06-18 23:21:24 +02:00
os.environ.get("ROUNDCUBE_DB_NAME", "roundcube")
)
elif db_flavor == "postgresql":
os.environ["DB_DSNW"] = "pgsql://%s:%s@%s/%s" % (
os.environ.get("ROUNDCUBE_DB_USER", "roundcube"),
2019-11-19 13:22:09 +02:00
os.environ.get("ROUNDCUBE_DB_PW"),
2021-06-19 09:20:23 +02:00
os.environ.get("ROUNDCUBE_DB_HOST", "database"),
2021-06-18 23:21:24 +02:00
os.environ.get("ROUNDCUBE_DB_NAME", "roundcube")
)
2019-11-19 13:22:09 +02:00
else:
2021-06-18 23:21:24 +02:00
print("Unknown ROUNDCUBE_DB_FLAVOR: %s", db_flavor)
2019-11-19 13:22:09 +02:00
exit(1)
conf.jinja("/php.ini", os.environ, "/usr/local/etc/php/conf.d/roundcube.ini")
2018-10-23 10:58:36 +02:00
# Create dirs, setup permissions
os.system("mkdir -p /data/gpg")
2019-11-21 14:46:38 +02:00
2019-11-21 22:05:15 +02:00
try:
print("Initializing database")
2021-06-18 23:21:24 +02:00
result = subprocess.check_output(["/var/www/html/bin/initdb.sh", "--dir", "/var/www/html/SQL"],
stderr=subprocess.STDOUT)
2019-11-21 22:05:15 +02:00
print(result.decode())
except subprocess.CalledProcessError as e:
if "already exists" in e.stdout.decode():
print("Already initialzed")
else:
print(e.stdout.decode())
quit(1)
try:
print("Upgrading database")
2021-06-18 23:21:24 +02:00
subprocess.check_call(["/var/www/html/bin/update.sh", "--version=?", "-y"], stderr=subprocess.STDOUT)
2019-11-21 22:05:15 +02:00
except subprocess.CalledProcessError as e:
quit(1)
# Setup database permissions
os.system("chown -R www-data:www-data /data")
2018-10-23 10:58:36 +02:00
# Run apache
os.execv("/usr/local/bin/apache2-foreground", ["apache2-foreground"])