-#!/bin/sh -x
-
-export CURDIR=`pwd`
-export WORKSPACE=${WORKSPACE:-$CURDIR}
-
-export CONFIG_PHP=func/config.php.buildbot
-export SELENIUM_RC_HOST=192.168.0.204
-export SELENIUM_RC_DIR=$WORKSPACE/reports
-if [ "x${HUDSON_URL}" = "x" ]
-then
- . tests/openvz/config.default
- if [ -f tests/openvz/config.`hostname` ] ; then . tests/openvz/config.`hostname`; fi
- export VEID=$VEIDDEB
- export IPBASE=$IPDEBBASE
- export IPDNS=$IPDEBDNS
- ARCH=`dpkg-architecture -qDEB_BUILD_ARCH`
- export VZTEMPLATE=debian-$DEBVERS-$ARCH-minimal
- export VZPRIVATEDIR
- export SELENIUM_RC_URL=http://`hostname -f`/ws/reports
- export FFORGE_RPM_REPO=http://`hostname -f`/ws/build/packages
- export HOST=debian6.local
- export SELENIUM_RC_HOST=localhost
+#!/bin/sh +x
+. tests/scripts/common-functions
+. tests/scripts/common-vm
+
+export FORGE_HOME=/usr/share/gforge
+export DIST=wheezy
+export HOST=$1
+
+prepare_workspace
+destroy_vm -t debian7 $HOST
+# start_vm_if_not_keeped -t debian7 $HOST
+
+CHECKOUTPATH=$(pwd)
+
+set -e
+set -x
+
+COWBUILDERBASE=/var/lib/jenkins/builder/
+COWBUILDERCOW=$COWBUILDERBASE/cow/base-$DIST-amd64.cow
+COWBUILDERCONFIG=$COWBUILDERBASE/config/$DIST.config
+
+sudo cowbuilder --update --basepath $COWBUILDERCOW --buildplace=$COWBUILDERBASE
+cat > $COWBUILDERCONFIG <<EOF
+PDEBUILD_PBUILDER=cowbuilder
+BASEPATH=$COWBUILDERBASE
+BUILDPLACE=$COWBUILDERBASE
+APTCACHEHARDLINK="no"
+APTCACHE="/var/cache/pbuilder/aptcache"
+PBUILDERROOTCMD="sudo HOME=${HOME}"
+BUILDRESULT=$BUILDRESULT
+EOF
+
+cd $CHECKOUTPATH/src
+pdebuild --configfile $COWBUILDERCONFIG
+
+PKGNAME=$(dpkg-parsechangelog | awk '/^Source:/ { print $2 }')
+PKGVERS=$(dpkg-parsechangelog | awk '/^Version:/ { print $2 }')
+MAJOR=$(echo $PKGVERS | sed 's,([^-]+).*,\1,')
+SMAJOR=$(echo $(MAJOR) | sed 's/^.://')
+if [ -d $CHECKOUTPATH/.svn ] ; then
+ MINOR=svn$(svn info | awk '/^Revision:/ { print $2 }')
+elif [ -d $CHECKOUTPATH/.bzr ] ; then
+ MINOR=bzr$(bzr revno)
+elif [ -d $CHECKOUTPATH/.git ] ; then
+ MINOR=git$(git describe --always)
else
- export SELENIUM_RC_URL=${HUDSON_URL}job/$JOB_NAME/ws/reports
- export FFORGE_RPM_REPO=${HUDSON_URL}job/$JOB_NAME/ws/build/packages
- export HOST=debian6.local
+ MINOR=-1
fi
-export DB_NAME=gforge
-export CONFIGURED=true
+ARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
+CHANGEFILE=$(PKGNAME)_$(SMAJOR)$(MINOR)_$(ARCH).changes
+
+cd $BUILDRESULT
+reprepro -Vb include $DIST $CHANGEFILE
+
+set +x
+exit 1
+
+# Build 3rd-party
+make -C 3rd-party -f Makefile.deb BUILDRESULT=$BUILDRESULT LOCALREPODEB=$WORKSPACE/build/debian BUILDDIST=$DIST DEBMIRROR=$DEBMIRROR botclean botbuild
+
+# Build fusionforge
+make -f Makefile.debian BUILDRESULT=$WORKSPACE/build/packages LOCALREPODEB=$WORKSPACE/build/debian rwheezy
+
+# Transfer preseeding
+cat tests/preseed/* | sed s/@FORGE_ADMIN_PASSWORD@/$FORGE_ADMIN_PASSWORD/ | ssh root@$HOST "LANG=C debconf-set-selections"
+
+# Setup debian repo
+ssh root@$HOST "echo \"deb $DEBMIRROR $DIST main\" > /etc/apt/sources.list"
+ssh root@$HOST "echo \"deb $DEBMIRRORSEC $DIST/updates main\" > /etc/apt/sources.list.d/security.list"
+
+ssh root@$HOST "echo \"deb file:/debian $DIST main\" >> /etc/apt/sources.list"
+scp -r $WORKSPACE/build/debian root@$HOST:/
+gpg --export --armor | ssh root@$HOST "apt-key add -"
+sleep 5
+ssh root@$HOST "apt-get update"
+
+# Install fusionforge
+ssh root@$HOST "UCF_FORCE_CONFFNEW=yes DEBIAN_FRONTEND=noninteractive LANG=C apt-get -y --force-yes install rsync postgresql-contrib fusionforge-full"
+echo "Set forge admin password"
+ssh root@$HOST "/usr/share/gforge/bin/forge_set_password $FORGE_ADMIN_USERNAME $FORGE_ADMIN_PASSWORD"
+ssh root@$HOST "LANG=C a2dissite default ; LANG=C invoke-rc.d apache2 reload"
+ssh root@$HOST "(echo [core];echo use_ssl=no) > /etc/gforge/config.ini.d/zzz-buildbot.ini"
+
+# Dump database
+echo "Dump freshly installed database"
+ssh root@$HOST "su - postgres -c \"pg_dumpall\" > /root/dump"
+
+# Stop cron
+echo "Stop cron daemon"
+ssh root@$HOST "invoke-rc.d cron stop" || true
+
+# Install selenium tests
+ssh root@$HOST mkdir $FORGE_HOME/tests
+cp 3rd-party/selenium/selenium-server.jar tests/
+rsync -a --delete tests/ root@$HOST:$FORGE_HOME/tests/
+
+ssh root@$HOST "cat > $FORGE_HOME/tests/config/phpunit" <<-EOF
+HUDSON_URL=$HUDSON_URL
+JOB_NAME=$JOB_NAME
+EOF
-[ ! -d $WORKSPACE/build ] || rm -fr $WORKSPACE/build
-mkdir -p $WORKSPACE/build/packages
-[ ! -d $WORKSPACE/reports ] || rm -fr $WORKSPACE/reports
-mkdir -p $WORKSPACE/reports/coverage
+# Run tests
+retcode=0
+echo "Run phpunit test on $HOST in $FORGE_HOME"
-make -f Makefile.debian BUILDRESULT=$WORKSPACE/build/packages LOCALREPODEB=$WORKSPACE/build/debian rsqueeze
+ssh root@$HOST "apt-get -y install vnc4server ; mkdir -p /root/.vnc"
+ssh root@$HOST "cat > /root/.vnc/xstartup ; chmod +x /root/.vnc/xstartup" <<EOF
+#! /bin/bash
+: > /root/phpunit.exitcode
+$FORGE_HOME/tests/scripts/phpunit.sh DEBDebian70Tests.php &> /var/log/phpunit.log &
+echo \$! > /root/phpunit.pid
+wait %1
+echo \$? > /root/phpunit.exitcode
+EOF
+ssh root@$HOST vncpasswd <<EOF
+password
+password
+EOF
+ssh root@$HOST "vncserver :1"
+sleep 5
+pid=$(ssh root@$HOST cat /root/phpunit.pid)
+ssh root@$HOST "tail -f /var/log/phpunit.log --pid=$pid"
+sleep 5
+retcode=$(ssh root@$HOST cat /root/phpunit.exitcode)
+rsync -av root@$HOST:/var/log/ $WORKSPACE/reports/
+ssh root@$HOST "vncserver -kill :1" || retcode=$?
-cd tests
-phpunit --log-junit $WORKSPACE/reports/phpunit-selenium.xml DEBDebian60Tests.php
+stop_vm_if_not_keeped -t debian7 $@
+exit $retcode
-cd ..
-cp $WORKSPACE/reports/phpunit-selenium.xml $WORKSPACE/reports/phpunit-selenium.xml.org
-xalan -in $WORKSPACE/reports/phpunit-selenium.xml.org -xsl fix_phpunit.xslt -out $WORKSPACE/reports/phpunit-selenium.xml