# copyright 2013 Holger Levsen <holger@layer-acht.org>
# GPL2 licenced
+if [ "$(id -n -u)" != "jenkins" ] ; then
+ echo "You must run this as user jenkins, exiting."
+ exit 1
+fi
+
set -e
set -x
export
GATEWAY=gw1301
PSERVER=pserver1301
+#
+# prepare ssh
+#
+TMPFILE=$(mktemp)
+ssh-agent > $TMPFILE
+source $TMPFILE
+ssh-add ~/.ssh/id_ritest
+
#
# prepare pserver
#
-ssh -i ~/.ssh/id_ritest $PSERVER "sudo dmsetup remove_all"
-ssh -i ~/.ssh/id_ritest $PSERVER "sudo mkdir -p /mnt/local_hdd"
-ssh -i ~/.ssh/id_ritest $PSERVER "sudo mount /dev/sda1 -t ext3 /mnt/local_hdd"
+ssh -t $PSERVER "sudo dmsetup remove_all"
+ssh -t $PSERVER "sudo mkdir -p /mnt/local_hdd"
+ssh -t $PSERVER "sudo umount /mnt/local_hdd || true"
+ssh -t $PSERVER "sudo mount /dev/sda1 -t ext3 /mnt/local_hdd"
#
# prepare core router
#
-ssh -i ~/.ssh/id_ritest $CORE_ROUTER "sudo rm /opt/autotest -rf"
-ssh -i ~/.ssh/id_ritest $CORE_ROUTER "git clone git://git/ri/autotest.git /opt/autotest"
-ssh -i ~/.ssh/id_ritest $CORE_ROUTER "cd /opt/autotest ; git checkout develop"
-ssh -A -i ~/.ssh/id_ritest $CORE_ROUTER "cd /opt/autotest ; ./run-compile.sh --config config-jenkins.xml"
+ssh -t $CORE_ROUTER "sudo rm /opt/autotest -rf"
+ssh -t $CORE_ROUTER "git clone git://git/ri/autotest.git /opt/autotest"
+ssh -t $CORE_ROUTER "cd /opt/autotest ; git checkout develop"
+
+#
+# run autotests
+#
+ssh -t $CORE_ROUTER "cd /opt/autotest ; cp config-jenkins.xml config.xml"
+#ssh -t -A $CORE_ROUTER "cd /opt/autotest ; ./run-compile.sh --config config-jenkins.xml"
+ssh -t -A $CORE_ROUTER "cd /opt/autotest ; ./run-compile.sh"