File squidGuard.spec of Package squidGuard

#
# spec file for package squidGuard
#
# Copyright (c) 2018 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/
#


%define sg_dbhome %{_localstatedir}/lib/squidGuard/db
%define sg_logdir %{_localstatedir}/log/squidGuard
%define sg_config %{_sysconfdir}/squidguard.conf
%define cgidir    /srv/www/cgi-bin
%define imgdir    /srv/www/htdocs/images

Name:           squidGuard
Version:        1.4
Release:        0
Summary:        Filter plugin for squid
License:        GPL-2.0-only
Group:          Productivity/Networking/Web/Proxy
Url:            http://www.squidguard.org/
Source0:        %{name}-%{version}.tar.bz2
Source1:        README.SUSE
Source2:        squidGuard.logrotate
Source3:        blocked.gif
Patch0:         squidGuard-Makefile.patch
Patch1:         squidGuard-1.4-mysql.patch
Patch2:         squidGuard-config.patch
Patch5:         squidGuard-CVE-2009-3700.patch
Patch6:         squidGuard-CVE-2009-3826.patch
Patch7:         xss_fix_02_2015.patch
Patch8:         squidGuard-1.4_upgrade.patch
Patch9:         default_config_pathfixes.patch
Patch10:        type_fixes.patch
BuildRequires:  bison
BuildRequires:  db-devel
BuildRequires:  flex
BuildRequires:  gettext
BuildRequires:  grep
BuildRequires:  libmysqlclient-devel
BuildRequires:  libtool
BuildRequires:  openldap2-devel
Requires:       http_proxy
Requires(pre):  http_proxy
Recommends:     logrotate
Recommends:     lynx

%description
SquidGuard is a filter, redirector, and access controller plugin for squid.
It lets you define multiple access rules with different restrictions for
different user groups on a squid cache. SquidGuard uses squid's standard
redirector interface.

%package doc
Summary:        Documentation and examples for squidGuard
Group:          Documentation/Other

%description doc
This package contains documentation for SquidGuard, a filter, redirector,
and access controller plugin for squid.

%prep
%setup -q
# remove autogenerated stuff
rm src/sgDiv.c contrib/sgclean/sgclean
%patch0
%patch1 -p1
%patch2
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
find -type d | xargs chmod 755
cp %{SOURCE1} .
# patch the test configs
pushd test 1>/dev/null
for i in test*.conf.in; do
	sed "s|logdir @TESTDIR@|logdir %{sg_logdir}|; \
		 s|dbhome @TESTDIR@|dbhome %{sg_dbhome}|" $i > $i.tmp
	mv -v $i.tmp $i
done

%build
gettextize
%configure \
	--with-squiduser=squid \
	--with-mysql \
	--with-nolog=yes \
	--with-db-inc=%{_includedir}/db4 \
	--with-sg-config=%{sg_config} \
	--with-sg-dbhome=%{sg_dbhome} \
	--with-sg-logdir=%{sg_logdir} \
	--with-ldap
make %{?_smp_mflags}
pushd contrib
make %{?_smp_mflags}
popd

%install
mkdir %{buildroot}%{_sysconfdir}
%make_install
# fix install dir
if [ -f %{buildroot}/%{_bindir}/squidGuard ]; then
	mkdir -p %{buildroot}/%{_sbindir}
	install -m755 %{buildroot}/%{_bindir}/squidGuard  %{buildroot}/%{_sbindir}/
	rm -rf %{buildroot}/%{_bindir}
fi
# install blacklist
mkdir -p %{buildroot}%{_localstatedir}/lib/squidGuard/db/blacklist
install -m 644 test/blacklist/* %{buildroot}%{_localstatedir}/lib/squidGuard/db/blacklist
# install cgi
mkdir -p %{buildroot}/%{cgidir}
mkdir -p %{buildroot}/%{imgdir}
install -m755 samples/*.cgi  %{buildroot}/%{cgidir}/
install -m644 samples/babel* %{buildroot}/%{cgidir}/
install -m644 %{SOURCE3}         %{buildroot}/%{imgdir}/blocked.gif
# prepare logdir
mkdir -p %{buildroot}%{sg_logdir}
# prepare logrotate
mkdir -p %{buildroot}%{_sysconfdir}/logrotate.d
sed "s|@SG_LOGDIR@|%{sg_logdir}|g" %{SOURCE2} > %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
# clean up
rm -f {contrib,doc,samples,test}/{Makefile,*.in,*/*.in,.*.swp}
# install docu
mkdir -p %{buildroot}/%{_defaultdocdir}/%{name}
cp -r {contrib,doc,samples,test} %{buildroot}/%{_defaultdocdir}/%{name}/
cp ANNOUNCE CHANGELOG FAQ ISSUES.txt README* %{buildroot}/%{_defaultdocdir}/%{name}/

%files
%license GPL COPYING
%dir %{_defaultdocdir}/%{name}
%doc %{_defaultdocdir}/%{name}/ANNOUNCE
%doc %{_defaultdocdir}/%{name}/CHANGELOG
%doc %{_defaultdocdir}/%{name}/FAQ
%doc %{_defaultdocdir}/%{name}/ISSUES.txt
%doc %{_defaultdocdir}/%{name}/README*
%attr(770, squid, squid) %dir %{_localstatedir}/lib/squidGuard
%attr(770, squid, squid) %dir %{sg_dbhome}
%attr(770, squid, squid) %dir %{sg_logdir}
%config(noreplace) %attr(660, squid, squid) %{sg_config}
%config(noreplace) %attr(660, squid, squid) %{_localstatedir}/lib/squidGuard/db/blacklist
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%{_sbindir}/*
%dir %{imgdir}
%{cgidir}/*
%{imgdir}/*

%files doc
%license GPL COPYING
%doc %{_defaultdocdir}/%{name}/contrib
%doc %{_defaultdocdir}/%{name}/doc
%doc %{_defaultdocdir}/%{name}/samples
%doc %{_defaultdocdir}/%{name}/test

%changelog