File xone.spec of Package xone

#
# spec file for package xone
#
# 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/
#
# needssslcertforbuild

Name:           xone
Version:        0.0.0
Release:        0
Summary:        Linux kernel driver for Xbox One and Xbox Series X|S accessories
# FIXME: Select a correct license from https://github.com/openSUSE/spec-cleaner#spdx-licenses
License:        GPL-2.0-or-later
URL:            https://github.com/medusalix
Source:         _service
Source1:        preamble
BuildRequires:  %{kernel_module_package_buildreqs}
%if 0%{?is_opensuse} && 0%{?suse_version} >= 1699
BuildRequires:  kernel-longterm-devel
%endif
BuildRequires:  libelf-devel
BuildRequires:  pkgconfig(libsystemd)
Requires: curl
Requires: cabextract
Requires: coreutils
Requires: %{name}-kmp = %version
Obsoletes: %{name}-kmp < %version 
Conflicts: xow <= 0.5
Obsoletes: xow <= 0.5

BuildRequires:  pesign-obs-integration
%kernel_module_package -n %{name} -x debug -x trace -c %{_sourcedir}/_projectcert.crt -p %{_sourcedir}/preamble
%description
xone is a Linux kernel driver for Xbox One and Xbox Series X|S accessories. It serves as a modern replacement for xpad, aiming to be compatible with Microsoft's Game Input Protocol (GIP)
✔️Wired devices (via USB)
✔️Wireless devices (with Xbox Wireless Dongle)
❌Bluetooth devices (check out xpadneo)
%prep
%setup -q -n %_sourcedir/%name-%version -T -D
%__mkdir -p %_builddir/%_sourcedir
%__ln -rs %_sourcedir/%name-%version %_builddir/%_sourcedir

cat dkms.conf|grep BUILT_MODULE_NAME |awk -F '"' '{print $2}' > %{name}.conf
set -- *
mkdir source
mv "$@" source/
mkdir obj
%build
# Build the driver kernel module
for flavor in %flavors_to_build; do
rm -rf obj/$flavor
cp -r source obj/$flavor
make -C %{kernel_source $flavor} modules M=$PWD/obj/$flavor
done

%install
# Install the driver kernel module
export INSTALL_MOD_PATH=%{buildroot}
export INSTALL_MOD_DIR=drivers/input/joystick
for flavor in %{flavors_to_build}; do
        make -C %{kernel_source $flavor} %{?linux_make_arch} modules_install M=$PWD/obj/$flavor
done

# The BRP_PESIGN_FILES variable must be set to a space separated list of
# directories or patterns matching files that need to be signed.  E.g., packages
# that include firmware files would set BRP_PESIGN_FILES='*.ko /lib/firmware'
export BRP_PESIGN_FILES='*.ko'

install -D -m 0644 source/install/modprobe.conf %{buildroot}%{_modprobedir}/60-%{name}.conf
install -D -m 0644 source/%{name}.conf %{buildroot}%{_modulesloaddir}/%{name}.conf


%post
if [ -x "$(command -v curl)" ];then
if [ ! -f "/lib/firmware/xow_dongle.bin" ]; then
  # After installation, download the firmware
  mkdir -p /tmp/microsoft
  cd /tmp/microsoft

  driver_url='http://download.windowsupdate.com/c/msdownload/update/driver/drvs/2017/07/1cd6a87c-623f-4407-a52d-c31be49e925c_e19f60808bdcbfbd3c3df6be3e71ffc52e43261e.cab'
  firmware_hash='48084d9fa53b9bb04358f3bb127b7495dc8f7bb0b3ca1437bd24ef2b6eabdf66'

  curl -L -o driver.cab "$driver_url"
  cabextract -F FW_ACC_00U.bin driver.cab
  echo "$firmware_hash" FW_ACC_00U.bin | sha256sum -c
  cp -f FW_ACC_00U.bin /lib/firmware/xow_dongle.bin

  rm -rf "/tmp/microsoft"
fi
fi
%preun
if [ "$1" = 0 ]; then
  # Remove xone
  modules=$(lsmod | grep '^xone_' | cut -d ' ' -f 1 | tr '\n' ' ')

  if [ -n "$modules" ]; then
    echo "Unloading modules: $modules..."
    modprobe -r -a $modules
  fi

  # Remove system firmware
  rm -rf "/lib/firmware/xow_dongle.bin"
fi

%files
%license source/LICENSE
%doc source/README.md
%{_modprobedir}/60-%{name}.conf
%{_modulesloaddir}/%{name}.conf
%changelog

openSUSE Build Service is sponsored by