2020-09-07 19:09:46 +00:00
#!/bin/bash
set -eu -o pipefail
2020-10-15 16:11:54 +00:00
init_php() {
2020-10-15 16:03:02 +00:00
if ! type composer > /dev/null 2>&1; then
2020-10-15 16:24:09 +00:00
apt update && apt install -y curl git
2020-10-15 16:03:02 +00:00
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.10.15
2020-10-15 14:26:32 +00:00
composer -V
2020-09-16 20:19:23 +00:00
fi
2020-10-15 16:11:54 +00:00
}
init_db() {
set -eu
if ! type mysql > /dev/null 2>&1; then
apt update && apt install -y mariadb-client
fi
2020-09-07 21:04:41 +00:00
2020-10-05 23:32:46 +00:00
PASSWORD=$(cat /run/secrets/db_password)
TABLE_COUNT=$(mysql -u " ${ DB_USER } " --password=" $ PASSWORD " -h " ${ DB_HOST } " " ${ DB_NAME } " -e "SELECT count(*) AS TOTAL FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'mediawiki';" -N -B)
2020-09-07 21:04:41 +00:00
2020-09-16 20:19:23 +00:00
if [[ " ${ TABLE_COUNT } " == "0" ]]; then
2020-10-05 23:32:46 +00:00
mysql -u " ${ DB_USER } " --password=" $ PASSWORD " -h " ${ DB_HOST } " " ${ DB_NAME } " < /var/www/html/maintenance/tables.sql
2020-09-16 20:19:23 +00:00
else
php /var/www/html/maintenance/update.php
fi
}
install_extensions() {
if [ ! -d /var/www/html/extensions/PluggableAuth ]; then
git clone --depth 1 -b REL1_32 \
https://gerrit.wikimedia.org/r/p/mediawiki/extensions/PluggableAuth \
/var/www/html/extensions/PluggableAuth
fi
2020-10-15 16:23:45 +00:00
if [ -n " $ SAML_ENABLED " ]; then
if [ ! -d /var/www/html/extensions/SimpleSAMLphp ]; then
git clone --depth 1 -b REL1_32 \
https://gerrit.wikimedia.org/r/p/mediawiki/extensions/SimpleSAMLphp \
/var/www/html/extensions/SimpleSAMLphp
fi
fi
if [ -n " $ OPENID_ENABLED " ]; then
if [ ! -d /var/www/html/extensions/OpenIDConnect]; then
git clone --depth 1 -b REL1_35 \
https://gerrit.wikimedia.org/r/admin/repos/mediawiki/extensions/OpenIDConnect
/var/www/html/extensions/OpenIDConnect
fi
2020-09-16 20:19:23 +00:00
fi
2020-09-07 19:09:46 +00:00
}
main() {
2020-09-16 20:19:23 +00:00
set -eu
a2enmod rewrite
2020-09-07 19:09:46 +00:00
2020-09-16 20:19:23 +00:00
install_extensions
2020-09-08 00:09:52 +00:00
2020-09-16 20:19:23 +00:00
init_db
2020-10-15 16:11:54 +00:00
init_php
2020-09-07 19:09:46 +00:00
}
main
2020-09-07 21:04:41 +00:00
/docker-entrypoint.sh apache2-foreground "$@"