# Suppress output of debuginfo and debugsource
%global debug_package %{nil}

%global git     %{nil}
                #.git3cadeb5

Name:           arexibo
Version:        0.2.5
Release:        2%{?git}%{?dist}
Summary:        A Rust Linux Xibo player

License:        AGPLv3+
    
URL:            https://github.com/birkenfeld/arexibo
Source0:        %{url}/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}%{git}.tar.gz

%if 0%{?fedora} || 0%{?rhel} >= 8
ExclusiveArch:  %{rust_arches}
%else
ExclusiveArch:  x86_64 ppc64le aarch64
%endif
BuildRequires:  rust >= 1.66
BuildRequires:  cargo
BuildRequires:  gcc-c++
BuildRequires:  dbus-devel >= 1.6
BuildRequires:  webkitgtk4-devel >= 2.22
BuildRequires:  zeromq-devel >= 4.1
BuildRequires:  systemd

Requires     :  gstreamer1-plugins-base
Requires     :  gstreamer1-plugins-good
Requires     :  gstreamer1-plugins-good-gtk
Requires     :  gstreamer1-plugins-bad-free
Requires     :  gstreamer1-plugins-ugly-free
Requires     :  gstreamer1-plugin-openh264
Requires     :  gstreamer1-vaapi
%if 0%{?fedora} || 0%{?rhel} >= 8
Recommends   :  gstreamer1-libav
%endif

Requires(pre): /usr/bin/getent
Requires(pre): /usr/sbin/groupadd
Requires(pre): /usr/sbin/useradd

Requires(post):   systemd
Requires(preun):  systemd

Requires(postun): systemd

%description
Arexibo is an unofficial alternate Digital Signage Player for Xibo,
implemented in Rust with the GTK GUI components, for Linux platforms.

It is currently quite incomplete.
Don't expect any particular feature to work unless tested.


%prep
%setup -q -n %{name}-%{version}%{git}

cat >systemd <<EOF
[Unit]
Description=Start X with Arexibo player
After=network-online.target
Requires=network-online.target

[Service]
Type=simple
ExecStart=%{_bindir}/xinit %{_bindir}/%{name} %{_localstatedir}/cache/xibo -- :0 vt2 -s 0 -v -dpms
User=xibo
Group=xibo
Restart=always
RestartSec=60
Environment=NO_AT_BRIDGE=1

[Install]
WantedBy=multi-user.target
EOF

%build
cargo fetch
cargo build --release --offline -j2

%install
mkdir -p %{buildroot}%{_bindir}
install -Dpm 0755 target/release/%{name} %{buildroot}%{_bindir}/

mkdir -p %{buildroot}%{_localstatedir}/cache/xibo

# systemd
install -Dpm 0644 systemd %{buildroot}%{_unitdir}/%{name}.service

%pre
getent group xibo >/dev/null || groupadd -g 9505 -r xibo
getent passwd xibo >/dev/null || \
  useradd -r -u 9505 -g xibo -d %{_localstatedir}/cache/xibo -s /sbin/nologin \
    -c "Xibo client cache" xibo

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun_with_restart %{name}.service

%files
%license LICENSE
%doc README.md assets target/release/examples
%dir %{_localstatedir}/cache/xibo
%{_bindir}/%{name}
%{_unitdir}/%{name}.service

%changelog
* Tue Aug 13 2024 Jean-Marc Liger <ligenix@iscp.fr> - 0.2.5-2
- Add missing /var/cache/xibo

* Tue Aug 13 2024 Jean-Marc Liger <ligenix@iscp.fr> - 0.2.5-1
- Update to 0.2.5

* Sat Jul 20 2024 Jean-Marc Liger <ligenix@iscp.fr> - 0.2.4-1
- Update to 0.2.4

* Wed Dec 27 2023 Jean-Marc Liger <ligenix@iscp.fr> - 0.2.3-4.3cadeb5
- Update from last git commit 3cadeb5
  Rust toolchain >= 1.66 is required

* Tue Aug 15 2023 Jean-Marc Liger <ligenix@iscp.fr> - 0.2.3-3
- Add gstreamer1-plugin-openh264 dependency #Luc Tamisier

* Sat Nov 19 2022 Jean-Marc Liger <ligenix@iscp.fr> - 0.2.3-2
- Add gstreamer1 dependencies #Nicolas Meneceur
- Update cargo dependencies from git

* Sat Nov 12 2022 Jean-Marc Liger <ligenix@iscp.fr> - 0.2.3-1
- Initial RPM 0.2.3