Files
docker-php-fpm/Dockerfiles/prod/data/docker-entrypoint.d/37-fix-php-5.3-env-vars.sh
2018-05-12 15:39:13 +02:00

48 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# PHP FPM 5.3 does not allow to pass through environment variables
# This is a hacky shell script to create:
# env[NAME]='VALUE' entries for PHP FPM config out of all current env vars
# Check if an environment variable is valid
# for PHP-FPM config and if yes return it
_get_env_php_fpm() {
local name="${1}"
local env=
# Not set
if ! printenv "${name}" >/dev/null 2>&1; then
return 1
fi
# Empty variables are not supported by PHP-FPM config syntax
env="$( printenv "${name}" )"
if [ -z "${env}" ]; then
return 1
fi
# Values containing a = are not supported by PHP-FPM config syntax
if echo "${env}" | grep -q '='; then
return 1
fi
echo "${env}"
}
# Write all valid environment variables to a PHP-FPM config
set_env_php_fpm() {
local config="${1}"
# Clear file
echo "[www]" > "${config}"
# Append env variables
for name in $(printenv | awk -F'=' '{print $1}'); do
if _get_env_php_fpm "${name}" >/dev/null 2>&1; then
echo "env[${name}]='$( _get_env_php_fpm "${name}" )'" >> "${config}"
fi
done
}