Write individual config file from env vars
authorThomas Bruederli <redacted>
Sat, 26 Dec 2020 20:38:15 +0000 (21:38 +0100)
committerThomas Bruederli <redacted>
Sat, 26 Dec 2020 20:38:15 +0000 (21:38 +0100)
This implements the changes proposed in #112 in order
to reflect (changed) env vars used with the Docker container.

templates/docker-entrypoint.sh

index 68df92c468a92b472a22cfecb45fd6fcee634118..83758b851ae10f40be9e5f615f9876b31eebadce 100644 (file)
@@ -72,37 +72,49 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
   : "${ROUNDCUBEMAIL_TEMP_DIR:=/tmp/roundcube-temp}"
 
   if [ ! -e config/config.inc.php ]; then
-    ROUNDCUBEMAIL_PLUGINS_PHP=`echo "${ROUNDCUBEMAIL_PLUGINS}" | sed -E "s/[, ]+/', '/g"`
-    ROUNDCUBEMAIL_DES_KEY=`test -f /run/secrets/roundcube_des_key && cat /run/secrets/roundcube_des_key || head /dev/urandom | base64 | head -c 24`
+    ROUNDCUBEMAIL_DES_KEY=`head /dev/urandom | base64 | head -c 24`
     touch config/config.inc.php
 
-    echo "Write config to $PWD/config/config.inc.php"
+    echo "Write root config to $PWD/config/config.inc.php"
     echo "<?php
-    \$config['db_dsnw'] = '${ROUNDCUBEMAIL_DSNW}';
-    \$config['db_dsnr'] = '${ROUNDCUBEMAIL_DSNR}';
-    \$config['default_host'] = '${ROUNDCUBEMAIL_DEFAULT_HOST}';
-    \$config['default_port'] = '${ROUNDCUBEMAIL_DEFAULT_PORT}';
-    \$config['smtp_server'] = '${ROUNDCUBEMAIL_SMTP_SERVER}';
-    \$config['smtp_port'] = '${ROUNDCUBEMAIL_SMTP_PORT}';
-    \$config['des_key'] = '${ROUNDCUBEMAIL_DES_KEY}';
-    \$config['temp_dir'] = '${ROUNDCUBEMAIL_TEMP_DIR}';
-    \$config['plugins'] = ['${ROUNDCUBEMAIL_PLUGINS_PHP}'];
-    \$config['zipdownload_selection'] = true;
+    \$config['plugins'] = [];
     \$config['log_driver'] = 'stdout';
-    \$config['skin'] = '${ROUNDCUBEMAIL_SKIN}';
+    \$config['zipdownload_selection'] = true;
+    \$config['des_key'] = '${ROUNDCUBEMAIL_DES_KEY}';
+    include(__DIR__ . '/config.docker.inc.php');
     " > config/config.inc.php
 
-    for fn in `ls /var/roundcube/config/*.php 2>/dev/null || true`; do
-      echo "include('$fn');" >> config/config.inc.php
-    done
+  elif ! grep -q "config.docker.inc.php" config/config.inc.php; then
+    echo "include(__DIR__ . '/config.docker.inc.php');" >> config/config.inc.php
+  fi
 
-    # initialize or update DB
-    bin/initdb.sh --dir=$PWD/SQL --create || bin/updatedb.sh --dir=$PWD/SQL --package=roundcube || echo "Failed to initialize database. Please run $PWD/bin/initdb.sh and $PWD/bin/updatedb.sh manually."
-  else
-    echo "WARNING: $PWD/config/config.inc.php already exists."
-    echo "ROUNDCUBEMAIL_* environment variables have been ignored."
+  ROUNDCUBEMAIL_PLUGINS_PHP=`echo "${ROUNDCUBEMAIL_PLUGINS}" | sed -E "s/[, ]+/', '/g"`
+  echo "Write Docker config to $PWD/config/config.docker.inc.php"
+  echo "<?php
+  \$config['db_dsnw'] = '${ROUNDCUBEMAIL_DSNW}';
+  \$config['db_dsnr'] = '${ROUNDCUBEMAIL_DSNR}';
+  \$config['default_host'] = '${ROUNDCUBEMAIL_DEFAULT_HOST}';
+  \$config['default_port'] = '${ROUNDCUBEMAIL_DEFAULT_PORT}';
+  \$config['smtp_server'] = '${ROUNDCUBEMAIL_SMTP_SERVER}';
+  \$config['smtp_port'] = '${ROUNDCUBEMAIL_SMTP_PORT}';
+  \$config['temp_dir'] = '${ROUNDCUBEMAIL_TEMP_DIR}';
+  \$config['skin'] = '${ROUNDCUBEMAIL_SKIN}';
+  \$config['plugins'] = array_filter(array_unique(array_merge(\$config['plugins'], ['${ROUNDCUBEMAIL_PLUGINS_PHP}'])));
+  " > config/config.docker.inc.php
+
+  if [ -e /run/secrets/roundcube_des_key ]; then
+    ROUNDCUBEMAIL_DES_KEY=`cat /run/secrets/roundcube_des_key`
+    echo "\$config['des_key'] = '${ROUNDCUBEMAIL_DES_KEY}';" >> config/config.docker.inc.php
   fi
 
+  # include custom config files
+  for fn in `ls /var/roundcube/config/*.php 2>/dev/null || true`; do
+    echo "include('$fn');" >> config/config.docker.inc.php
+  done
+
+  # initialize or update DB
+  bin/initdb.sh --dir=$PWD/SQL --create || bin/updatedb.sh --dir=$PWD/SQL --package=roundcube || echo "Failed to initialize database. Please run $PWD/bin/initdb.sh and $PWD/bin/updatedb.sh manually."
+
   if [ ! -z "${ROUNDCUBEMAIL_TEMP_DIR}" ]; then
     mkdir -p ${ROUNDCUBEMAIL_TEMP_DIR} && chown www-data ${ROUNDCUBEMAIL_TEMP_DIR}
   fi
@@ -114,7 +126,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
 
   : "${ROUNDCUBEMAIL_LOCALE:=en_US.UTF-8 UTF-8}"
 
-  if [ ! -z "${ROUNDCUBEMAIL_LOCALE}" ]; then
+  if [ -e /usr/sbin/locale-gen ] && [ ! -z "${ROUNDCUBEMAIL_LOCALE}" ]; then
     echo "${ROUNDCUBEMAIL_LOCALE}" > /etc/locale.gen
     /usr/sbin/locale-gen
   fi
git clone https://git.99rst.org/PROJECT