File fwupd.spec of Package fwupd

# spec file for package fwupd
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# 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
# needssslcertforbuild

%ifarch %{ix86} x86_64 aarch64
%bcond_without efi_fw_update
%bcond_with efi_fw_update
%if 0%{?is_opensuse}
%global efidir opensuse
%global efidir sles
Name:           fwupd
Version:        1.2.3
Release:        0
Summary:        Device firmware updater daemon
License:        GPL-2.0-or-later AND LGPL-2.1-or-later
Group:          System/Management
Source:         %{name}-%{version}.tar.xz
BuildRequires:  dejavu-fonts
BuildRequires:  docbook-utils-minimal
BuildRequires:  gcab
# for certtool
BuildRequires:  gnutls
BuildRequires:  gobject-introspection
BuildRequires:  gobject-introspection-devel
BuildRequires:  gpgme-devel
BuildRequires:  help2man
BuildRequires:  intltool
BuildRequires:  libelf-devel
BuildRequires:  meson >= 0.47.0
BuildRequires:  pkgconfig
BuildRequires:  procps
BuildRequires:  python3-Pillow
BuildRequires:  python3-cairo
BuildRequires:  python3-gobject-Gdk
BuildRequires:  python3-xml
BuildRequires:  vala
BuildRequires:  pkgconfig(appstream-glib) >= 0.5.10
BuildRequires:  pkgconfig(bash-completion)
BuildRequires:  pkgconfig(cairo)
BuildRequires:  pkgconfig(colorhug) >= 1.2.12
BuildRequires:  pkgconfig(gio-2.0) >= 2.25.9
BuildRequires:  pkgconfig(gio-unix-2.0)
BuildRequires:  pkgconfig(glib-2.0) >= 2.45.8
BuildRequires:  pkgconfig(gmodule-2.0)
BuildRequires:  pkgconfig(gnutls)
BuildRequires:  pkgconfig(gobject-2.0)
BuildRequires:  pkgconfig(gthread-2.0)
BuildRequires:  pkgconfig(gtk-doc) >= 1.14
BuildRequires:  pkgconfig(gudev-1.0)
BuildRequires:  pkgconfig(gusb) >= 0.2.9
BuildRequires:  pkgconfig(json-glib-1.0) >= 1.1.1
BuildRequires:  pkgconfig(libarchive)
BuildRequires:  pkgconfig(libelf)
BuildRequires:  pkgconfig(libgcab-1.0)
BuildRequires:  pkgconfig(libsoup-2.4) >= 2.51.92
BuildRequires:  pkgconfig(polkit-gobject-1) >= 0.103
BuildRequires:  pkgconfig(sqlite3)
BuildRequires:  pkgconfig(systemd)
BuildRequires:  pkgconfig(udev)
BuildRequires:  pkgconfig(valgrind)
BuildRequires:  pkgconfig(xmlb)
%if %{with efi_fw_update}
BuildRequires:  gnu-efi
BuildRequires:  pesign-obs-integration
BuildRequires:  pkgconfig(efiboot)
BuildRequires:  pkgconfig(efivar) >= 33
%ifarch %{ix86} x86_64
BuildRequires:  pkgconfig(libsmbios_c) >= 2.3.0
%if %{with efi_fw_update}
%ifarch x86_64
Requires:       shim >= 11
Obsoletes:      fwupdate

fwupd is a daemon to allows session software to update device firmware on
the local machine.

You can either use a GUI software manager like GNOME Software to view and apply
updates, the command line tool or the system D-Bus interface directly.

%package -n libfwupd2
Summary:        Allow session software to update device firmware
Group:          System/Libraries
Requires:       %{name} >= %{version}

%description -n libfwupd2
fwupd is a daemon to allows session software to update device firmware on
the local machine.

%package -n typelib-1_0-Fwupd-2_0
Summary:        GObject-introspection bindings for libfwupd
Group:          System/Libraries

%description -n typelib-1_0-Fwupd-2_0
fwupd is a daemon to allows session software to update device firmware on
the local machine.

%package -n dfu-tool
Summary:        Generic tool Device Firmware Upgrade (DFU) tool
Group:          Development/Tools/Other

%description -n dfu-tool
A generic tool to upload firmware to USB Devices based on Device Firmware Upgrade (DFU).

%package devel
Summary:        Allow session software to update device firmware
Group:          Development/Languages/C and C++
Requires:       libfwupd2 = %{version}

%description devel
fwupd is a daemon to allows session software to update device firmware on
the local machine.


%setup -q
for file in $(grep -l %{_bindir}/env . -r); do
  sed -i "s|%{_bindir}/env python3|%{_bindir}/python3|" $file

# Dell support requires direct SMBIOS access,
# Synaptics requires Dell support, i.e. x86 only
%meson \
%if %{without efi_fw_update}
  -Dplugin_nvme=false \
  -Dplugin_redfish=false \
  -Dplugin_uefi=false \
%ifnarch %{ix86} x86_64
  -Dplugin_dell=false \
  -Dplugin_synaptics=false \

export BRP_PESIGN_FILES='%{_libexecdir}/fwupd/efi/fwupd*.efi'
# is packaged as doc
rm %{buildroot}%{_localstatedir}/lib/fwupd/builder/
# Add SUSE specific rcfoo service symlink
mkdir -p %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcfwupd-offline-update
%find_lang %{name}

# do not package tests
rm -fr %{buildroot}%{_datadir}/installed-tests

%post   -n libfwupd2 -p /sbin/ldconfig
%postun -n libfwupd2 -p /sbin/ldconfig
%service_del_preun %{name}.service fwupd-offline-update.service

%service_add_pre %{name}.service fwupd-offline-update.service

%service_add_post %{name}.service fwupd-offline-update.service
%if %{with efi_fw_update}
if [ -d "/boot/efi/EFI/%{efidir}" ]; then
	# Create the directory for firwmare update capsules
	mkdir -p /boot/efi/EFI/%{efidir}/fw
	# Install the UEFI firmware update program
	cp %{_libexecdir}/fwupd/efi/fwupd*.efi /boot/efi/EFI/%{efidir}

%service_del_postun %{name}.service fwupd-offline-update.service
%if %{with efi_fw_update}
if [ "$1" = 0 ] && [ -d "/boot/efi/EFI/%{efidir}" ] ; then
	# Remove all capsule files
	rm -rf /boot/efi/EFI/%{efidir}/fw
	# Remove the UEFI firmware update program
	rm -f /boot/efi/EFI/%{efidir}/fwupd*.efi

%license COPYING
%%dir %{_libexecdir}/systemd/system/
%config %{_sysconfdir}/%{name}/
%dir %{_sysconfdir}/pki
%dir %{_sysconfdir}/pki/fwupd
%dir %{_sysconfdir}/pki/fwupd-metadata
%dir %{_datadir}/metainfo
%dir %{_localstatedir}/lib/%{name}/

%files -n dfu-tool

%files -n libfwupd2

%files -n typelib-1_0-Fwupd-2_0

%files lang -f %{name}.lang
%if %{with efi_fw_update}

%files devel
%doc %{_datadir}/gtk-doc/html/libfwupd/