File openct.spec of Package openct
#
# spec file for package openct
#
# Copyright (c) 2017 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/
#
# These UID and GID must be equal to values in the pcsc-lite.spec:
%define USER scard
%define GROUPID scard
%define ifddir %(pkg-config libpcsclite --variable=usbdropdir)
%define LBRACE (
%define RBRACE )
%define QUOTE "
%define BACKSLASH \\
%define USBDRIVERS %(set -x ; bunzip2 <%{SOURCE0} | sed -n 's/^ENV{MODALIAS}==%{QUOTE}%{BACKSLASH}%{LBRACE}usb:[^{QUOTE}]*%{BACKSLASH}%{RBRACE}%{BACKSLASH}*%{QUOTE}.*$/modalias%{LBRACE}%{BACKSLASH}1d*dc*dsc*dp*ic*isc*ip*%{RBRACE}/p' | tr '%{BACKSLASH}n' ' ')
%define _udevdir %(pkg-config --variable=udevdir udev)
%{!?_udevrulesdir: %define _udevrulesdir %{_udevdir}/rules.d}
%if 0%{?suse_version} > 1140
%define has_systemd 1
BuildRequires: systemd-rpm-macros
%{?systemd_requires}
%endif
Name: openct
Version: 0.6.20
Release: 0
Summary: Tools for Smart Card Readers
License: BSD-3-Clause and LGPL-2.1+
Group: Productivity/Security
Url: https://github.com/OpenSC/openct/wiki
Source: %{name}-%{version}.tar.bz2
Source2: README.SUSE
Source3: baselibs.conf
Source4: %{name}-rpmlintrc
Source5: %{name}.service
Source6: %{name}-handler@.service
Patch1: %{name}-init.patch
Patch2: %{name}-udev-permission.patch
Patch3: %{name}-systemd.patch
Patch4: %{name}-disable_forcepool.patch
# this patch can be dropped once 0.6.21 is out
Patch5: 0001-Handling-multiple-USB-tokens-in-IFD-handler.patch
BuildRequires: db-devel
BuildRequires: doxygen
BuildRequires: krb5-devel
BuildRequires: libtool
BuildRequires: libusb-devel
BuildRequires: openldap2-devel
BuildRequires: pcsc-lite-devel
BuildRequires: pkg-config
BuildRequires: udev
%if !0%{?has_systemd}
Requires(post): %insserv_prereq %fillup_prereq
%endif
# openSUSE package pcsc-lite 1.6.6 is the first one which creates the scard UID and GID:
Requires(post): pcsc-lite >= 1.6.6
# We are not using Supplements here. User may want to choose between openct and pcsc-lite:
Enhances: %{USBDRIVERS}
# Generic CCID devices:
Enhances: modalias(usb:*ic0Bisc00d*dc*dsc*dp*ic*isc*ip*)
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: libudev-devel
%description
OpenCT is a set of library and tools to talk to smart card readers.
OpenCT is used by the OpenSC Smart Card library.
For a list of supported readers, please read documentation in
%{_docdir}/openct/wiki/index.html - some readers may be
supported only with particular firmware or particular connection type.
There are other packages that may support your reader in a different
way. Name of all these packages starts with "pcsc-".
%package -n libopenct1
Summary: Library for Smart Card Readers
Group: System/Libraries
%description -n libopenct1
OpenCT is a set of library and tools to talk to smart card readers.
OpenCT is used by the OpenSC Smart Card library.
For a list of supported readers, please read documentation in
%{_docdir}/openct/wiki/index.html - some readers may be
supported only with particular firmware or particular connection type.
There are other packages that may support your reader in a different
way. Name of all these packages starts with "pcsc-".
%package -n pcsc-openct
Summary: PC/SC IFD Handler for OpenCT Smart Card Drivers
Group: Productivity/Security
%description -n pcsc-openct
PC/SC Connector for OpenCT. It allows to use any of OpenCT Smart Card
drivers with the PCSC-Lite daemon from the pcsc-lite package.
OpenCT is a set of library and tools to talk to smart card readers.
OpenCT is used by the OpenSC Smart Card library.
For a list of supported readers, please read documentation in
%{_docdir}/openct/wiki/index.html - some readers may be
supported only with particular firmware or particular connection type.
There are other packages that may support your reader in a different
way. Name of all these packages starts with "pcsc-".
%package devel
Summary: Library for Smart Card Readers
Group: Development/Libraries/C and C++
Requires: glibc-devel
Requires: libopenct1 = %{version}
%description devel
OpenCT is a set of library and tools to talk to smart card readers.
OpenCT is used by the OpenSC Smart Card library.
For a list of supported readers, please read documentation in
%{_docdir}/openct/wiki/index.html - some readers may be
supported only with particular firmware or particular connection type.
There are other packages that may support your reader in a different
way. Name of all these packages starts with "pcsc-".
%prep
%setup -q
cp -a %{SOURCE2} .
%patch1
%patch2 -p1
%if 0%{?has_systemd}
%patch3 -p1
%endif
%patch4 -p1
%patch5 -p1
sed -i 's/@USER@/%{USER}/g;s/@GROUPID@/%{GROUPID}/g' etc/init-script.in
tr -d \\r <doc/nonpersistent/wiki.out/trac.css >doc/nonpersistent/wiki.out/trac.css.unix
touch -r doc/nonpersistent/wiki.out/trac.css doc/nonpersistent/wiki.out/trac.css.unix
mv doc/nonpersistent/wiki.out/trac.css.unix doc/nonpersistent/wiki.out/trac.css
%build
%if 0%{?suse_version} > 1110
ACLOCAL="aclocal -I m4" autoreconf -f -i
%endif
%configure \
--docdir=%{_docdir}/%{name} \
--disable-static \
--enable-doc \
--enable-api-doc \
--enable-usb \
--enable-pcsc \
--enable-non-privileged \
--with-daemon-user=%{USER} \
--with-daemon-groups=%{GROUPID} \
--with-bundle=%{ifddir} \
--with-ifddir=%{ifddir} \
--with-udev=%{_udevdir}
make %{?_smp_mflags}
%install
mkdir -p %{buildroot}%{_sysconfdir}
make DESTDIR=%{buildroot} install %{?_smp_mflags}
# meanless to create on /run as it is tmpfs
%if 0%{?has_systemd}
mkdir -p "%{buildroot}%{_libexecdir}/tmpfiles.d/"
cat >%{buildroot}%{_libexecdir}/tmpfiles.d/%{name}.conf <<EOF
d %{_localstatedir}/run/%{name} 0755 %{USER} %{GROUPID}
EOF
%else
# Create directory
mkdir -p %{buildroot}%{_localstatedir}/run/openct
# NOTE: Example in the source recommends 750, but this value allows
# access only to dedicated users and root.
chmod 0755 %{buildroot}%{_localstatedir}/run/openct
%endif
# Install 60-openct.rules rule for udev
mkdir -p %{buildroot}%{_udevrulesdir}
install -m0644 etc/openct.udev %{buildroot}%{_udevrulesdir}/60-openct.rules
%if 0%{?has_systemd}
# add systemd services (based on http://blog.fraggod.net/2012/06/16/proper-ish-way-to-start-long-running-systemd-service-on-udev-event-device-hotplug.html)
install -D -m 0644 %{SOURCE5} %{buildroot}%{_unitdir}/%{name}.service
install -D -m 0644 %{SOURCE6} %{buildroot}%{_unitdir}/%{name}-handler@.service
ln -s service %{buildroot}%{_sbindir}/rcopenct
%else
# Install init script
mkdir -p %{buildroot}%{_sysconfdir}/init.d
install etc/init-script %{buildroot}%{_sysconfdir}/init.d/openct
ln -s ../..%{_sysconfdir}/init.d/openct %{buildroot}%{_sbindir}/rcopenct
%endif
#
# Copy the rest of documentation
cp LGPL-2.1 README.SUSE TODO doc/nonpersistent/ChangeLog etc/openct-disable.fdi %{buildroot}%{_docdir}/%{name}
# And remove pointless .la file
find %{buildroot} -type f -name "*.la" -delete -print
%pre
%if 0%{?has_systemd}
%service_add_pre %{name}.service openct-handler@.service
%endif
%preun
%{stop_on_removal openct}
%if 0%{?has_systemd}
%service_del_preun %{name}.service openct-handler@.service
%endif
%post
%if 0%{?has_systemd}
%service_add_post %{name}.service openct-handler@.service
systemd-tmpfiles --create %{_libexecdir}/tmpfiles.d/%{name}.conf
%else
%{fillup_and_insserv -y openct}
%endif
%postun
%if 0%{?has_systemd}
%service_del_postun %{name}.service openct-handler@.service
%else
%{restart_on_update openct}
%insserv_cleanup
%endif
%post -n libopenct1 -p /sbin/ldconfig
%postun -n libopenct1 -p /sbin/ldconfig
%files
%defattr(-,root,root)
%doc %dir %{_docdir}/%{name}
%doc %{_docdir}/%{name}/ChangeLog
%doc %{_docdir}/%{name}/LGPL-2.1
%doc %{_docdir}/%{name}/NEWS
%doc %{_docdir}/%{name}/README
%doc %{_docdir}/%{name}/README.SUSE
%doc %{_docdir}/%{name}/TODO
%doc %{_docdir}/%{name}/openct-disable.fdi
%doc %{_docdir}/%{name}/wiki
%{_bindir}/*
%doc %{_mandir}/man?/*.*
%{_sbindir}/*
%{_libdir}/libopenctapi.so
%config(noreplace) %{_sysconfdir}/openct.conf
# SLE11 needs it. Expansion from the preamble does not apply here:
%{!?_udevrulesdir: %define _udevrulesdir %{_udevdir}/rules.d}
%{_udevrulesdir}/60-openct.rules
%{_udevdir}/openct_*
%if 0%{?has_systemd}
%{_unitdir}/%{name}.service
%{_unitdir}/%{name}-handler@.service
%{_libexecdir}/tmpfiles.d/openct.conf
%else
%{_sysconfdir}/init.d/openct
%ghost %dir %{_localstatedir}/run/openct
%endif
%files -n libopenct1
%defattr(-,root,root)
%{_libdir}/*.so.*
%files -n pcsc-openct
%defattr(-,root,root)
%{ifddir}/openct-ifd.bundle
%files devel
%defattr(-,root,root)
%doc %{_docdir}/%{name}/api
%{_includedir}/openct
%{_libdir}/*.so
%exclude %{_libdir}/libopenctapi.so
%{_libdir}/pkgconfig/libopenct.pc
%changelog