#!/bin/sh

dbadapter="${1:-sqlite3}"
setup="${2:-lighttpd-host}"
uri="${3:-/}"

exec 2>&1
set -eux

grep "adapter:[[:space:]]*$dbadapter" /etc/redmine/default/database.yml

cp /usr/share/doc/redmine/examples/${setup}.conf /etc/lighttpd/conf-enabled/redmine.conf

lighty-enable-mod fastcgi

# restart does not work well: the service is marked as stopped but the process is still there
# it happpened in the autopkgtest on Salsa but I could not reproduce it on a bare metal system
service lighttpd reload

# lighttpd redirects (301) /redmine to /redmine/ and the test breaks
# thus adding a final / here to not change the semantic in the control file
curl -s http://localhost${uri}/ | grep 'meta.*name="description".*content="Redmine"'
curl -s http://localhost${uri}/login/ | grep 'meta.*name="description".*content="Redmine"'
