#!/bin/sh
set -eux
# Ubuntu still creates this legacy group by default, breaks useradd
delgroup --quiet --system admin || true

# test expects this user and Fedora group "wheel"
addgroup wheel
useradd -m -U -c Administrator -G sudo,wheel -s /bin/bash admin
echo admin:foobar | chpasswd

# packaged phantomjs crashes with "QXcbConnection: Could not connect to display" otherwise
export QT_QPA_PLATFORM=offscreen

# avocado is not packaged, thus install through pip
pip install avocado-framework

npm install sizzle

test/avocado/checklogin-raw.py
if ! test/avocado/checklogin-basic.py; then
    if grep -q 'Error: PhantomJS or driver broken' /tmp/avocado*core.job*/job.log; then
        echo "Ignoring PhantomJS failure"
    else
        exit 1
    fi
fi
