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

mkdir /tmp/mw-install
echo "CREATE USER 'wikidebadmin'@'localhost' IDENTIFIED BY 'password1';" > /tmp/mw-install/db_setup.sql
echo "GRANT ALL PRIVILEGES ON * . * TO 'wikidebadmin'@'localhost';" >> /tmp/mw-install/db_setup.sql
sudo mysql < /tmp/mw-install/db_setup.sql
rm /tmp/mw-install/db_setup.sql
php /var/lib/mediawiki/maintenance/install.php --confpath /tmp/mw-install --dbname autopkgtestwiki --dbtype mysql --dbuser wikidebadmin --dbpass password1 --pass password1 Debian-Autopkgtest Administrator
php /var/lib/mediawiki/maintenance/getText.php --conf /tmp/mw-install/LocalSettings.php "Main_Page" | grep "MediaWiki has been installed"
php /var/lib/mediawiki/maintenance/update.php --conf /tmp/mw-install/LocalSettings.php --quick
sudo cp /tmp/mw-install/LocalSettings.php /etc/mediawiki/LocalSettings.php
curl -I --silent "http://localhost/mediawiki/index.php/Main_Page"
curl --silent "http://localhost/mediawiki/index.php/Main_Page" | grep "MediaWiki has been installed"
curl --silent "http://localhost/mediawiki/index.php/Special:BlankPage" | grep "This page is intentionally left blank."

