File usbguard.spec of Package usbguard

#
# spec file for package usbguard
#
# Copyright (c) 2016 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 http://bugs.opensuse.org/
#


%global _hardened_build 1

%define lname libusbguard0

Name:           usbguard
Version:        0.4
Release:        1
Summary:        A tool for implementing USB device usage policy
License:        GPL-2.0+
Group:          System Environment/Daemons
## Not installed
# src/ThirdParty/Catch: Boost Software License - Version 1.0
Url:            https://dkopecek.github.io/usbguard
Source0:        https://dkopecek.github.io/usbguard/dist/%{name}-%{version}.tar.gz
Source1:        usbguard-daemon.conf
Source2:        usbguard.service
%{?systemd_requires}

BuildRequires:  libqb-devel
BuildRequires:  libsodium-devel
BuildRequires:  libseccomp-devel
BuildRequires:  libcap-ng-devel
BuildRequires:  gcc-c++
#BuildRequires:  spdlog-static
BuildRequires:  systemd-devel libudev-devel

%description
The USBGuard software framework helps to protect your computer against rogue USB
devices by implementing basic whitelisting/blacklisting capabilities based on
USB device attributes.

%package -n %lname
Summary:        Library for implementing USB device usage policy
License:        GPL-2.0+
Group:          System Environment/Daemons

%description -n %lname
The USBGuard software framework helps to protect your computer against rogue USB
devices by implementing basic whitelisting/blacklisting capabilities based on
USB device attributes.

%package        devel
Summary:        Development files for %{name}
Group:          Development/Libraries
Requires:       %{name} = %{version}
Requires:	%lname = %{version}
Requires:       libstdc++-devel
Requires:       pkgconfig

%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.

%package        tools
Summary:        USBGuard Tools
Group:          Applications/System
Requires:       %{name} = %{version}-%{release}

%description    tools
The %{name}-tools package contains optional tools from the USBGuard
software framework.

%prep
%setup -q
# Remove bundled library sources before build
#rm -rf src/ThirdParty/{json,spdlog}

%build
%configure \
    --disable-silent-rules \
    --with-bundled-json \
    --with-bundled-spdlog \
    --disable-static

make %{?_smp_mflags}

%check
make check

%install
make install INSTALL='install -p' DESTDIR=%{buildroot}

# Install configuration
mkdir -p %{buildroot}%{_sysconfdir}/usbguard
install -p -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/usbguard/usbguard-daemon.conf

# Install systemd unit
mkdir -p %{buildroot}%{_unitdir}
install -p -m 644 %{SOURCE2} %{buildroot}%{_unitdir}/usbguard.service

# Cleanup
find %{buildroot} -name '*.la' -delete

%preun
%service_del_preun usbguard.service

%post
/sbin/ldconfig
%service_add_post usbguard.service

%postun
/sbin/ldconfig
%service_del_postun usbguard.service

%pre
%service_add_pre usbguard.service


%files
%defattr(-,root,root,-)
%doc README.md
%license LICENSE
%{_sbindir}/usbguard-daemon
%dir %{_sysconfdir}/usbguard
%config(noreplace) %{_sysconfdir}/usbguard/usbguard-daemon.conf
%{_unitdir}/usbguard.service
%{_datadir}/man/man8/usbguard-daemon.8.gz
%{_datadir}/man/man5/usbguard-daemon.conf.5.gz
%{_datadir}/man/man5/usbguard-rules.conf.5.gz

%files -n %lname
%defattr(-,root,root,-)
%license LICENSE
%{_libdir}/*.so.*

%files devel
%defattr(-,root,root,-)
%{_includedir}/*
%{_libdir}/*.so
%{_libdir}/pkgconfig/*.pc

%files tools
%defattr(-,root,root,-)
%{_bindir}/usbguard
%{_bindir}/usbguard-rule-parser
%{_datadir}/man/man1/usbguard.1.gz

%changelog