2019-11-26 21:42:51 -05:00
|
|
|
#!/usr/bin/env sh
|
2016-07-17 05:35:13 -04:00
|
|
|
|
2016-07-18 01:34:39 -04:00
|
|
|
# Required env variables
|
2018-12-26 12:26:51 -05:00
|
|
|
if [ -z "${DB_PASS}" ]; then
|
2016-07-17 05:35:13 -04:00
|
|
|
echo "[ERROR] Mariadb database password must be set !"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-12-26 12:26:51 -05:00
|
|
|
if [ -z "${FORUM_URL}" ]; then
|
2016-07-17 05:35:13 -04:00
|
|
|
echo "[ERROR] Forum url must be set !"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-11-20 12:02:41 -05:00
|
|
|
CACHE_DIR=/flarum/app/extensions/.cache
|
|
|
|
LIST_FILE=/flarum/app/extensions/list
|
|
|
|
|
2018-11-29 22:00:50 -05:00
|
|
|
# Set file config for nginx and php
|
2020-02-09 13:55:56 -05:00
|
|
|
sed -i "s/<FLARUM_PORT>/${FLARUM_PORT}/g" /etc/nginx/nginx.conf
|
2021-03-16 13:20:57 -04:00
|
|
|
sed -i "s/<UPLOAD_MAX_SIZE>/${UPLOAD_MAX_SIZE}/g" /etc/nginx/nginx.conf /etc/php8/php-fpm.d/www.conf
|
|
|
|
sed -i "s/<PHP_MEMORY_LIMIT>/${PHP_MEMORY_LIMIT}/g" /etc/php8/php-fpm.d/www.conf
|
|
|
|
sed -i "s/<OPCACHE_MEMORY_LIMIT>/${OPCACHE_MEMORY_LIMIT}/g" /etc/php8/conf.d/00_opcache.ini
|
2017-05-13 05:12:25 -04:00
|
|
|
|
2020-11-19 12:13:36 -05:00
|
|
|
# Set permissions for /flarum folder
|
|
|
|
echo "[INFO] Setting folder permissions"
|
2021-03-16 16:51:47 -04:00
|
|
|
for folder in /etc/s6.d /run/php /var/log /var/lib/nginx; do
|
2020-11-19 12:13:36 -05:00
|
|
|
find ${folder} ! -user "${UID}" -exec chown -h "${UID}:${GID}" {} \+
|
|
|
|
find ${folder} ! -group "${GID}" -exec chown -h "${UID}:${GID}" {} \+
|
2019-12-28 17:47:12 -05:00
|
|
|
done
|
2016-09-25 05:22:48 -04:00
|
|
|
|
2020-11-19 12:13:36 -05:00
|
|
|
find /flarum ! -user "${UID}" -exec chown "${UID}:${GID}" {} \+
|
|
|
|
find /flarum ! -group "${GID}" -exec chown "${UID}:${GID}" {} \+
|
|
|
|
|
2018-06-22 02:58:40 -04:00
|
|
|
# Set log output to STDOUT if wanted (LOG_TO_STDOUT=true)
|
2018-12-26 12:26:51 -05:00
|
|
|
if [ "${LOG_TO_STDOUT}" = true ]; then
|
2018-06-22 02:58:40 -04:00
|
|
|
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
|
2021-03-16 13:20:57 -04:00
|
|
|
sed -i "s/.*error_log.*$/error_log = \/dev\/stdout/" /etc/php8/php-fpm.d/www.conf
|
2018-06-22 02:58:40 -04:00
|
|
|
fi
|
|
|
|
|
2020-06-02 12:12:38 -04:00
|
|
|
# Install additional php extensions
|
|
|
|
if [ -n "${PHP_EXTENSIONS}" ]; then
|
2020-06-04 20:55:38 -04:00
|
|
|
for php_extension in ${PHP_EXTENSIONS}; do
|
2021-03-16 13:20:57 -04:00
|
|
|
PACKAGES="php8-${php_extension} ${PACKAGES}"
|
2020-06-02 12:12:38 -04:00
|
|
|
done
|
2020-11-19 12:13:36 -05:00
|
|
|
echo "[INFO] Adding php extensions"
|
2020-11-20 12:08:34 -05:00
|
|
|
apk add --no-progress --no-cache ${PACKAGES}
|
2020-06-02 12:12:38 -04:00
|
|
|
fi
|
|
|
|
|
2018-11-29 23:24:19 -05:00
|
|
|
cd /flarum/app
|
|
|
|
|
2020-11-19 12:13:36 -05:00
|
|
|
# Add github token authentication (eg. for privates extensions)
|
2019-10-10 08:24:53 -04:00
|
|
|
if [ "${GITHUB_TOKEN_AUTH}" != false ]; then
|
|
|
|
echo "[INFO] Adding github token authentication"
|
2020-11-20 12:02:41 -05:00
|
|
|
COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" composer config github-oauth.github.com "${GITHUB_TOKEN_AUTH}"
|
2018-12-26 12:26:51 -05:00
|
|
|
fi
|
|
|
|
|
2016-12-02 02:23:11 -05:00
|
|
|
# Custom repositories (eg. for privates extensions)
|
2018-11-29 22:00:50 -05:00
|
|
|
if [ -f '/flarum/app/extensions/composer.repositories.txt' ]; then
|
2016-12-02 02:23:11 -05:00
|
|
|
while read line; do
|
2019-12-28 16:24:02 -05:00
|
|
|
repository="$(echo ${line} | cut -d '|' -f1)"
|
|
|
|
json="$(echo ${line} | cut -d '|' -f2)"
|
2016-12-02 02:23:11 -05:00
|
|
|
echo "[INFO] Adding ${repository} composer repository"
|
2020-11-20 12:02:41 -05:00
|
|
|
COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" composer config repositories."${repository}" --json "${json}"
|
2018-11-29 22:47:57 -05:00
|
|
|
done < /flarum/app/extensions/composer.repositories.txt
|
2016-11-06 03:01:52 -05:00
|
|
|
fi
|
|
|
|
|
2018-11-05 12:53:30 -05:00
|
|
|
# Custom vhost flarum nginx
|
2021-02-04 19:35:29 -05:00
|
|
|
if [ ! -e '/etc/nginx/flarum/custom-vhost-flarum.conf' ]; then
|
2018-11-05 12:53:30 -05:00
|
|
|
echo '# Example:
|
|
|
|
# fix for flagrow/sitemap (https://github.com/flagrow/sitemap)
|
|
|
|
# location = /sitemap.xml {
|
|
|
|
# try_files $uri $uri/ /index.php?$query_string;
|
2021-02-04 19:35:29 -05:00
|
|
|
# }' > /etc/nginx/flarum/custom-vhost-flarum.conf
|
2018-11-05 12:53:30 -05:00
|
|
|
fi
|
|
|
|
|
2019-11-26 21:42:51 -05:00
|
|
|
# if installation was performed before
|
2021-05-30 17:17:20 -04:00
|
|
|
if [ -e '/flarum/app/public/assets/rev-manifest.json' ] || [ -e '/flarum/app/public/assets/._flarum-installed.lock' ] ; then
|
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" \
|
2021-03-03 14:31:28 -05:00
|
|
|
-e "s|<DB_PORT>|${DB_PORT}|g" \
|
2019-11-26 21:42:51 -05:00
|
|
|
-e "s|<FORUM_URL>|${FORUM_URL}|g" /flarum/app/config.php.sample
|
2016-10-23 17:01:02 -04:00
|
|
|
|
2020-11-19 12:13:36 -05:00
|
|
|
cp -p /flarum/app/config.php.sample /flarum/app/config.php
|
2019-12-28 16:24:02 -05:00
|
|
|
su-exec "${UID}:${GID}" php /flarum/app/flarum cache:clear
|
2016-07-23 02:44:00 -04:00
|
|
|
|
2016-07-23 11:46:59 -04:00
|
|
|
# Download extra extensions installed with composer wrapup script
|
2018-12-26 12:26:51 -05:00
|
|
|
if [ -s "${LIST_FILE}" ]; then
|
2016-07-23 11:46:59 -04:00
|
|
|
echo "[INFO] Install extra bundled extensions"
|
2018-12-02 09:25:13 -05:00
|
|
|
while read line; do
|
2018-12-26 16:54:01 -05:00
|
|
|
extension="${extension}${line} "
|
2018-12-02 10:47:40 -05:00
|
|
|
done < /flarum/app/extensions/list
|
2021-03-16 16:38:23 -04:00
|
|
|
cmd="composer require --update-with-all-dependencies ${extension}"
|
2020-11-20 12:02:41 -05:00
|
|
|
eval "COMPOSER_CACHE_DIR=${CACHE_DIR} su-exec ${UID}:${GID} ${cmd}"
|
|
|
|
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
|
|
|
|
|
2020-11-20 12:02:41 -05:00
|
|
|
echo "[INFO] Flarum already installed, init app: DONE"
|
2016-10-23 17:01:02 -04:00
|
|
|
else
|
2019-11-26 21:42:51 -05:00
|
|
|
# if no installation was performed before
|
2018-11-29 22:00:50 -05:00
|
|
|
echo "[INFO] First launch, installation..."
|
2016-07-17 05:35:13 -04:00
|
|
|
|
2018-12-26 12:26:51 -05:00
|
|
|
if [ -z "${FLARUM_ADMIN_USER}" ] || [ -z "${FLARUM_ADMIN_PASS}" ] || [ -z "${FLARUM_ADMIN_MAIL}" ]; then
|
2018-11-29 22:00:50 -05:00
|
|
|
echo "[ERROR] User admin info of flarum must be set !"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed -i -e "s|<DEBUG>|${DEBUG}|g" \
|
|
|
|
-e "s|<FORUM_URL>|${FORUM_URL}|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|<DB_PORT>|${DB_PORT}|g" \
|
|
|
|
-e "s|<FLARUM_ADMIN_USER>|${FLARUM_ADMIN_USER}|g" \
|
|
|
|
-e "s|<FLARUM_ADMIN_PASS>|${FLARUM_ADMIN_PASS}|g" \
|
|
|
|
-e "s|<FLARUM_ADMIN_MAIL>|${FLARUM_ADMIN_MAIL}|g" \
|
|
|
|
-e "s|<FLARUM_TITLE>|${FLARUM_TITLE}|g" /flarum/app/config.yml
|
2016-08-08 02:09:01 -04:00
|
|
|
|
2018-11-30 04:26:05 -05:00
|
|
|
# Install flarum
|
2021-05-30 17:17:20 -04:00
|
|
|
su-exec "${UID}:${GID}" php /flarum/app/flarum install --file=/flarum/app/config.yml &&
|
|
|
|
touch /flarum/app/public/assets/._flarum-installed.lock
|
2018-11-29 22:00:50 -05:00
|
|
|
echo "[INFO] End of flarum installation"
|
2016-10-23 17:01:02 -04:00
|
|
|
fi
|
2016-07-17 05:35:13 -04:00
|
|
|
|
2020-11-20 12:02:41 -05:00
|
|
|
echo "[INFO] End of startup script. Forum is starting."
|
2021-03-16 16:17:16 -04:00
|
|
|
exec su-exec "${UID}:${GID}" /bin/s6-svscan /etc/s6.d
|