#!/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 :el8 /etc/os-release; then
    dnf -y install python3-pip python3-pycodestyle python3-pyflakes \
        power-profiles-daemon iio-sensor-proxy
fi

[ -z "${PYLINT:-}" ] || dnf -y install python3-pylint

# 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
grep -q platform:el8 /etc/os-release || pip3 install mypy
python3 -m unittest -v || {
  [ -z "$DEBUG" ] || sleep infinity
  exit 1
}
EOF
