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}
|
2018-06-22 02:58:40 -04:00
|
|
|
LOG_TO_STDOUT=${LOG_TO_STDOUT:-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
|
|
|
|
|
2018-01-14 05:31:43 -05:00
|
|
|
sed -i "s/<UPLOAD_MAX_SIZE>/$UPLOAD_MAX_SIZE/g" /etc/nginx/nginx.conf /etc/php7/php-fpm.conf
|
2018-02-17 04:21:10 -05:00
|
|
|
sed -i "s/<PHP_MEMORY_LIMIT>/$PHP_MEMORY_LIMIT/g" /etc/php7/php-fpm.conf
|
|
|
|
sed -i "s/<OPCACHE_MEMORY_LIMIT>/$OPCACHE_MEMORY_LIMIT/g" /etc/php7/conf.d/00_opcache.ini
|
2017-05-13 05:12:25 -04:00
|
|
|
|
2016-09-25 05:22:48 -04:00
|
|
|
# Set permissions
|
2018-08-25 02:21:39 -04:00
|
|
|
chown -R $UID:$GID /services /var/log /var/lib/nginx
|
2016-09-25 05:22:48 -04:00
|
|
|
|
2016-10-23 17:01:02 -04:00
|
|
|
cd /flarum/app
|
2016-07-17 05:35:13 -04:00
|
|
|
|
2018-06-22 02:58:40 -04:00
|
|
|
# Set log output to STDOUT if wanted (LOG_TO_STDOUT=true)
|
|
|
|
if [ "$LOG_TO_STDOUT" = true ]; then
|
|
|
|
echo "[INFO] Logging to stdout activated"
|
|
|
|
chmod o+w /dev/stdout
|
|
|
|
sed -i "s/.*error_log.*$/error_log \/dev\/stdout warn;/" /etc/nginx/nginx.conf
|
|
|
|
sed -i "s/.*error_log.*$/error_log = \/dev\/stdout/" /etc/php7/php-fpm.conf
|
|
|
|
fi
|
|
|
|
|
2018-01-14 05:31:43 -05:00
|
|
|
# Disable custom errors pages if debug mode is enabled
|
|
|
|
if [ "$DEBUG" = true ]; then
|
2018-06-22 02:58:40 -04:00
|
|
|
echo "[INFO] Debug mode enabled"
|
2018-01-14 05:31:43 -05:00
|
|
|
sed -i '/error_page/ s/^/#/' /etc/nginx/nginx.conf
|
|
|
|
fi
|
|
|
|
|
2016-11-06 03:01:52 -05:00
|
|
|
# Custom HTTP errors pages
|
2016-10-29 13:36:42 -04:00
|
|
|
if [ -d 'assets/errors' ]; then
|
2016-12-02 02:23:11 -05:00
|
|
|
echo "[INFO] Found custom errors pages"
|
2016-10-29 13:36:42 -04:00
|
|
|
rm -rf vendor/flarum/core/error/*
|
|
|
|
ln -s /flarum/app/assets/errors/* vendor/flarum/core/error
|
|
|
|
fi
|
|
|
|
|
2016-12-02 02:23:11 -05:00
|
|
|
# Custom repositories (eg. for privates extensions)
|
|
|
|
if [ -f 'extensions/composer.repositories.txt' ]; then
|
|
|
|
while read line; do
|
|
|
|
repository=$(echo $line | cut -d '|' -f1)
|
|
|
|
json=$(echo $line | cut -d '|' -f2)
|
|
|
|
echo "[INFO] Adding ${repository} composer repository"
|
|
|
|
composer config repositories.${repository} "${json}"
|
|
|
|
done < extensions/composer.repositories.txt
|
2016-11-06 03:01:52 -05:00
|
|
|
fi
|
|
|
|
|
2016-07-23 02:44:00 -04:00
|
|
|
# if no installation was performed before
|
2016-10-23 17:01:02 -04:00
|
|
|
if [ -e 'assets/rev-manifest.json' ]; then
|
2016-07-17 10:57:27 -04:00
|
|
|
|
2016-07-23 02:44:00 -04:00
|
|
|
echo "[INFO] Flarum already installed, init app..."
|
|
|
|
|
2016-10-23 17:01:02 -04:00
|
|
|
sed -i -e "s|<DEBUG>|${DEBUG}|g" \
|
|
|
|
-e "s|<DB_HOST>|${DB_HOST}|g" \
|
|
|
|
-e "s|<DB_NAME>|${DB_NAME}|g" \
|
|
|
|
-e "s|<DB_USER>|${DB_USER}|g" \
|
|
|
|
-e "s|<DB_PASS>|${DB_PASS}|g" \
|
|
|
|
-e "s|<DB_PREF>|${DB_PREF}|g" \
|
|
|
|
-e "s|<FORUM_URL>|${FORUM_URL}|g" config.php
|
|
|
|
|
|
|
|
su-exec $UID:$GID php flarum cache:clear
|
2016-07-23 02:44:00 -04:00
|
|
|
|
2016-07-23 11:46:59 -04:00
|
|
|
# Composer cache dir and packages list paths
|
2016-12-02 02:23:11 -05:00
|
|
|
CACHE_DIR=extensions/.cache
|
|
|
|
LIST_FILE=extensions/list
|
2016-07-23 11:46:59 -04:00
|
|
|
|
|
|
|
# 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"
|
2016-07-23 11:46:59 -04:00
|
|
|
done < "$LIST_FILE"
|
|
|
|
echo "[INFO] Install extra bundled extensions. DONE."
|
2016-10-23 17:01:02 -04:00
|
|
|
else
|
|
|
|
echo "[INFO] No installed extensions"
|
2016-07-23 11:46:59 -04:00
|
|
|
fi
|
|
|
|
|
2016-07-23 02:44:00 -04:00
|
|
|
echo "[INFO] Init done, launch flarum..."
|
|
|
|
|
2016-10-23 17:01:02 -04:00
|
|
|
else
|
2016-07-17 05:35:13 -04:00
|
|
|
|
2016-10-23 17:01:02 -04:00
|
|
|
echo "[INFO] First launch, you must install flarum by opening your browser and setting database parameters."
|
2016-10-23 17:18:57 -04:00
|
|
|
rm -rf config.php
|
2016-08-08 02:09:01 -04:00
|
|
|
|
2016-10-23 17:01:02 -04:00
|
|
|
fi
|
2016-07-17 05:35:13 -04:00
|
|
|
|
2016-07-28 02:09:26 -04:00
|
|
|
# Set permissions
|
2018-08-25 02:21:39 -04:00
|
|
|
find /flarum ! -user $UID -print0 | xargs -0 -r chown $UID:$GID
|
|
|
|
find /flarum ! -group $GID -print0 | xargs -0 -r chown $UID:$GID
|
2016-07-28 02:09:26 -04:00
|
|
|
|
2016-07-17 05:35:13 -04:00
|
|
|
# RUN !
|
2018-01-14 05:31:43 -05:00
|
|
|
exec su-exec $UID:$GID /bin/s6-svscan /services
|