File sunshine.spec of Package sunshine

#
# spec file for package sunshine
#
# Copyright (c) 2023 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

Name:           sunshine
Version:        0.23.1
Release:        0
Summary:        Streaming server for moonlight
License:        GPL-3.0
URL:            https://github.com/LizardByte/Sunshine
Source:         Sunshine-%{version}.tar.gz
Source2:        sunshine.xml
Source98:       package-lock.json
Source99:       node_modules.spec.inc
%include  %{_sourcedir}/node_modules.spec.inc
BuildRequires:  cmake
BuildRequires:  fdupes
BuildRequires:  gcc13
BuildRequires:  gcc13-c++
BuildRequires:  libboost_system-devel-impl
BuildRequires:  libboost_thread-devel-impl
BuildRequires:  libboost_locale-devel-impl
BuildRequires:  libboost_log-devel-impl
BuildRequires:  libboost_program_options-devel-impl
BuildRequires:  libayatana-appindicator3-devel
BuildRequires:  wayland-protocols-devel
BuildRequires:  libmfx1
BuildRequires:  mfx-compat
BuildRequires:  pkgconfig(libnotify)
BuildRequires:  pkgconfig(libcap)
BuildRequires:  pkgconfig(libcurl)
BuildRequires:  pkgconfig(libdrm)
BuildRequires:  pkgconfig(libevdev)
BuildRequires:  pkgconfig(libopusenc)
BuildRequires:  pkgconfig(libva)
BuildRequires:  pkgconfig(vdpau)
BuildRequires:  pkgconfig(wayland-client)
BuildRequires:  pkgconfig(x11)
BuildRequires:  pkgconfig(xcb)
BuildRequires:  pkgconfig(xfixes)
BuildRequires:  pkgconfig(xtst)
BuildRequires:  pkgconfig(xrandr)
BuildRequires:  pkgconfig(numa)
BuildRequires:  pkgconfig(openssl)
BuildRequires:  pkgconfig(miniupnpc)
BuildRequires:  pkgconfig(systemd)
BuildRequires:  pkgconfig(udev)
BuildRequires:  pulseaudio-libs >= 10.0
BuildRequires:  pulseaudio-devel >= 10.0
BuildRequires:  local-npm-registry
BuildRequires:  libcap-progs
%if 0%{?suse_version} <= 1600
BuildRequires:  python311
%{?sle15_python_module_pythons}
%endif
Suggests:       %{name}-firewalld

%description
Sunshine is a self-hosted game stream host for Moonlight.
Offering low latency, cloud gaming server capabilities with support for AMD, Intel, and Nvidia GPUs for hardware encoding.
Software encoding is also available. You can connect to Sunshine from any Moonlight client on a variety of devices.
A web UI is provided to allow configuration, and client pairing, from your favorite web browser.
Pair from the local server or any mobile device.

%package firewalld
Requires:       firewalld
Requires:       %{name} = %{version}
BuildRequires:  firewalld
BuildArch:      noarch
Summary:        Firewalld settings for Sunshine

%description firewalld
%{summary}.

%prep
%setup -n Sunshine-%{version}
rm -f package-lock.json
local-npm-registry %{_sourcedir} install --include=dev --legacy-peer-deps

%check

%build
export CC="gcc-13"
export CXX="g++-13"
%cmake -DSUNSHINE_ASSETS_DIR="share/sunshine" -DSUNSHINE_EXECUTABLE_PATH=%{_bindir}/sunshine
%cmake_build

%install
%cmake_install
mv %{buildroot}%{_bindir}/sunshine-%{version} %{buildroot}%{_bindir}/sunshine
install -d %{buildroot}%{_exec_prefix}/lib/firewalld/services/
install -m 644 %{SOURCE2} %{buildroot}%{_exec_prefix}/lib/firewalld/services/sunshine.xml
%fdupes %{buildroot}/%{_prefix}
%{__strip} %{buildroot}%{_bindir}/sunshine

%post
%{_sbindir}/setcap cap_sys_admin+p /usr/bin/sunshine

%post firewalld
%ldconfig
%if 0%{?is_opensuse}
if [ $1 -eq 1 ]; then # inital/first package install
    if [ -x %{_bindir}/firewall-cmd ]; then
        echo 'Adding sunshine service to default and home firewalld zones'
        if firewall-cmd -q --state; then
            firewall-cmd -q --add-service=sunshine
            firewall-cmd -q --add-service=sunshine --zone=home
            firewall-cmd -q --runtime-to-permanent
        else
            firewall-offline-cmd -q --add-service=sunshine
            firewall-offline-cmd -q --add-service=sunshine --zone=home
        fi
    fi
fi
true
%endif

%postun firewalld
%ldconfig
%if 0%{?is_opensuse}
if [ $1 -eq 0 ]; then # last/final package removal
    if [ -x %{_bindir}/firewall-cmd ]; then
        echo 'Removing sunshine service from default and home firewalld zones'
        if firewall-cmd -q --state; then
            firewall-cmd -q --remove-service=sunshine
            firewall-cmd -q --remove-service=sunshine --zone=home
            firewall-cmd -q --runtime-to-permanent
        else
            firewall-offline-cmd -q --remove-service=sunshine
            firewall-offline-cmd -q --remove-service-from-zone=sunshine --zone=home
        fi
    fi
fi
true
%endif

%files
%{_datadir}/sunshine
%{_bindir}/sunshine
%dir %attr(0755, root, root) "/usr/lib/udev"
%dir %attr(0755, root, root) "/usr/lib/udev/rules.d"
%attr(0644, root, root) "/usr/lib/udev/rules.d/60-sunshine.rules"
%dir %attr(0755, root, root) "/usr/lib/systemd"
%dir %attr(0755, root, root) "/usr/lib/systemd/user"
%attr(0644, root, root) "/usr/lib/systemd/user/sunshine.service"
%{_datadir}/applications/sunshine.desktop
%{_datadir}/applications/sunshine_terminal.desktop
%{_datadir}/icons/hicolor/scalable/apps/sunshine.svg
%{_datadir}/icons/hicolor/scalable/status/sunshine-locked.svg
%{_datadir}/icons/hicolor/scalable/status/sunshine-pausing.svg
%{_datadir}/icons/hicolor/scalable/status/sunshine-playing.svg
%{_datadir}/icons/hicolor/scalable/status/sunshine-tray.svg
%{_datadir}/metainfo/sunshine.appdata.xml

%files firewalld
%{_exec_prefix}/lib/firewalld/services/sunshine.xml

%changelog
openSUSE Build Service is sponsored by