forked from Chekote/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·44 lines (35 loc) · 1.48 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·44 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
if [ "$PHP_FPM_USER_ID" != "" ]; then
(>&2 echo "Warning: PHP_FPM_USER_ID is deprecated. Please use WWW_DATA_USER_ID instead.")
WWW_DATA_USER_ID=$PHP_FPM_USER_ID
fi
# Set the uid that www-data will run as if one was specified
if [ "$WWW_DATA_USER_ID" != "" ]; then
usermod -u $WWW_DATA_USER_ID www-data
fi
replace_in_file() {
PHP_FILE=${1}
VAR_MATCH=${2}
REPLACE_VARS=`printenv | awk -F'=' '{print $1}' | grep -E "^$2"`
# If there are variables to be replace move forward
if [ ! -z "$REPLACE_VARS" ]; then
for VAR_NAME in $REPLACE_VARS; do
# get the directive name by removing the prefixes e.g. PHP_CLI and making them lowercase.
# if there are any double '_' replace with a dot.
DIRECTIVE=`echo "$VAR_NAME" | cut -c9- | tr '[:upper:]' '[:lower:]' | sed 's/__/./g'`
VALUE=`printenv "$VAR_NAME"`
# Replace the variable only if it starts with the name of the directive and remove optional ';'
sed -i "s!^\(;\)\{0,1\}$DIRECTIVE = [^\n]\+!$DIRECTIVE = $VALUE!g" "$PHP_FILE"
done
fi
}
# Set php.ini options
for TYPE in cli fpm; do
PHP_INI=/etc/php/${PHP_VERSION}/${TYPE}/php.ini
VAR_TYPE=`echo "PHP_$TYPE" | tr '[:lower:]' '[:upper:]'`
# Replace all variables ( prefixed by PHP_TYPE ) on the proper PHP type file
replace_in_file $PHP_INI $VAR_TYPE
# Replace all variables ( prefixed by PHP_ALL )
replace_in_file $PHP_INI "PHP_ALL"
done
/usr/local/bin/entrypoint.sh "$@"