#!/bin/sh
# Install MediaWiki on the SQLite backend
# and then verify the installation was successful.
# We use /etc instead of /tmp for the data directory
# since apache has a private tmp directory.
set -e

sudo mkdir /etc/mw-install
sudo chgrp www-data /etc/mw-install
sudo chmod g+w /etc/mw-install
sudo -u www-data php /var/lib/mediawiki/maintenance/install.php --scriptpath /mediawiki --confpath /etc/mw-install --dbpath /etc/mw-install --dbtype sqlite --pass DebianIsTheBest Debian-Autopkgtest Administrator
sudo cat >> /etc/mw-install/LocalSettings.php <<EOF
\$wgShowExceptionDetails = true;
\$wgShowDBErrorBacktrace = true;
ini_set( 'max_execution_time', 300 );
EOF
sudo mv /etc/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

