#! /bin/sh

export PATH=/bin:$PATH
export SCREENSHOT_FAILURES=true
export HEADLESS=true
export MEDIAWIKI_URL=https://zero.wikimedia.org/wiki/

if [ ! -e ~/.zero/ ]
then
	mkdir ~/.zero
	error=true
fi
chmod 700 ~/.zero

if [ ! -e ~/.zero/email ]
then
	touch ~/.zero/email
	echo "REPLACE_WITH_EMAIL" > ~/.zero/email
	error=true
fi
chmod 600 ~/.zero/email

if [ "$error" = true ]
then
	echo "ERROR"
	echo "====="
	echo "Go setup ~/.zero/email"
	exit 1
fi

# okay, we look good to go
export EMAIL=`cat ~/.zero/email`
if [ ! -e reports/ ]
then
	mkdir reports
fi
chmod 755 reports

d=`date "+%Y%m%d-%H%M-%S"`
report="reports/cucumber_anon_prod-${d}.html"
screenshots="reports/cucumber_anon_prod_screenshots-${d}"
mkdir $screenshots
chmod 755 $screenshots
export SCREENSHOT_FAILURES_PATH=$screenshots
bundle exec cucumber --tags @anon -f html -o $report
if [ $? -eq 1 ]
then
        echo "Partner portal ANON PROD failure. See attached." | mailx -s "Portal Cucumber: FAIL Anon Prod" -a $report $EMAIL
fi
