#!/bin/sh

KILL_MONGODB=false

if ! pidof mongod; then
    /usr/bin/mongod --config /etc/mongod.conf &
    KILL_MONGODB=true
fi

if ! nslookup example.com; then
  mv /etc/resolv.conf /etc/resolv.conf.bak
  echo "nameserver 8.8.8.8" > /etc/resolv.conf
  trap "mv /etc/resolv.conf.bak /etc/resolv.conf" INT EXIT
fi

while read runner; do
  oldpath=`pwd` >/dev/null
  cd bin
  echo Testing $runner
  ./$runner -ignore $oldpath/cppignore.lnx -all && echo PASS: $runner || echo FAIL: $runner
  cd $oldpath >/dev/null
done < testrunners

[ "$KILL_MONGODB" = "true" ] && killall mongod
