Skip to content

Commit 5ee5ec7

Browse files
committed
Use conf_env for runtime configuration
1 parent ec0daf4 commit 5ee5ec7

File tree

2 files changed

+14
-55
lines changed

2 files changed

+14
-55
lines changed
Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
11
#!/bin/sh
22
set -e
33

4-
if [ "$(id -u)" != 0 ] || [ x"${PHP_RUNTIME_CONF-1}" != x'1' ]; then
5-
return
4+
if [ "$(id -u)" != 0 ] || [ "${PHP_RUNTIME_CONF-1}" != '1' ]; then
5+
return
66
fi
77

8-
_FPM_CONF="$PHP_INI_DIR/php-fpm.conf"
9-
_FPM_WWW_CONF="$PHP_INI_DIR/php-fpm.d/www.conf"
10-
11-
for _ENV_NAME in $(printenv | awk -F= '{print $1}'); do
12-
if [ "${_ENV_NAME:0:8}" = "FPM_WWW_" ]; then
13-
if [ ! -w "$_FPM_WWW_CONF" ]; then
14-
continue
15-
fi
16-
_START=8
17-
_FILE="$_FPM_WWW_CONF"
18-
elif [ "${_ENV_NAME:0:4}" = "FPM_" ] && [ -w "$_FPM_CONF" ]; then
19-
_START=4
20-
_FILE="$_FPM_CONF"
21-
else
22-
continue
23-
fi
24-
25-
_FPM_NAME="$(echo "${_ENV_NAME:$_START}" | sed -e 's|__|\.|g' | tr '[:upper:]' '[:lower:]')"
26-
_FPM_VALUE="$(eval echo "\${$_ENV_NAME}")"
27-
if grep "${_FPM_NAME} =" "$_FILE" > /dev/null; then
28-
sed -i "s|^[; ]*\($_FPM_NAME *=\).*|\1 $_FPM_VALUE|" "$_FILE"
29-
else
30-
echo "${_FPM_NAME} = ${_FPM_VALUE}" >> "$_FILE"
31-
fi
32-
done
33-
34-
unset -v _FPM_CONF _FPM_WWW_CONF _FPM_NAME _FPM_VALUE _ENV_NAME _START _FILE
8+
conf_env FPM_ --pattern='!/^FPM_WWW_/' --comment=";" --file="$PHP_INI_DIR/php-fpm.conf"
9+
conf_env FPM_WWW_ --comment=";" --file="$PHP_INI_DIR/php-fpm.d/www.conf"

rootfs/docker-entrypoint.d/20-php.sh

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,17 @@ set -e
44
export PATH="$COMPOSER_HOME/vendor/bin:$PATH"
55

66
if [ "$(id -u)" != 0 ] || [ "${PHP_RUNTIME_CONF-1}" != '1' ]; then
7-
return
7+
return
88
fi
99

10-
_PHP_INI="$PHP_INI_DIR/php.ini"
11-
for _ENV_NAME in $(printenv | awk -F= '{print $1}'); do
12-
if [ "${_ENV_NAME:0:8}" = "PHP_EXT_" ]; then
13-
_PHP_EXT="$(echo "${_ENV_NAME:8}" | tr '[:upper:]' '[:lower:]')"
14-
_PHP_EXT_FILE="$PHP_INI_DIR/conf.d/${_PHP_EXT}.ini"
15-
if [ ! -f "$_PHP_EXT_FILE" ] || [ ! -w "$_PHP_EXT_FILE" ]; then
16-
continue
17-
fi
10+
conf_env PHP_ --pattern='!/^PHP_EXT_/' --comment=";" --file="$PHP_INI_DIR/php.ini"
1811

19-
_PHP_VALUE="$(eval echo "\${$_ENV_NAME}")"
20-
if [ "${_PHP_VALUE}" = 1 ] || [ "${_PHP_VALUE}" = true ]; then
21-
sed -i "s/^[; ]*\(zend_extension\|extension\)/\1/" "${_PHP_EXT_FILE}"
22-
else
23-
sed -i "s/^[; ]*\(zend_extension\|extension\)/;\1/" "${_PHP_EXT_FILE}"
24-
fi
25-
elif [ "${_ENV_NAME:0:4}" = "PHP_" ] && [ -w "$_PHP_INI" ]; then
26-
_PHP_NAME="$(echo "${_ENV_NAME:4}" | sed -e 's|__|\.|g' | tr '[:upper:]' '[:lower:]')"
27-
_PHP_VALUE="$(eval echo "\${$_ENV_NAME}")"
28-
if grep "${_PHP_NAME} =" "$_PHP_INI" > /dev/null; then
29-
sed -i "s|^[; ]*\($_PHP_NAME *=\).*|\1 $_PHP_VALUE|" "$_PHP_INI"
30-
else
31-
echo "${_PHP_NAME} = ${_PHP_VALUE}" >> "$_PHP_INI"
32-
fi
33-
fi
34-
done
12+
conf_env "PHP_EXT_" | while read -r extension value; do
13+
file="$(find "$PHP_INI_DIR/conf.d" -name "*${extension}.ini" | head -1)"
14+
if [ ! -f "$file" ] || [ ! -w "$file" ]; then
15+
return
16+
fi
3517

36-
unset -v _PHP_INI _PHP_NAME _PHP_VALUE _ENV_NAME
18+
if [ "${value}" = 1 ] || [ "${value}" = true ]; then prefix=; else prefix=";"; fi
19+
sed -i "s/^[; ]*\(zend_extension\|extension\)/${prefix}\1/" "$file"
20+
done

0 commit comments

Comments
 (0)