2022-09-13 16:05:48 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
echo "Now in entrypoint.sh for Webcron Management"
|
|
|
|
echo "Script: 1.0.21 (2022-02-17)"
|
|
|
|
echo "User: '$(whoami)'"
|
|
|
|
echo "Group: '$(id -g -n)'"
|
|
|
|
echo "Working dir: '$(pwd)'"
|
|
|
|
|
|
|
|
# https://github.com/docker-library/wordpress/blob/master/docker-entrypoint.sh
|
|
|
|
# usage: file_env VAR [DEFAULT]
|
|
|
|
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
|
|
|
|
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
|
|
|
|
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
|
|
|
|
file_env() {
|
|
|
|
local var="$1"
|
|
|
|
local fileVar="${var}_FILE"
|
|
|
|
local def="${2:-}"
|
|
|
|
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
|
|
|
|
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
local val="$def"
|
|
|
|
if [ "${!var:-}" ]; then
|
|
|
|
val="${!var}"
|
|
|
|
elif [ "${!fileVar:-}" ]; then
|
|
|
|
val="$(< "${!fileVar}")"
|
|
|
|
fi
|
|
|
|
export "$var"="$val"
|
|
|
|
unset "$fileVar"
|
|
|
|
}
|
|
|
|
|
|
|
|
# envs that can be appended with _FILE
|
|
|
|
envs=(
|
2022-09-21 16:13:26 +02:00
|
|
|
APP_ENV
|
2022-09-13 16:05:48 +02:00
|
|
|
DATABASE_URL
|
|
|
|
DEMO_MODE
|
|
|
|
DEMO_USER
|
|
|
|
DEMO_PASS
|
|
|
|
APP_SECRET
|
|
|
|
ENCRYPTION_METHOD
|
|
|
|
HASHING_METHOD
|
|
|
|
DEBUG
|
|
|
|
COOKIE_LIFETIME
|
|
|
|
TRUSTED_PROXIES
|
|
|
|
MAILER_DSN
|
|
|
|
MAILER_FROM
|
|
|
|
)
|
|
|
|
|
|
|
|
echo "Now parsing _FILE variables."
|
|
|
|
for e in "${envs[@]}"; do
|
|
|
|
file_env "$e"
|
|
|
|
done
|
|
|
|
echo "done!"
|
|
|
|
|
|
|
|
|
|
|
|
echo "Dump envs to .env..."
|
|
|
|
rm -rf .env
|
|
|
|
touch .env
|
|
|
|
for e in "${envs[@]}"; do
|
|
|
|
echo "$e=\"${!e}\"" >> .env
|
|
|
|
done
|
|
|
|
echo "Dump auto load..."
|
|
|
|
composer dump-autoload
|
|
|
|
|
|
|
|
echo "Current working dir is '$(pwd)'"
|
|
|
|
echo "Parsing database url."
|
|
|
|
|
|
|
|
DB_CONNECTION=$(php -r "echo parse_url('$DATABASE_URL')['scheme'];")
|
|
|
|
DB_HOST=$(php -r "echo parse_url('$DATABASE_URL')['host'];")
|
|
|
|
DB_PORT=$(php -r "echo parse_url('$DATABASE_URL')['port'];")
|
|
|
|
DB_NAME=$(php -r "echo parse_url('$DATABASE_URL')['path'];")
|
|
|
|
echo "Wait for the database."
|
|
|
|
if [[ -z "$DB_PORT" ]]; then
|
|
|
|
if [[ $DB_CONNECTION == "mysql" ]]; then
|
|
|
|
DB_PORT=3306
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ -n "$DB_PORT" ]]; then
|
|
|
|
/usr/local/bin/wait-for-it.sh "${DB_HOST}:${DB_PORT}" -t 60 -- echo "DB is up."
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Wait another 5 seconds in case the DB needs to boot."
|
|
|
|
sleep 5
|
|
|
|
echo "Done waiting for the DB to boot."
|
|
|
|
|
|
|
|
if [[ $DKR_BUILD_LOCALE == "true" ]]; then
|
|
|
|
echo "Will build all locales..."
|
|
|
|
locale-gen
|
|
|
|
else
|
|
|
|
echo "Will not build the locales..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
php bin/console cache:clear
|
|
|
|
php bin/console cache:warm
|
|
|
|
|
|
|
|
# set docker var.
|
|
|
|
export IS_DOCKER=true
|
|
|
|
|
|
|
|
if [ -z $APACHE_RUN_USER ]
|
|
|
|
then
|
|
|
|
APACHE_RUN_USER='www-data'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z $APACHE_RUN_GROUP ]
|
|
|
|
then
|
|
|
|
APACHE_RUN_GROUP='www-data'
|
|
|
|
fi
|
|
|
|
|
|
|
|
chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $WEBCRON_ROOT/var
|
|
|
|
|
|
|
|
|
|
|
|
exec apache2-foreground
|