File sks.spec of Package sks

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

%if 0%{?suse_version} > 1230 || 0%{?rhel_version} > 6 || 0%{?centos_version} > 6 || 0%{?fedora_version} >= 20 || 0%{?el7}%{?fc20}%{?fc21}%{?fc22}
%bcond_without systemd
%else
%bcond_with    systemd
%endif

Name:           sks
Version:        1.1.6
Release:        0
License:        GPL-2.0+
Summary:        Synchronizing Key Server
Group:          System/Daemons
URL:            https://bitbucket.org/skskeyserver/sks-keyserver
Source:         https://bitbucket.org/skskeyserver/sks-keyserver/downloads/sks-%{version}.tgz
Source1:        sks-db.service
Source2:        sks-recon.service
Source3:        sks.logrotate
Source4:        cryptokit-1.7-uint32.patch
Source5:        apparmor-usr.bin.sks
Source6:        apparmor-usr.bin.sks-local
Source7:        sks-rpmlintrc
Patch0:         sks-1.1.5-cflags.patch
Patch1:         sks-1.1.5-sks_build.patch
Patch2:         sks-1.1.6-cryptokit-1.7-Makefile.patch
Recommends:     logrotate
BuildRequires:  apparmor-profiles
BuildRequires:  db-devel >= 4.8
BuildRequires:  ncurses-devel
BuildRequires:  ocaml
BuildRequires:  ocaml-camlp4-devel
BuildRequires:  zlib-devel
Requires(pre):  /usr/sbin/groupadd 
Requires(pre):  /usr/sbin/useradd
%if %{with systemd}
BuildRequires:  pkgconfig(systemd)
%{?systemd_requires}
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%define homedir   /srv/sks/
%define configdir /etc/sks
%define sksuser   _sks
%define sksgroup  _sks

%description
SKS is a OpenPGP keyserver which provides reliable decentralized
synchronization.

%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1

%build
echo LIBDB="-ldb-4.8" >> Makefile.local
echo OPTFLAGS="%{optflags}" >> Makefile.local
make dep
install -m 0644 %{SOURCE4} .
make all
make all.bc # if you want the bytecode versions

%install
make install PREFIX=%{buildroot}%{_prefix} MANDIR=%{buildroot}%{_mandir}
install -D -d -m 0750 %{buildroot}%{homedir} %{buildroot}%{configdir}
%if %{with systemd}
install -D -d -m 0755 %{buildroot}%{_unitdir}/ %{buildroot}%{_sbindir}
sed -e "s/__SKSGROUP__/%{sksgroup}/g;" \
    -e "s/__SKSUSER__/%{sksuser}/g;" %{SOURCE1} > %{buildroot}%{_unitdir}/sks-db.service
sed -e "s/__SKSGROUP__/%{sksgroup}/g;" \
    -e "s/__SKSUSER__/%{sksuser}/g;" %{SOURCE2} > %{buildroot}%{_unitdir}/sks-recon.service
%if 0%{?suse_version}
%{__ln_s} -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-db
%{__ln_s} -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-recon
%endif
%endif
chmod a-x %{buildroot}%{_mandir}/man8/sks.8*
find sample* -name \*.orig -print -delete
cp sampleConfig/sksconf.typical %{buildroot}%{configdir}/sksconf
cp sampleConfig/membership %{buildroot}%{configdir}/membership
cp sampleConfig/mailsync %{buildroot}%{configdir}/mailsync
cd %{buildroot}%{homedir}
for config in sksconf membership mailsync ; do
    ln -s %{configdir}/$config .
done
mkdir -p %{buildroot}/%{_var}/log/%{name}  %{buildroot}%{_sysconfdir}/logrotate.d
for logfile in recon.log db.log build.log clean.log pbuild.log; do
	touch %{buildroot}/%{_var}/log/%{name}/$logfile
	cd %{buildroot}%{homedir}
	ln -s %{_var}/log/%{name}/$logfile .
done
sed -e "s/__SKSGROUP__/%{sksgroup}/g;" \
    -e "s/__SKSUSER__/%{sksuser}/g;" %{SOURCE3} > %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
# apparmor profile
install -Dm0644 %{SOURCE6} %{buildroot}%{_sysconfdir}/apparmor.d/local/usr.bin.sks
install -m0644  %{SOURCE5} %{buildroot}%{_sysconfdir}/apparmor.d/usr.bin.sks

%pre
/usr/sbin/groupadd -r %{sksgroup} >/dev/null 2>&1 || :
/usr/sbin/useradd -g %{sksgroup} -s /bin/false -r -c "sks key server" -d "%{homedir}" %{sksuser} >/dev/null 2>&1 || :
# START BIG SYSTEMD
%if %{with systemd}
%service_add_pre sks-db.service  sks-recon.service
%endif

%preun
%if %{with systemd}
%service_del_preun sks-db.service  sks-recon.service
%endif

%post
%if %{with systemd}
%service_add_post sks-db.service  sks-recon.service
%endif

%postun
%if %{with systemd}
%service_del_postun sks-db.service  sks-recon.service
%endif


%files
%defattr(-,root,root)
%doc ANNOUNCEMENT BUGS CHANGELOG LICENSE README.md TODO UPGRADING VERSION
%doc sample*/
%config(noreplace) %attr(-,root,%{sksgroup}) %{configdir}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %{_sysconfdir}/apparmor.d/local/usr.bin.sks
%config %{_sysconfdir}/apparmor.d/usr.bin.sks
%{_sbindir}/rc*
%{_bindir}/sks
%{_bindir}/sks_add_mail
%{_bindir}/sks_build.sh
%{_mandir}/man8/sks.8*
%if %{with systemd}
%{_unitdir}/%{name}*.service
%endif
%dir %attr(-,%{sksuser},%{sksgroup}) %{_var}/log/%{name}
%attr(-,%{sksuser},%{sksgroup}) %{_var}/log/%{name}/*
%dir %attr(-,%{sksuser},%{sksgroup}) %{homedir}
%{homedir}/sksconf
%{homedir}/mailsync
%{homedir}/membership
%{homedir}/*.log

%changelog
openSUSE Build Service is sponsored by