File cfengine.spec of Package cfengine

# spec file for package cfengine
# Copyright (c) 2015 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

%define srcname %{name}-%{version}
%define libname   libpromises
%define libsoname %{libname}3
# Yes, its not FHS conformant but in sync with cfengine documentation
# reported upstream as
%define         basedir   %{_localstatedir}/%{name}
%define         workdir   %{basedir}
%if 0%{?suse_version} >= 1210
%define have_systemd 1
%define have_systemd 0
# pass --with-bla to enable the build
%bcond_with mysql
%bcond_with postgresql
%bcond_with libvirt
Name:           cfengine
Version:        3.7.1
Release:        0
# This is the place where workdir should be
#define         basedir   /var/lib/%{name}
#define         workdir   %{basedir}/work
Summary:        CFEngine automates large-scale IT computing infrastructure
License:        GPL-3.0
Group:          Productivity/Networking/System
Source:         %{srcname}.tar.gz
Source1:        %{name}.SuSEfirewall2
Source10:       %{name}.cron
Source11:       %{name}-rpmlintrc
# docs
# SLE 11 or RHEL5 autoconf does not support AM_SUBST_NOTMAKE,
Patch2:         remove-am_subst_notmake.patch
# PATCH-FIX-UPSTREAM add 'suse' class for consistency with other vendor classes
# PATCH-FEATURE-UPSTREAM better /etc/SuSE-release parsing, upstream #5423
Patch5:         0001-Simplify-and-fix-parsing-of-etc-SuSE-release-fixes-i.patch
# set cfengine's notion of bindir to /usr/sbin instead of /var/cfengine/bin
Patch6:         0001-Set-sys.bindir-to-usr-sbin-expect-cf-components-ther.patch

BuildRequires:  bison
BuildRequires:  db-devel
BuildRequires:  flex
BuildRequires:  libacl-devel
BuildRequires:  libtool
BuildRequires:  libxml2-devel
BuildRequires:  lmdb-devel
BuildRequires:  openssl-devel
BuildRequires:  pam-devel
BuildRequires:  pcre-devel
%if 0%{?suse_version} == 0
# for testing on RHEL/Fedora
BuildRequires:  fakeroot
Requires:       %{libsoname} = %{version}
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if %{have_systemd}
Source7:        cf-execd.service
Source8:        cf-monitord.service
Source9:        cf-serverd.service
Source7:        cf-monitord
Source8:        cf-execd
Source9:        cf-serverd
%if %{with mysql}
BuildRequires:  mysql-devel
%if %{with libvirt}
BuildRequires:  libvirt-devel
%if %{with postgresql}
BuildRequires:  postgresql-devel
%if %{have_systemd}
BuildRequires:  systemd
# Without systemd we require cron
Requires:       cron
%if 0%{?suse_version}
Requires(post): %insserv_prereq %fillup_prereq
# FHS was a hit with sle11 so it dies out otherwise
%if 0%{?suse_version} <= 1110
BuildRequires:  -post-build-checks
%if 0%{?suse_version} > 1020
BuildRequires:  fdupes
%if 0%{?fedora_version} == 20
BuildRequires:  perl-Exporter

CFEngine is the core of a configuration management system: ensuring
the availability, security and compliance of mission-critical
applications and services. Based on popular and flexible open source
configuration management software, CFEngine configuration management
products are highly scalable through decentralized, autonomous agents
that can continuously monitor, self-repair, and update the IT
infrastructure of a global multi-site enterprise - with negligible
impact on system resources or performance.

%package -n %{libsoname}
Summary:        Shared library of cfengine
Group:          System/Libraries
Provides:       %{libname}1 = %{version}
Obsoletes:      %{libname}1 < %{version}

%description -n %{libsoname}
This package contains the shared libpromises (cfengine) library.

%package -n %{libname}-devel
Summary:        Development package for libpromises
Group:          Development/Libraries/C and C++
Requires:       %{libsoname} = %{version}
Requires:       glibc-devel
Provides:       %{name}-devel = %{version}
Obsoletes:      %{name}-devel < %{version}

%description -n %{libname}-devel
A high-speed character set detection library

This package contains the files needed to compile programs that use the
libpromises library.

%package doc
Summary:        CFEngine automates large-scale IT computing infrastructure - documentation
Group:          Documentation/Other

%description doc
Full documentation for cfengine

%package examples
Summary:        CFEngine example promises
Group:          Documentation/Other

%description examples
Lots of examples promises for CFEngine.

%setup -q -n %{srcname}
%if 0%{?suse_version} <= 1110
%patch2 -p1
%patch5 -p1
%patch6 -p1

##### rpmlint
#### wrong-file-end-of-line-encoding
#### incorrect-fsf-address
find ./examples -type f -name "*.cf" -exec perl -p -i -e 's|\r\n|\n|,s|^# Foundation.*|# Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA|' {} \;

### install extra docs
install -d docs
cp -a $RPM_SOURCE_DIR/*pdf docs/

autoreconf -fvi -I m4
# /usr/include/sys for acl.h
CC=cc CFLAGS="%{optflags} -fno-strict-aliasing" \
%configure \
  --disable-static \
  --disable-silent-rules \
  --enable-fhs \
  --datadir=/var \
  --with-workdir=%{workdir} \
%if %{with postgresql}
  --with-postgresql \
%if %{with mysql}
  --with-mysql \
  --without-qdbm \
  --without-tokyocabinet \
  --with-lmdb \
  --with-pthreads \
  --with-openssl \
  --with-pcre \
%if %{with libvirt}
  --with-libvirt \
  --with-libacl \
  --with-libxml2 \
%if 0%{?rhel_version} > 0 && 0%{?rhel_version} < 700
  --docdir=%{_docdir}/%{name}-%{version} \
  --docdir=%{_docdir}/%{name} \

make %{?_smp_mflags}

# FAIL: process_test
make check %{?_smp_mflags} || : 

chmod -x ChangeLog
make "DESTDIR=%{buildroot}" install

# will appear in cfengine-examples
rm -rf %{buildroot}/%{_docdir}/%{name}/examples

install -d %{buildroot}/{usr/sbin,%{workdir}/{bin,inputs,reports}}

# create dirs needed for better organizing dirs and files
install -d %{buildroot}/%{basedir}/{backup,failsafe,config,plugins}

%if %{have_systemd}
# systemd: install sample cron file in docdir
install -D -m0644 %{SOURCE10} %{buildroot}/%{_docdir}/%{name}
# no systemd -> use cron
# install cron file
install -D -m0644 %{SOURCE10} %{buildroot}/%{_sysconfdir}/cron.d/%{name}

%if %{have_systemd}
# install systemd scripts
install -D -m 0644 %{SOURCE7} %{buildroot}/%{_unitdir}/cf-execd.service
install -D -m 0644 %{SOURCE8} %{buildroot}/%{_unitdir}/cf-monitord.service
install -D -m 0644 %{SOURCE9} %{buildroot}/%{_unitdir}/cf-serverd.service
ln -s -f service %{buildroot}/%{_sbindir}/rccf-monitord
ln -s -f service %{buildroot}/%{_sbindir}/rccf-execd
ln -s -f service %{buildroot}/%{_sbindir}/rccf-serverd
# install init scripts
install -d %{buildroot}%{_initddir}
install -m 0755 %{SOURCE7} %{SOURCE8} %{SOURCE9} %{buildroot}%{_initddir}/
ln -s -f ../..%{_initddir}/cf-monitord %{buildroot}/%{_sbindir}/rccf-monitord
ln -s -f ../..%{_initddir}/cf-execd %{buildroot}/%{_sbindir}/rccf-execd
ln -s -f ../..%{_initddir}/cf-serverd %{buildroot}/%{_sbindir}/rccf-serverd
# sed @workdir@ in initscripts/cron.d
sed -i\
 -e "s,@workdir@,%{workdir},g"\
 -e "s,@basedir@,%{basedir},g" \
 %{buildroot}%{_initddir}/cf-* %{buildroot}%{_sysconfdir}/cron.d/%{name}

# create symlinks for sbin_PROGRAMS
# because: cf-promises needs to be installed in /var/cfengine/work/bin for pre-validation of full configuration
for i in cf-agent cf-execd cf-key cf-monitord cf-promises cf-runagent cf-serverd cf-upgrade; do
  ln -s -f ../../..%{_sbindir}/${i} %{buildroot}%{workdir}/bin/${i}

rm -rf %{buildroot}/%{_libdir}/%{name}/

# will appear in %%docdir
rm -rf %{buildroot}/%{_datadir}/%{name}/ChangeLog
rm -rf %{buildroot}/%{_datadir}/%{name}/README

# create man pages, see
install -d %{buildroot}/%{_mandir}/man8
for i in cf-agent cf-execd cf-key cf-monitord cf-promises cf-runagent cf-serverd
  LD_LIBRARY_PATH=%{buildroot}%{_libdir}/%{name} %{buildroot}%{_sbindir}/$i -M > %{buildroot}%{_mandir}/man8/$i.8
  gzip %{buildroot}%{_mandir}/man8/$i.8

# Firewall
install -D -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/cfengine

# Ckeabyo dyoes
%if 0%{?suse_version} > 1020
%fdupes %{buildroot}%{_datadir}/cfengine

%if %{have_systemd}
%service_add_pre cf-execd.service cf-monitord.service cf-serverd.service

%if %{have_systemd}
%service_add_post cf-execd.service cf-monitord.service cf-serverd.service
for i in execd monitord serverd; do
  %fillup_and_insserv cf-${i}
if [ $1 -lt 2 ]; then
  # first install, generate key pair

%if %{have_systemd}
%service_del_preun cf-execd.service cf-monitord.service cf-serverd.service
for i in execd monitord serverd; do
  %stop_on_removal cf-${i}

%if %{have_systemd}
%service_del_postun cf-execd.service cf-monitord.service cf-serverd.service
for i in execd monitord serverd; do
  %restart_on_update cf-${i}
if [ $1 -eq 0 ]; then
  # clean up inputs cache dir on removal
  rm -rf %{basedir}/inputs/*

%post   -n %{libsoname} -p /sbin/ldconfig

%postun -n %{libsoname} -p /sbin/ldconfig

%doc ChangeLog LICENSE
%if %{have_systemd}
%config %attr(0755,root,root) %{_initddir}/*
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/cfengine
%dir %{basedir}
%dir %{workdir}
%if !%{have_systemd}
%config(noreplace) %{_sysconfdir}/cron.d/%{name}

%files -n %{libsoname}
%dir %{_libdir}/%{name}

%files -n %{libname}-devel

%files doc
%doc docs/*.pdf

%files examples
%doc examples/*cf