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

if ! grep -q :el /etc/os-release; then
    dnf -y install power-profiles-daemon python3-pytest
else
    dnf -y install python3-pip
    pip install pytest
fi

if [ "$SKIP_STATIC_CHECKS" != "1" ]; then
    dnf -y install python3-pylint python3-mypy python3-pip black
    pip install ruff
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 || { [ -z "$DEBUG" ] || sleep infinity; exit 1; }
set -ex
cd /source
export SKIP_STATIC_CHECKS="$SKIP_STATIC_CHECKS"

python3 -m unittest -v
python3 -m pytest -v
EOF
