#!/bin/bash set -eu -o pipefail init_composer() { set -eu if ! type composer > /dev/null 2>&1; then apt update -yqq && apt install -yqq curl git unzip zip curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=2.5.4 composer -V fi } composer_install() { set -eu cd /var/www/html/ && composer update && composer install } init_db() { set -eu if ! type mysql > /dev/null 2>&1; then apt update -qq && apt install -yqq mariadb-client fi PASSWORD=$(cat /run/secrets/db_password) # FIXME 3wc: replace with sql.php, not sure how to parse output: # stdClass Object #( # [TOTAL] => 58 #) 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) if [[ "${TABLE_COUNT}" == "0" ]]; then php /var/www/html/maintenance/generateSchemaSql.php php /var/www/html/maintenance/sql.php /var/www/html/maintenance/tables-generated.sql php /var/www/html/maintenance/sql.php /var/www/html/maintenance/tables.sql php /var/www/html/maintenance/sql.php /var/www/html/maintenance/interwiki.sql # FIXME run createAndPromote.php with $ADMIN_USERNAME fi php /var/www/html/maintenance/update.php --quick } init_extensions() { if [ ! -d /var/www/html/extensions/PluggableAuth ]; then git clone --depth 1 -b REL1_39 \ https://gerrit.wikimedia.org/r/p/mediawiki/extensions/PluggableAuth \ /var/www/html/extensions/PluggableAuth fi if [ -n "${SAML_ENABLED-}" ]; then if [ ! -d /var/www/html/extensions/SimpleSAMLphp ]; then git clone --depth 1 -b REL1_39 \ 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_39 \ https://gerrit.wikimedia.org/r/mediawiki/extensions/OpenIDConnect \ /var/www/html/extensions/OpenIDConnect fi fi if [ -n "${MOBILEFRONTEND_ENABLED-}" ]; then if [ ! -d /var/www/html/extensions/MobileFrontend ]; then git clone --depth 1 -b REL1_39 \ https://github.com/wikimedia/mediawiki-extensions-MobileFrontend.git \ /var/www/html/extensions/MobileFrontend fi fi if [ -n "${MSU_ENABLED-}" ]; then if [ ! -d /var/www/html/extensions/MsUpload ]; then git clone --depth 1 -b REL1_39 \ https://gerrit.wikimedia.org/r/mediawiki/extensions/MsUpload \ /var/www/html/extensions/MsUpload fi fi if [ -n "${PAGEFORMS_ENABLED-}" ]; then if [ ! -d /var/www/html/extensions/PageForms ]; then git clone --depth 1 -b REL1_39 \ https://gerrit.wikimedia.org/r/mediawiki/extensions/PageForms \ /var/www/html/extensions/PageForms fi fi if [ -n "${PAGESCHEMAS_ENABLED-}" ]; then if [ ! -d /var/www/html/extensions/PageSchemas ]; then git clone --depth 1 -b REL1_39 \ https://gerrit.wikimedia.org/r/mediawiki/extensions/PageSchemas \ /var/www/html/extensions/PageSchemas fi fi if [ -n "${MARKDOWN_ENABLED-}" ]; then if [ ! -d /var/www/html/extensions/WikiMarkdown ]; then git clone --depth 1 \ https://github.com/kuenzign/WikiMarkdown \ /var/www/html/extensions/WikiMarkdown fi fi } init_skins() { if [ -n "${TWEEKI_ENABLED-}" ]; then if [ ! -d /var/www/html/skins/Tweeki ]; then git clone --depth 1 \ https://github.com/thaider/Tweeki \ /var/www/html/skins/Tweeki fi fi } main() { set -eu init_extensions init_skins init_composer composer_install init_db } main apache2-foreground