1
0
mirror of https://github.com/zokradonh/kopano-docker.git synced 2026-08-11 16:32:59 +00:00

make webapp configurable from env (#112)

* make webapp configurable from env
inspired by https://github.com/mlan/docker-kopano/blob/master/assets/entrypoint.sh#L80-L92 and https://github.com/zokradonh/kopano-docker/blob/a7c213434766f5433148ea6b50e0894094b92e12/meet/start-service.sh#L22-L27
  * updating is in a dedicated function and has verbose error handling
* add documentation for env variables
This commit is contained in:
Felix Bartels
2019-03-18 12:45:03 +01:00
committed by GitHub
parent c8c55ae2aa
commit 4e367badc5
3 changed files with 86 additions and 9 deletions
+40 -7
View File
@@ -8,6 +8,28 @@ ADDITIONAL_KOPANO_WEBAPP_PLUGINS=${ADDITIONAL_KOPANO_WEBAPP_PLUGINS:-""}
set -eu # unset variables are errors & non-zero return values exit the whole script
php_cfg_gen() {
local cfg_file="$1"
local cfg_setting="$2"
local cfg_value="$3"
if [ -e "$cfg_file" ]; then
if grep -q "$cfg_setting" "$cfg_file"; then
echo "Setting $cfg_setting = $cfg_value in $cfg_file"
sed -ri "s#(\s*define).+${cfg_setting}.+#\define(\x27${cfg_setting}\x27, \x27${cfg_value}\x27\);#g" "$cfg_file"
else
echo "Error: Config option $cfg_setting not found in $cfg_file"
cat "$cfg_file"
exit 1
fi
else
echo "Error: Config file $cfg_file not found. Plugin not installed?"
local dir
dir=$(dirname "$cfg_file")
ls -la "$dir"
exit 1
fi
}
ADDITIONAL_KOPANO_PACKAGES="$ADDITIONAL_KOPANO_PACKAGES $ADDITIONAL_KOPANO_WEBAPP_PLUGINS"
[ -n "${ADDITIONAL_KOPANO_PACKAGES// }" ] && apt update
@@ -18,22 +40,33 @@ ADDITIONAL_KOPANO_PACKAGES="$ADDITIONAL_KOPANO_PACKAGES $ADDITIONAL_KOPANO_WEBAP
fi
done
echo "Ensure directories"
# Ensure directories exist
mkdir -p /run/sessions /tmp/webapp
if [ "$KCCONF_SERVERHOSTNAME" == "127.0.0.1" ]; then
echo "Kopano WebApp is using the default: connection"
else
echo "Kopano WebApp is using an ip connection"
sed -e "s#define(\"DEFAULT_SERVER\",\s*\".*\"#define(\"DEFAULT_SERVER\", \"https://${KCCONF_SERVERHOSTNAME}:${KCCONF_SERVERPORT}/kopano\"#" \
-i /etc/kopano/webapp/config.php
php_cfg_gen /etc/kopano/webapp/config.php DEFAULT_SERVER "https://${KCCONF_SERVERHOSTNAME}:${KCCONF_SERVERPORT}/kopano"
fi
# TODO is enabling this really neccesary when reverse proxying webapp?
echo "Configuring Kopano WebApp for use behind a reverse proxy"
sed \
-e "s#define(\"INSECURE_COOKIES\",\s*.*)#define(\"INSECURE_COOKIES\", true)#" \
-i /etc/kopano/webapp/config.php
php_cfg_gen /etc/kopano/webapp/config.php INSECURE_COOKIES true
# configuring webapp from env
for setting in $(compgen -A variable KCCONF_WEBAPP_); do
setting2=${setting#KCCONF_WEBAPP_}
php_cfg_gen /etc/kopano/webapp/config.php "${setting2}" "${!setting}"
done
# configuring webapp plugins from env
for setting in $(compgen -A variable KCCONF_WEBAPPPLUGIN_); do
setting2=${setting#KCCONF_WEBAPPPLUGIN_}
filename="${setting2%%_*}"
setting3=${setting#KCCONF_WEBAPPPLUGIN_${filename}_}
identifier="${filename,,}"
php_cfg_gen /etc/kopano/webapp/config-"$identifier".php "${setting3}" "${!setting}"
done
echo "Ensure config ownership"
chown -R www-data:www-data /run/sessions /tmp/webapp