#!/bin/sh

dbadapter="${1:-sqlite3}"
setup="${2:-thin-redmine}"
uri="${3:-/}"

exec 2>&1
set -eux

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

cp /usr/share/doc/redmine/examples/${setup}.yml /etc/thin3.1/redmine.yml

service thin restart

# retry is needed because Thin takes time to startup
curl --retry-connrefused --retry 10 -s http://localhost:3000${uri} | grep 'meta.*name="description".*content="Redmine"'
curl -s http://localhost:3000${uri}/login | grep 'meta.*name="description".*content="Redmine"'
