%global modulename fedora-laptop-testing
%define commit 6e3ca9ee9588ddff17e6ebd00e10d58c3a1ef422
%define relversion 0.2
%if 0%{?commit:1}
  %define shortcommit %(c=%{commit}; echo ${c:0:7})
  %define build_timestamp %(date +"%Y%m%d")
%endif

Summary: Testing Fedora on laptops and other hardware
Name: fedora-laptop-testing
Version: %{relversion}%{?commit:.}%{?build_timestamp}%{?commit:git}%{?shortcommit}
Release: 0%{?dist}
License: GPLv2
Source0: %{name}-%{relversion}%{?commit:-}%{?shortcommit}.tar.gz
Group: Development/Tools
URL: https://pagure.io/fedora-laptop-testing
BuildArch: noarch
Requires: python2-evdev, python2-docutils, pygobject3, gdm, gnome-shell, js-jquery2
Requires: pulseaudio-utils, gstreamer1, gstreamer1-plugins-good
Requires: libwebkit2gtk
Requires: usbutils, iw
Requires: python2-avocado
Requires: evemu
# This is a workaround for https://github.com/avocado-framework/avocado/issues/2116
Requires: python2-avocado-plugins-runner-remote
Requires(pre): shadow-utils, dconf
Requires(post):   systemd
Requires(preun):  systemd
Requires(postun): systemd
%if 0%{?fedora}
Requires: python2-numpy
Requires: python2-pycurl
Requires: python2-yaml
Recommends: gnome-battery-bench >= 3.25.0, fwts, rfkill
Recommends: libinput, dmidecode, alsa-utils
%else
# Currently missing: rfkill
Requires: numpy
Requires: PyYAML
Requires: python-pycurl
Requires: gnome-battery-bench >= 3.25.0, fwts, rfkill
Requires: libinput, dmidecode, alsa-utils
%define _unitdir /usr/lib/systemd/system
%endif
BuildRequires: python2-devel, python-setuptools, python-mock, yum


%description
This package contains a suit of tests to verify that the hardware is working as
expected. Some of these tests can be run standalone on a machine, other require
specialized external hardware or user interaction to work.

After install the standalone tests can be run.

%prep
%setup -q -n %{name}-%{relversion}%{?commit:-}%{?shortcommit}

%build
%{__python} setup.py build
cd plugins
%{__python} setup.py build
cd ../

%install
%{__python} setup.py install --root %{buildroot} --skip-build
cd plugins
%{__python} setup.py install --root %{buildroot} --skip-build
cd ../
%{__install} -d %{buildroot}%{_sysconfdir}/avocado
%{__install} -d %{buildroot}%{_sysconfdir}/avocado/sysinfo
%{__install} -m 0644 avocado/fedora-laptop-testing.conf %{buildroot}%{_sysconfdir}/avocado/
%{__install} -m 0644 avocado/sysinfo/* %{buildroot}%{_sysconfdir}/avocado/sysinfo/
%{__install} -d %{buildroot}%{_datadir}/polkit-1/rules.d/
%{__install} -d %{buildroot}%{_bindir}
%{__install} -d %{buildroot}%{_sbindir}
%{__install} -m 0755 scripts/dbus-dump.py %{buildroot}%{_bindir}/fed-dbus-dump.py
%{__install} -m 0755 scripts/evemu-dump %{buildroot}%{_bindir}/fed-evemu-dump
%{__install} -m 0755 init/fedora-laptop-testing %{buildroot}%{_sbindir}/fedora-laptop-testing
%{__install} -d %{buildroot}%{_datadir}/applications/
%{__install} -m 0755 scripts/fedora-laptop-testing-upload.desktop %{buildroot}%{_datadir}/applications/fedora-laptop-testing-upload.desktop
%{__install} -m 0755 scripts/fedora-laptop-testing-upload %{buildroot}%{_bindir}/fedora-laptop-testing-upload
%{__install} -m 0644 fedora-laptop-testing-polkit.rules %{buildroot}%{_datadir}/polkit-1/rules.d/fedora-laptop-testing.rules
%{__install} -d %{buildroot}%{_sysconfdir}/dconf/db/database.d
%{__install} -m 0644 user.conf %{buildroot}%{_sysconfdir}/dconf/db/database.d/user.conf
%{__install} -d %{buildroot}%{_sharedstatedir}/fedora-laptop-testing
%{__install} -d %{buildroot}%{_sharedstatedir}/fedora-laptop-testing/job-results
%{__install} -d %{buildroot}%{_sharedstatedir}/fedora-laptop-testing/result-bundles
%{__install} -d %{buildroot}%{_localstatedir}/cache/fedora-laptop-testing
%{__install} -Dpm 644 init/fedora-laptop-testing.service %{buildroot}%{_unitdir}/fedora-laptop-testing.service
%{__install} -d %{buildroot}%{_sharedstatedir}/fedora-laptop-testing/home
%{__install} -d %{buildroot}%{_sharedstatedir}/fedora-laptop-testing/home/.config
touch %{buildroot}%{_sharedstatedir}/fedora-laptop-testing/home/.config/gnome-initial-setup-done

%check
%{__python} setup.py develop --user
#cd plugin
#%{__python} setup.py develop --user
#cd ..

%files
%defattr(-,root,root,-)
#%doc README.rst LICENSE
%{python_sitelib}/fed_laptoptest*
%{python_sitelib}/avocado_*
%{_datadir}/fedora-laptop-testing*
%{_datadir}/polkit-1/rules.d/*
%{_datadir}/applications/fedora-laptop-testing-upload.desktop
%{_bindir}/*
%{_sbindir}/*
%{_unitdir}/*
%{_sharedstatedir}/fedora-laptop-testing/job-results
%{_sharedstatedir}/fedora-laptop-testing/result-bundles
%{_localstatedir}/cache/fedora-laptop-testing
# Configuration files
%config %{_sysconfdir}/avocado/fedora-laptop-testing.conf
%config %{_sysconfdir}/avocado/sysinfo/*
%config %{_sysconfdir}/dconf/db/database.d/user.conf
# Home directory for the test user
%attr(0700, fedora-laptop-testing, fedora-laptop-testing) %{_sharedstatedir}/fedora-laptop-testing/home*

%pre
getent group fedora-laptop-testing >/dev/null || groupadd -r fedora-laptop-testing
getent passwd fedora-laptop-testing >/dev/null || \
    useradd -r -g fedora-laptop-testing \
    -d %{_sharedstatedir}/fedora-laptop-testing/home \
    -s /bin/bash \
    -c "Account to create a user session for laptop testing" fedora-laptop-testing
usermod fedora-laptop-testing -s /bin/bash

exit 0

%post
%if 0%{?fedora}
%systemd_post fedora-laptop-testing.service
%else
if [ $1 -eq 1 ] ; then
        # Initial installation
        systemctl --no-reload preset fedora-laptop-testing.service >/dev/null 2>&1 || :
fi
%endif
dconf update
exit 0

%preun
%if 0%{?fedora}
%systemd_preun fedora-laptop-testing.service
%else
if [ $1 -eq 0 ] ; then
        # Package removal, not upgrade
        systemctl --no-reload disable --now fedora-laptop-testing.service > /dev/null 2>&1 || :
fi
%endif

%postun
if [ $1 == 0 ]; then
    # Lock the user account
    usermod fedora-laptop-testing -s /sbin/nologin
fi
%systemd_postun

%changelog
* Fri May 30 2017 Benjamin Berg <bberg@redhat.com> - 0.2-1
- Update package.

* Fri Mar 24 2017 Benjamin Berg <bberg@redhat.com> - 0.1-1
- Created initial spec file