#!/bin/sh
set -eux
# install build dependencies
dnf -y install python3-setuptools python3 python3-gobject-base \
    python3-dbus dbus-x11 util-linux \
    upower NetworkManager bluez libnotify polkit

if ! grep -q :el /etc/os-release; then
    dnf -y install iio-sensor-proxy
fi
# HACK: powerprofilectl started to SIGTRAP in Fedora Rawhide https://github.com/martinpitt/python-dbusmock/issues/177
if [ -n "$TEST_CODE" ]; then
    dnf -y install power-profiles-daemon
fi

if [ -n "$TEST_CODE" ]; then
    dnf -y install python3-flake8 python3-pylint python3-mypy
fi

# systemd's tools otherwise fail on "not been booted with systemd"
mkdir -p /run/systemd/system

# run build and test as user
useradd build
su -s /bin/sh - build << EOF
set -ex
cd /source
export TEST_CODE="$TEST_CODE"
python3 -m unittest -v || {
  [ -z "$DEBUG" ] || sleep infinity
  exit 1
}
EOF
