flarum-docker/docker/docker-entrypoint.sh

60 lines
1.6 KiB
Bash
Raw Normal View History

2023-08-05 17:42:27 +00:00
#!/bin/bash
set -e
# Wait for MySQL/MariaDB
2023-08-05 20:17:52 +00:00
echo "Waiting for MySQL/MariaDB..."
2023-08-05 17:42:27 +00:00
MAX_RETRY=45
RETRY=1
while ! mysql --protocol TCP -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -e "show databases;" > /dev/null 2>&1; do
sleep 1
RETRY=`expr $RETRY + 1`
if [ $RETRY -gt $MAX_RETRY ]; then
>&2 echo "We have been waiting for MySQL too long already; failing."
exit 1
fi;
done
# Set up Flarum
if [[ -e '/flarum/app/public/assets/.installed.lock' ]]; then
# If Flarum has already been installed, just create a config file
echo "Creating config file..."
cat << EOF > /flarum/app/config.php
<?php return array (
'debug' => ${DEBUG:-false},
'offline' => false,
'database' => array (
'driver' => 'mysql',
'host' => '${MYSQL_HOST:-mysql}',
'port' => '${MYSQL_PORT:-3306}',
'database' => '${MYSQL_DATABASE:-flarum}',
'username' => '${MYSQL_USER:-flarum}',
'password' => '${MYSQL_PASSWORD:-flarum}',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
),
'url' => '${SITE_URL:-http://localhost}',
'paths' => array (
'api' => 'api',
'admin' => 'admin',
),
);
EOF
else
# Else build the config template and run the command line installer
cd /flarum
php make_config.php
cd /flarum/app
php flarum install -f /flarum/config.yaml
rm -f /flarum/config.yaml
touch /flarum/app/public/assets/.installed.lock
fi
# first arg is `-f` or `--some-option`
if [[ "${1#-}" != "$1" ]]; then
set -- apache2-foreground "$@"
fi
exec "$@"