File openarc.spec of Package openarc

# Copyright (c) 2010, 2011, 2016, 2017 The Trusted Domain Project.
# All rights reserved.

Summary:	An open source library and milter for providing ARC service
Name:		openarc
Version:	1.0.0.beta3
Release:	1
%define DebianRelease 3
Group:		System/Daemons
Requires:	libopenarc0 = %{version}-%{release}
BuildRequires:	openssl-devel, xz
Source:		%{name}_1.0.0~beta3.orig.tar.gz
Source1:	%{name}_1.0.0~beta3-%{DebianRelease}.debian.tar.xz
Source2:	rpmlintrc
BuildRoot:	%{_tmppath}/%{name}-%{version}-root
Prefix:		%{_prefix}

License:	BSD-2-Clause
URL:		https://openarc.org/
# as long as ./configure is not shipped...
BuildRequires:	automake
BuildRequires:	libtool
BuildRequires:	xz

######### SUSE ####################
%if 0%{?suse_version} >= 1200
PreReq: pwdutils
BuildRequires: sendmail-devel
BuildRequires: libbsd-devel
# https://en.opensuse.org/openSUSE:Systemd_packaging_guidelines
BuildRequires: systemd-rpm-macros
%{?systemd_requires}
%endif

######### Fedora #################
%if 0%{?fedora_version} >= 26
Requires: shadow-utils
BuildRequires: sendmail-milter-devel
BuildRequires: libbsd-devel
%endif

%if 0%{?fedora_version} > 27
# Package "system-release" exist as
# - fedora-modular-release
# - generic-release
# fedora-modular-release don't exist on build.opensuse.org
BuildRequires: generic-release
%endif

######### CentOS ################
%if 0%{?centos_version} >= 700
PreReq: shadow-utils
BuildRequires: sendmail-devel
BuildRequires: libbsd-devel
%endif

%description
The Trusted Domain Project is a community effort to develop and maintain a
C library for producing ARC-aware applications and an open source milter for
providing ARC service through milter-enabled MTAs.

%package -n libopenarc0
Summary: An open source ARC library
Group: System/Libraries

%description -n libopenarc0
This package contains the library files required for running services built
using libopenarc.

%package -n libopenarc-devel
Summary: Development files for libopenarc
Group: Development/Libraries/C and C++
Requires: libopenarc0 = %{version}
Requires: libbsd-devel

%description -n libopenarc-devel
This package contains the static libraries, headers, and other support files
required for developing applications against libopenarc.

%prep
%setup -n OpenARC-rel-openarc-1-0-0-Beta3
xz -cd %{S:1} | tar xf -
if [ -e debian/patches/series ]; then
  for p in $( cat debian/patches/series ); do
      echo "apply Patch debian/patches/$p ..."
      patch -p1 <  debian/patches/$p
  done
fi

%build
aclocal
autoreconf -i || :
CFLAGS="%{optflags} -fpie -fstack-protector"
CPPFLAGS="%{optflags} -fpie -fstack-protector"
LDFLAGS="-Wl,-z,relro,-z,now -pie"
export CFLAGS CPPFLAGS LDFLAGS
./configure --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} --mandir=%{_mandir} CPPFLAGS="$INCLUDES"
make

%install
make install DESTDIR="$RPM_BUILD_ROOT"
install -D -m 0644 contrib/systemd/%{name}.service %{buildroot}%{_unitdir}/%{name}.service
ln -s service %{buildroot}%{_sbindir}/rc%{name}

# BUG? remove macros from service file
sed -i -e 's|${prefix}||' -e 's|${exec_prefix}|/usr|' %{buildroot}%{_unitdir}/%{name}.service
# BUG? installed "doc files" have no content anyway...
rm -r "$RPM_BUILD_ROOT"%{_prefix}/share/doc/openarc/

install -p -d "$RPM_BUILD_ROOT"%{_sysconfdir}/
cat > "$RPM_BUILD_ROOT"%{_sysconfdir}/openarc.conf <<EOF
# Basic OpenARC config file
PidFile /run/openarc/openarc.pid
Syslog yes
UserID openarc:mail
#
Socket local:/run/openarc/openarc.socket
#
Domain example.com
Selector seal
KeyFile %{_sysconfdir}/openarc/seal.private
EOF

install -p -d "$RPM_BUILD_ROOT"/usr/lib/tmpfiles.d/
cat > "$RPM_BUILD_ROOT"/usr/lib/tmpfiles.d/%{name}.conf <<EOF
D /run/%{name} 0755 %{name} %{name} -
EOF

%pre
getent group  openarc >/dev/null || %{_sbindir}/groupadd -r openarc
getent passwd openarc >/dev/null || %{_sbindir}/useradd  -r -g openarc -d %{_localstatedir}/lib -s /bin/false -c "OpenARC daemon" openarc
getent group  mail    >/dev/null && %{_sbindir}/usermod  -G mail openarc
%if 0%{?suse_version} >= 1200
%service_add_pre openarc.service
%else
if [ -x /sbin/chkconfig ]; then
        /sbin/chkconfig --add openarc
elif [ -x /usr/lib/lsb/install_initd ]; then
        /usr/lib/lsb/install_initd openarc
fi
%endif

%post
if [ ! -d %{_sysconfdir}/openarc ]; then
  mkdir %{_sysconfdir}/openarc
  chmod o-rx %{_sysconfdir}/openarc
  openssl genrsa -out %{_sysconfdir}/openarc/seal.private
  chmod 0640 %{_sysconfdir}/openarc/seal.private
  chown -R openarc:openarc %{_sysconfdir}/openarc
fi
%tmpfiles_create %_tmpfilesdir/%{name}.conf
%service_add_post openarc.service
# enable the service
ln -s %{_unitdir}/%{name}.service %{_sysconfdir}/systemd/system/multi-user.target.wants/%{name}.service || :
# start the service
%{_sbindir}/rc%{name} start || :

%preun
%if 0%{?suse_version} >= 1200
%service_del_preun openarc.service
%else
if [ $1 = 0 ]; then
        service openarc stop && rm -f %{_localstatedir}/run/openarc/openarc.sock && rmdir %{_localstatedir}/run/openarc 2>/dev/null
        if [ -x /sbin/chkconfig ]; then
                /sbin/chkconfig --del openarc
        elif [ -x /usr/lib/lsb/remove_initd ]; then
                /usr/lib/lsb/remove_initd openarc
        fi
        userdel openarc
        if getent group openarc >/dev/null; then
                groupdel openarc
        fi
fi
%endif


%postun
%if 0%{?suse_version} >= 1200
%service_del_postun openarc.service
%endif

%post -n libopenarc0 -p /sbin/ldconfig

%postun -n libopenarc0 -p /sbin/ldconfig

%files
%defattr(-,root,root)
%doc LICENSE LICENSE.Sendmail README RELEASE_NOTES
%doc openarc/openarc.conf.sample openarc/openarc.conf.simple
%config(noreplace) %{_sysconfdir}/openarc.conf
%{_mandir}/*/*
%{_sbindir}/*
%if 0%{?suse_version} >= 1200
%{_unitdir}/%{name}.service
/usr/lib/tmpfiles.d/%{name}.conf
%else
/usr/lib/systemd/system/%{name}.service
/usr/lib/tmpfiles.d/%{name}.conf
%endif
%ghost /run/%{name}

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

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

%changelog
* Sat Dec 21 2019 <rpmbuild@openarc.org> - 1.0.0
- debian.postinst fixed
* Wed Oct 09 2019 <rpmbuild@openarc.org> - 1.0.0
- build https://github.com/trusteddomainproject/OpenARC/releases/tag/rel-openarc-1-0-0-Beta3
* Thu Aug  8 2019 <rpmbuild@openarc.org> - 1.0.0
- build from develop branch
* Mon May 27 2019 <rpmbuild@openarc.org> - 1.0.0
- fromdomains.patch
* Tue May 07 2019 <rpmbuild@openarc.org> - 1.0.0
- Version 1.0.0.Beta2
* Wed Aug 01 2018 <rpmbuild@openarc.org> - 1.0.0
- Fix https://github.com/trusteddomainproject/OpenARC/issues/100
- Fix https://github.com/trusteddomainproject/OpenARC/issues/102
* Thu Jul 26 2018 <rpmbuild@openarc.org> - 1.0.0
- Version 1.0.0.Beta0
* Thu Feb 22 2018 <rpmbuild@openarc.org> - 0.1.0
- SLES11 removed
- CentOS-7 added
* Fri Dec 08 2017 <rpmbuild@openarc.org> - 0.1.0
- build for SLES11
* Thu Dec 07 2017 <rpmbuild@openarc.org> - 0.1.0
- git checkout develop -> commit 495aff7 fix for
  https://github.com/trusteddomainproject/OpenARC/issues/47
* Wed Dec 06 2017 <rpmbuild@openarc.org> - 0.1.0
- git clone (latest commit  0b955c3 from 20171206
* Mon Nov 27 2017 <rpmbuild@openarc.org> - 20171127
- git clone (latest commit 8ee5d92 from 20171123)
* Thu Nov 09 2017 <rpmbuild@openarc.org> - 20171109
- postinst: don't require packager's staff
* Fri Oct 13 2017 <rpmbuild@openarc.org> - 20171013
- git clone (latest commit 1bb9999 from 20171012)
* Fri Sep 15 2017 <rpmbuild@openarc.org> - 20170915
- git clone (latest commit 942cd16 from 20170913)
* Tue Sep 12 2017 <rpmbuild@openarc.org> - 20170912
- git clone
* Thu Aug 03 2017 <rpmbuild@openarc.org> - 20170803
- git clone, https://github.com/mskucherawy/OpenARC/commit/b3faba121c07bce32d04895ee1c9f4278669a835
* Sun Jul 30 2017 <rpmbuild@openarc.org> - 20170730
- specfile for openSuSE:Leap:42.3