File c-icap.spec of Package c-icap

#
# spec file for package c-icap
#
# Copyright 2013-2014 by Lars Vogdt <lars@linux-schulserver.de>
#
# 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.


%{!?_rundir: %{expand: %%global _rundir %{_localstatedir}/run}}
Name:           c-icap
Version:        0.3.5
%define         lib_vers 3
Release:        1
License:        LGPL-2.1+ and public-domain and GPL-2.0+
Summary:        Implementation of an ICAP server
Url:            http://c-icap.sourceforge.net/
Group:          Development/Libraries/C and C++
Source:         http://switch.dl.sourceforge.net/sourceforge/c-icap/c_icap-%{version}.tar.gz
Source1:        %{name}.init
Source2:        %{name}-rpmlintrc
Source3:        %{name}.logrotate
Source4:        %{name}.service
Source5:        %{name}.tmpfiles
# PATCH-FIX-openSUSE -- Use user and group 'c-icap' explicitely
Patch3:         c-icap-use_c-icap_user_and_group_in_config.patch
Patch4:         c_icap-0.3.2_libexec_handling.patch
Patch5:         c_icap-0.3.2-missing-call-to-setgroups-before-setuid.patch
# PATCH-FIX-UPSTREAM -- CONF variable is poluting namespace - as does openssl too but openssl is bigger
Patch6:         c_icap-0.3.5-rename_CONF_to_IC_CONF.patch
PreReq:         %insserv_prereq
PreReq:         pwdutils
PreReq:         grep
PreReq:         coreutils
Requires:       libicapapi%{lib_vers} = %{version}
BuildRequires:  gcc-c++
BuildRequires:  glibc-devel
BuildRequires:  libtool
BuildRequires:  zlib-devel
BuildRequires:  db-devel
BuildRequires:  libbz2-devel 
BuildRequires:  openldap2-devel
Recommends:     squid >= 3
Recommends:     logrotate
Recommends:     c-icap-modules
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%define         icap_user c-icap
%define         icap_group c-icap
%if 0%{?suse_version} >= 1210
BuildRequires:  systemd
%{?systemd_requires}
%endif

%description
c-icap is an implementation of an ICAP server. It can be used with HTTP proxies
that support the ICAP protocol to implement content adaptation and filtering
services.

Most of the commercial HTTP proxies must support the ICAP protocol. The open
source Squid 3.x proxy server supports it.

%package -n libicapapi%{lib_vers}
Summary:        ICAP API library
Group:          Development/Libraries/C and C++

%description -n libicapapi%{lib_vers}
This Package contains the ICAP API library.


%package devel
Summary:        Include headers for c-icap
Group:          Development/Libraries/C and C++
Requires:       %{name} = %{version}

%description devel
This package contains the ICAP API library development files.


%prep
%setup -q -n c_icap-%{version}
%patch3 -p1
%patch4 -p1
%patch5 -p1
sed -i "s|/usr/local/c-icap/etc|%{_sysconfdir}/%{name}|g; \
        s|@prefix@/etc/c-icap.magic|%{_sysconfdir}/%{name}/c-icap.magic|g; \
        s|/var/tmp|/tmp|g; \
        s|@prefix@/lib/c_icap|@libexecdir@/c_icap|g; \
        s|@prefix@/var/log/|/var/log/%{name}/|g;" \
        c-icap.conf.in
%patch6

%build
autoreconf -fi
export CFLAGS="%{optflags} -fno-strict-aliasing"
%configure --prefix=%{_prefix} --sysconfdir=%{_sysconfdir}/%{name} \
           --libdir=%{_libdir} \
           --libexecdir=%{_prefix}/lib \
           --enable-large-files \
           --enable-ipv6 \
           --enable-sysvipc
%{__make} %{?_smp_mflags}

%install
make INSTALL_ROOT="%{buildroot}" DESTDIR="%{buildroot}" install
%{__mkdir} -p %{buildroot}%{_sbindir}
%{__install} -Dm 0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
mkdir -p %{buildroot}/%{_datadir}/c_icap/templates/
mkdir -p %{buildroot}/var/log/%{name}
%if 0%{?suse_version} >= 1210
%{__install} -Dm 0644 %{SOURCE4} %{buildroot}%{_unitdir}/%{name}.service
%{__install} -Dm 0644 %{SOURCE5} %{buildroot}/usr/lib/tmpfiles.d/%{name}.conf
%{__ln_s} -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%else
mkdir -p %{buildroot}%{_rundir}/%{name}
%{__install} -Dm 0755 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/%{name}
%{__ln_s} -f %{_sysconfdir}/init.d/%{name} %{buildroot}%{_sbindir}/rc%{name}
%endif

%clean
%{__rm} -rf %{buildroot}

%post -n libicapapi%{lib_vers} -p /sbin/ldconfig

%postun -n libicapapi%{lib_vers} -p /sbin/ldconfig

%pre 
%{_bindir}/getent group %{icap_group} >/dev/null || %{_sbindir}/groupadd -r %{icap_group} || :
%{_bindir}/getent passwd %{icap_user} >/dev/null || %{_sbindir}/useradd -r -d %{_localstatedir}/lib/%{icap_user} -s /bin/false -c "ICAP server user" -g %{icap_group} %{icap_user} || :
%if 0%{?suse_version} >= 1210
%service_add_pre %{name}.service
%endif

%post 
%if 0%{?suse_version} >= 1210
systemd-tmpfiles --create /usr/lib/tmpfiles.d/%{name}.conf
%service_add_post %{name}.service
%else
%{fillup_and_insserv %{name}}
%endif

%preun
%if 0%{?suse_version} >= 1210
%service_del_preun %{name}.service
%else
%stop_on_removal %{name}
%endif

%postun
%if 0%{?suse_version} >= 1210
%service_del_postun %{name}.service
%else
%restart_on_update %{name}
%{insserv_cleanup}
%endif

%files
%defattr(-,root,root)
%doc AUTHORS COPYING README contrib
%dir %{_prefix}/lib/c_icap
%dir %{_sysconfdir}/%{name}
%dir %{_datadir}/c_icap
%dir %{_datadir}/c_icap/templates
%{_bindir}/*
%exclude %{_bindir}/c-icap-libicapapi-config
%exclude %{_bindir}/c-icap-config
%{_mandir}/man8/*
%exclude %{_mandir}/man8/c-icap-config.8*
%exclude %{_mandir}/man8/c-icap-libicapapi-config.8*
%attr(644,root,root) %config(noreplace) %{_sysconfdir}/%{name}/c-icap.conf
%attr(644,root,root) %config(noreplace) %{_sysconfdir}/%{name}/*.magic
%attr(644,root,root) %config %{_sysconfdir}/%{name}/*.default
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%{_prefix}/lib/c_icap/*.so
%{_prefix}/lib/c_icap/*.la
%attr(-,%{icap_user},%{icap_group}) /var/log/%{name}
%{_sbindir}/rc%{name}
%if 0%{?suse_version} >= 1210
%_unitdir/%{name}.service
/usr/lib/tmpfiles.d/%{name}.conf
%else
%{_sysconfdir}/init.d/%{name}
%endif
%ghost %attr(-,%{icap_user},%{icap_group}) %{_rundir}/%{name}

%files -n libicapapi%{lib_vers}
%defattr(-,root,root)
%exclude %{_libdir}/libicapapi.la
%{_libdir}/libicapapi.so.*

%files devel
%defattr(-,root,root)
%{_bindir}/c-icap-libicapapi-config
%{_bindir}/c-icap-config
%{_mandir}/man8//c-icap-config.8*
%{_mandir}/man8/c-icap-libicapapi-config.8*
%dir %{_includedir}/c_icap
%{_includedir}/c_icap/*.h
%exclude %{_libdir}/libicapapi.la
%{_libdir}/libicapapi.so

%changelog
openSUSE Build Service is sponsored by