File privoxy.spec of Package privoxy.openSUSE_13.1_Update

#
# spec file for package privoxy
#
# Copyright (c) 2013 SUSE LINUX Products 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} > 1210
%define with_systemd 1
%else
%define with_systemd 0
%endif

%if %{with_systemd}
%if 0%{?suse_version} < 1230
%define _unitdir /lib/systemd/system
%else
%define _unitdir /usr/lib/systemd/system
%endif
%endif

Name:           privoxy
BuildRequires:  automake
BuildRequires:  pcre-devel
BuildRequires:  w3m
BuildRequires:  zlib-devel
%if %{with_systemd}
BuildRequires:  systemd
%endif
Url:            http://www.privoxy.org/
Provides:       ijb
Provides:       junkbuster
Obsoletes:      ijb
Obsoletes:      junkbuster
%if %{with_systemd}
%{?systemd_requires}
PreReq:         /usr/sbin/useradd /usr/sbin/groupadd
%else
PreReq:         %fillup_prereq %insserv_prereq /usr/sbin/useradd /usr/sbin/groupadd
%endif
Version:        3.0.21
Release:        0
Summary:        The Internet Junkbuster - HTTP Proxy Server
License:        GPL-2.0+
Group:          Productivity/Networking/Web/Proxy
Source:         %{name}-%{version}-stable-src.tar.gz
%if %{with_systemd}
Source1:        %{name}.logrotate.systemd
%else
Source1:        %{name}.logrotate
%endif
Source2:        %{name}-3.0.16-init.suse
Source3:        %{name}.service
Patch1:         %{name}-3.0.21-config.patch
Patch2:         %{name}-3.0.17-utf8.patch
%if %{with_systemd}
Patch3:         %{name}-3.0.16-networkmanager.systemd.patch
%else
Patch3:         %{name}-3.0.16-networkmanager.patch
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Requires:       cron
Requires:       logrotate
%define chroot /var/lib/privoxy

%description
The Internet Junkbuster - HTTP Proxy Server: A non-caching HTTP proxy
server that runs between a web browser and a web server and filters
contents as described in the configuration files.

%package doc
Summary:        The documentation of Privoxy
Group:          Productivity/Networking/Web/Proxy
Requires:       %{name} = %{version}

%description doc
Documentation files for the Privoxy: The Internet Junkbuster - HTTP
Proxy Server. A non-caching HTTP proxy server that runs between a web
browser and a web server and filters contents as described in the
configuration files.

%prep
%setup -q -n privoxy-%{version}-stable
%patch1
%patch2 -p0
%patch3

%build
autoreconf -fiv
%configure --enable-zlib
make

%install
%if %{with_systemd}
mkdir -p $RPM_BUILD_ROOT/%{_unitdir}
%else
mkdir -p $RPM_BUILD_ROOT/etc/init.d
%endif
mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d
mkdir -p $RPM_BUILD_ROOT/%chroot/etc
mkdir -p $RPM_BUILD_ROOT/usr/sbin
mkdir -p $RPM_BUILD_ROOT/%chroot/log
mkdir -p $RPM_BUILD_ROOT/%chroot/var/log
mkdir -p $RPM_BUILD_ROOT/%chroot/var/run
mkdir -p $RPM_BUILD_ROOT/%chroot/%_lib
mkdir -p $RPM_BUILD_ROOT%_mandir/man1
mkdir -p $RPM_BUILD_ROOT/etc/NetworkManager/dispatcher.d
cp -a templates $RPM_BUILD_ROOT/%chroot/etc
install -m 644 config *.action *.filter trust $RPM_BUILD_ROOT/%chroot/etc
%if %{with_systemd}
sed -e 's/@lib@/%{_lib}/g' %{SOURCE3} > $RPM_BUILD_ROOT/%{_unitdir}/%{name}.service
%if 0%{?suse_version} >= 1310
ln -sf /usr/sbin/service $RPM_BUILD_ROOT/usr/sbin/rc%{name}
%else
ln -sf /sbin/service $RPM_BUILD_ROOT/usr/sbin/rc%{name}
%endif
%else
install -m 755 %{SOURCE2} $RPM_BUILD_ROOT/etc/init.d/privoxyd
ln -sf ../../etc/init.d/privoxyd $RPM_BUILD_ROOT/usr/sbin/rcprivoxyd
ln -sf ../../etc/init.d/privoxyd $RPM_BUILD_ROOT/usr/sbin/rcprivoxy
%endif
install -m 755 privoxy $RPM_BUILD_ROOT/usr/sbin
install -m 755 privoxy_nm $RPM_BUILD_ROOT/etc/NetworkManager/dispatcher.d/privoxyd
install -m 644 privoxy.1 $RPM_BUILD_ROOT%_mandir/man1
install -m 644 %{SOURCE1} $RPM_BUILD_ROOT/etc/logrotate.d/privoxy
ln -s ../../log $RPM_BUILD_ROOT/%chroot/var/log/privoxy
ln -sf %chroot/etc/ $RPM_BUILD_ROOT/etc/privoxy

%pre
%if %{with_systemd}
mkdir -p /var/lib/systemd/migrated || :
if test $1 -eq 1; then
  touch /var/lib/systemd/migrated/%{name} || :                        
else
  if test ! -e /var/lib/systemd/migrated/%{name}; then
    # /usr/sbin/systemd-sysv-convert --save privoxy{d}
    find_service() {
      local runlevel
      declare -i priority
      runlevel=$1
      priority=-1
      for l in /etc/rc.d/rc$runlevel.d/*; do
	test -f "$l" || continue
	initscript=$(basename $l)
	if test ${initscript:0:1} != "S" || test ${initscript:3} != privoxyd; then
	  continue
	fi
	if test ${initscript:1:2} -ge 0 && test ${initscript:1:2} -le 99 &&
	   test ${initscript:1:2} -ge $priority; then
	  if test ${initscript:1:1} = 0; then
	    priority=${initscript:2:1}
	  else
	    priority=${initscript:1:2}
	  fi
	fi
      done
      if test $priority -ge 0; then
	return $priority
      else
	return 255
      fi
    }
    if test -r /etc/init.d/privoxyd; then
      for runlevel in 2 3 4 5; do
	find_service $runlevel
	priority=$?
	if test $priority -lt 255; then
	  printf "%%s\t%%s\t%%s\n" %{name} $runlevel $priority >> /var/lib/systemd/sysv-convert/database
	fi
      done
    fi
  fi
fi
%endif
/usr/sbin/groupadd -r privoxy 2> /dev/null ||:
/usr/sbin/useradd -r -g privoxy -s /bin/false -c "Daemon user for privoxy" \
 -d /var/lib/privoxy privoxy 2> /dev/null ||:
exit 0

%post
%if %{with_systemd}
%service_add_post %{name}.service
%else
%{fillup_and_insserv privoxyd}
%endif
# create logfiles if missing
for i in ./%chroot/log/logfile ./%chroot/log/jarfile; do
	if ! test -e $i; then touch $i; chown privoxy: $i; chmod 640 $i ; fi
done
exit 0

%preun
%if %{with_systemd}
%service_del_preun %{name}.service
%else
%stop_on_removal privoxyd
%endif

%postun
%if %{with_systemd}
%service_del_postun %{name}.service
%else
%restart_on_update privoxyd
%insserv_cleanup
%endif

%files
%defattr(-,root,root)
%doc AUTHORS LICENSE README ChangeLog
/usr/sbin/privoxy
/etc/NetworkManager/dispatcher.d/privoxyd
%dir /etc/NetworkManager
%dir /etc/NetworkManager/dispatcher.d
%doc %_mandir/man1/privoxy.1.gz
%config(noreplace) /etc/logrotate.d/privoxy
%dir /%chroot/etc
%config(noreplace) /%chroot/etc/config
%config(noreplace) /%chroot/etc/trust
%config                                    /%chroot/etc/match-all.action
%config            %attr(640,privoxy,root) /%chroot/etc/default.action
%config(noreplace) %attr(640,privoxy,root) /%chroot/etc/user.action
%config(noreplace) /%chroot/etc/*.filter
%dir %chroot
%chroot/etc/templates
%dir %attr(770,root,privoxy) %chroot/log
%chroot/var
%chroot/%_lib
%chroot/etc/regression-tests.action
%if %{with_systemd}
%{_unitdir}/%{name}.service
%else
%config /etc/init.d/privoxyd
/usr/sbin/rcprivoxyd
%endif
/usr/sbin/rcprivoxy
/etc/privoxy

%files doc
%defattr(-,root,root)
%doc doc/source

%changelog
openSUSE Build Service is sponsored by