flarum-docker/docker/docker-entrypoint.sh

80 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
set -e
# Wait for MySQL/MariaDB
echo "Waiting for MySQL/MariaDB..."
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
# Change into the flarum directory so that we can do a number of tasks
cd /flarum/app
echo "Installing extensions..."
if [[ "$EXTENSIONS" != "" ]]; then
# install extensions
for EXT in $EXTENSIONS; do
composer require $EXT:"*"
done
fi
# Always run migrate and clear the cache
echo "Running any pending migrations and clearing the cache..."
php flarum migrate
if [[ -d "/flarum/app/storage/cache" ]]; then
php flarum cache:clear
fi
chown www-data:www-data -R /flarum/*
# first arg is `-f` or `--some-option`
if [[ "${1#-}" != "$1" ]]; then
set -- apache2-foreground "$@"
fi
exec "$@"