#!/bin/sh
# Install MediaWiki on the PostgreSQL backend
# and then verify the installation was successful.
set -e

mkdir /tmp/mw-install
sudo -u postgres createuser --createdb -e wikidebadmin
sudo -u postgres psql -c "ALTER USER wikidebadmin WITH PASSWORD 'DebianIsTheBest';"
php /var/lib/mediawiki/maintenance/install.php --scriptpath /mediawiki --confpath /tmp/mw-install --dbname autopkgtestwiki --dbtype postgres --dbserver localhost --dbuser wikidebadmin --dbpass DebianIsTheBest --pass DebianIsTheBest Debian-Autopkgtest Administrator
echo '$wgShowExceptionDetails = true; $wgShowDBErrorBacktrace = true;' >> /tmp/mw-install/LocalSettings.php
sudo mv /tmp/mw-install/LocalSettings.php /etc/mediawiki/LocalSettings.php

if [ -f ./debian/tests/install-thing ]; then
    ./debian/tests/install-thing
fi

# Force clearing of PHP caches, etc.
sudo systemctl restart apache2

# Run tests
./debian/tests/assert-cli
./debian/tests/assert-http
if [ -f ./debian/tests/assert-thing ]; then
    ./debian/tests/assert-thing
fi

