#!/bin/bash
# Sets up a Xvfb display to run the browser selenium headless

jarfile="selenium-server-standalone-2.47.1.jar"

if [ ! -f $jarpath ]; then

    echo "Error: Couldn't find selenium server jar file"
    echo -e  "\t If you're running a different selenium server than"
    echo -e  "\t expected, please edit this file"
    echo "Aborting"
    exit 1

else

    echo "Killing existing Xvfb process"

    pkill Xvfb

    echo "Setting up Xvfb display"
    
    Xvfb :47 -ac &
    export DISPLAY=:47
    
    echo "Starting selenium server"

    java -jar $jarpath &> /dev/null &

    echo "Done, exiting"

fi

exit 0
