#!/bin/sh
#
# Copyright (C) 2007 Loic Dachary <loic@dachary.org>
# Copyright (C) 2005, 2006 Mekensleep
#
# Mekensleep
# 24 rue vieille du temple
# 75004 Paris
#       licensing@mekensleep.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Authors:
#  Loic Dachary <loic@gnu.org>
#
set -e

WWW=/home/www
COOKIES=$0.cookies
rm -f ${COOKIES}
#DUMP_HEADERS='--dump-header /dev/tty'
touch run-pokerserver.launching
DONT_RUN_BOTS=1 bash -x run-pokerserver &
pokerserver_pid=$!
trap "kill $pokerserver_pid ; rm -f $0.{cookies,out}" EXIT INT QUIT
lockfile run-pokerserver.launching
rm -f run-pokerserver.launching

if [ "$(chase ${WWW}/test-poker-web)" != "$(chase ../pokerweb/pages)" ] ; then
    rm -f ${WWW}/test-poker-web
    ln -s $(chase ../pokerweb/pages) ${WWW}/test-poker-web
fi

rm -f ../pokerweb/pages/constants.php
sed -e 's/@POKER_SERVER_HOST@:19382/localhost:19482/' \
    -e "s|one_private.*|one_private', 'http://localhost/test-poker-web/currency_one.php');|" \
    -e "s|one_public.*|one_public', 'http://localhost/test-poker-web/currency_one.php');|" \
    < ../pokerweb/pages/constants.php.ref.in > ../pokerweb/pages/constants.php
perl -pi -e "s/currency_db_user'] = '.*/currency_db_user'] = 'root';/" ../pokerweb/pages/currency_one.php
perl -pi -e "s/currency_db_password'] = '.*/currency_db_password'] = '';/" ../pokerweb/pages/currency_one.php
if ! grep currency_id ../pokerweb/pages/currency_one.php ; then
    echo "$GLOBALS['currency_id'] = TRUE;" >> ../pokerweb/pages/currency_one.php
fi

echo "Now run http://localhost/test-poker-web/selenium-core-0.8.1/core/TestRunner.html?test=../../tests/TestSuite.html"
wait
#. ../tests/pokerweb
