From: Thomas Bruederli Date: Fri, 1 Jan 2021 21:12:43 +0000 (+0100) Subject: Update entry point to write individual config file from env vars X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=26d1b0d6c89d485d2f9f07e068d4cea153c19077;p=roundcube-roundcubemail-docker.git Update entry point to write individual config file from env vars This implements the changes proposed in #112 and should fix issues #87, #111 and #116. --- diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 68df92c..83758b8 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -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 " 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 " 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 diff --git a/fpm-alpine/docker-entrypoint.sh b/fpm-alpine/docker-entrypoint.sh index 78804ff..83758b8 100755 --- a/fpm-alpine/docker-entrypoint.sh +++ b/fpm-alpine/docker-entrypoint.sh @@ -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 " 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 " 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 @@ -111,6 +123,13 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then echo "upload_max_filesize=${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}" >> /usr/local/etc/php/conf.d/roundcube-override.ini echo "post_max_size=${ROUNDCUBEMAIL_UPLOAD_MAX_FILESIZE}" >> /usr/local/etc/php/conf.d/roundcube-override.ini fi + + : "${ROUNDCUBEMAIL_LOCALE:=en_US.UTF-8 UTF-8}" + + if [ -e /usr/sbin/locale-gen ] && [ ! -z "${ROUNDCUBEMAIL_LOCALE}" ]; then + echo "${ROUNDCUBEMAIL_LOCALE}" > /etc/locale.gen + /usr/sbin/locale-gen + fi fi exec "$@" diff --git a/fpm/docker-entrypoint.sh b/fpm/docker-entrypoint.sh index 68df92c..83758b8 100755 --- a/fpm/docker-entrypoint.sh +++ b/fpm/docker-entrypoint.sh @@ -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 " 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 " 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