docker-flarum/run.sh

127 lines
3.8 KiB
Bash
Raw Normal View History

2016-07-17 05:35:13 -04:00
#!/bin/sh
2016-07-18 01:34:39 -04:00
# Env variables
export DB_HOST
export DB_USER
export DB_NAME
2016-08-08 02:09:01 -04:00
export DEBUG
2016-07-18 01:34:39 -04:00
# Default values
DB_HOST=${DB_HOST:-mariadb}
DB_USER=${DB_USER:-flarum}
DB_NAME=${DB_NAME:-flarum}
2016-08-08 02:09:01 -04:00
DEBUG=${DEBUG:-false}
2016-07-18 01:34:39 -04:00
# Required env variables
2016-07-17 05:35:13 -04:00
if [ -z "$DB_PASS" ]; then
echo "[ERROR] Mariadb database password must be set !"
exit 1
fi
if [ -z "$FORUM_URL" ]; then
echo "[ERROR] Forum url must be set !"
exit 1
fi
2016-09-25 05:22:48 -04:00
# Set permissions
chown -R $UID:$GID /flarum /etc/nginx /etc/php7 /var/log /var/lib/nginx /tmp /etc/s6.d
2016-07-17 09:55:22 -04:00
cd /flarum/app/
# Installation settings
2016-07-17 09:55:22 -04:00
cat > config.yml <<EOF
2016-07-17 05:35:13 -04:00
databaseConfiguration:
driver: mysql
host: ${DB_HOST}
database: ${DB_NAME}
username: ${DB_USER}
password: ${DB_PASS}
baseUrl: ${FORUM_URL}
EOF
2016-07-17 10:57:27 -04:00
# Installer problem, wait fix in beta 6
2016-07-17 05:35:13 -04:00
# PHP Fatal error: Uncaught ReflectionException: Class flarum.config does not
# exist in /flarum/vendor/illuminate/container/Container.php
# https://github.com/flarum/core/commit/7192c4391bee006ccc2de3db6caa89803d72d130
sed -i -e 's|InfoCommand::class,||g' \
2016-07-17 09:55:22 -04:00
-e "s|\['config' => \$app->make('flarum.config')\]|['config' => \$app->isInstalled() ? \$app->make('flarum.config') : []]|g" vendor/flarum/core/src/Console/Server.php
2016-07-17 05:35:13 -04:00
# if no installation was performed before
if [ ! -e 'assets/rev-manifest.json' ]; then
2016-07-17 05:35:13 -04:00
2016-09-25 05:22:48 -04:00
echo "[INFO] First launch, installing flarum..."
# Mail settings
2016-08-03 15:52:59 -04:00
sed -i -e "s|{{ DB_NAME }}|${DB_NAME}|g" \
-e "s|{{ MAIL_FROM }}|${MAIL_FROM}|g" \
-e "s|{{ MAIL_HOST }}|${MAIL_HOST}|g" \
-e "s|{{ MAIL_PORT }}|${MAIL_PORT}|g" \
-e "s|{{ MAIL_USER }}|${MAIL_USER}|g" \
-e "s|{{ MAIL_PASS }}|${MAIL_PASS}|g" \
-e "s|{{ MAIL_ENCR }}|${MAIL_ENCR}|g" config.sql
2016-07-17 05:35:13 -04:00
# Install flarum
2016-09-25 05:22:48 -04:00
su-exec $UID:$GID php flarum install --file config.yml
2016-07-17 10:57:27 -04:00
# Define flarum settings in database
mysql -h"${DB_HOST}" -u"${DB_USER}" -p"${DB_PASS}" "${DB_NAME}" < config.sql
2016-07-17 10:57:27 -04:00
2016-09-25 05:22:48 -04:00
echo "[INFO] Installation done, launch flarum..."
2016-07-17 05:35:13 -04:00
else
2016-07-17 10:57:27 -04:00
echo "[INFO] Flarum already installed, init app..."
# Disable already done steps during installation
# ----------------------------------------------
#
# See : flarum/core/src/Install/Console/DefaultsDataProvider.php
# flarum/core/src/Install/Console/InstallCommand.php
#
# runMigrations() = Database migration (Flarum\Database\Migrator)
# writeSettings() = Writing default flarum settings (Flarum\Settings\SettingsRepositoryInterface)
# seedGroups() = Create default groups
# seedPermissions() = Create default permissions
# createAdminUser() = Create default admin user
sed -i -e '/$this->runMigrations();/ s/^/#/' \
-e '/$this->writeSettings();/ s/^/#/' \
-e '/$this->seedGroups();/ s/^/#/' \
-e '/$this->seedPermissions();/ s/^/#/' \
-e '/$this->createAdminUser();/ s/^/#/' vendor/flarum/core/src/Install/Console/InstallCommand.php
# Init flarum (without steps above)
2016-09-25 05:22:48 -04:00
su-exec $UID:$GID php flarum install --file config.yml
# Composer cache dir and packages list paths
CACHE_DIR=/flarum/app/assets/.extensions
LIST_FILE=assets/.extensions/list
# Download extra extensions installed with composer wrapup script
if [ -s "$LIST_FILE" ]; then
echo "[INFO] Install extra bundled extensions"
while read extension; do
echo "[INFO] -------------- Install extension : ${extension} --------------"
2016-09-25 05:22:48 -04:00
COMPOSER_CACHE_DIR="$CACHE_DIR" su-exec $UID:$GID composer require "$extension"
done < "$LIST_FILE"
echo "[INFO] Install extra bundled extensions. DONE."
fi
echo "[INFO] Init done, launch flarum..."
2016-07-17 05:35:13 -04:00
fi
2016-08-08 02:09:01 -04:00
# Set flarum debug mode
if [ -f "config.php" ]; then
sed -i "s|\('debug' =>\) .*|\1 ${DEBUG},|" config.php
fi
# Removing installation files
rm -f config.sql config.yml
2016-07-17 05:35:13 -04:00
# Set permissions
2016-09-25 05:22:48 -04:00
chown -R $UID:$GID /flarum
2016-07-17 05:35:13 -04:00
# RUN !
2016-09-25 05:22:48 -04:00
exec su-exec $UID:$GID /bin/s6-svscan /etc/s6.d