##
##  privoxy.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         privoxy
Summary:      Privacy Web Proxy
URL:          http://www.privoxy.org/
Vendor:       Privoxy Development Team
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Web
License:      GPL
Version:      3.0.33
Release:      20211208

#   list of sources
Source0:      http://download.sourceforge.net/ijbswa/privoxy-%{version}-stable-src.tar.gz
Source1:      rc.privoxy
Patch0:       privoxy.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, autoconf, make
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  pcre
PreReq:       pcre

%description
    Privoxy is a web proxy with advanced filtering capabilities for
    protecting privacy, modifying web page content, managing cookies,
    controlling access, and removing ads, banners, pop-ups and other
    obnoxious Internet junk. Privoxy has a very flexible configuration and
    can be customized to suit individual needs and tastes. Privoxy has
    application for both stand-alone systems and multi-user networks.

%track
    prog privoxy = {
        version   = %{version}
        url       = http://sourceforge.net/projects/ijbswa/files/
        regex     = privoxy-(\d+\.\d+(\.\d+)*)-(?:stable|beta)-src\.tar\.gz
    }

%prep
    %setup -q -n privoxy-%{version}-stable
    %patch -p0

%build
    %{l_prefix}/bin/autoheader >/dev/null 2>&1
    %{l_prefix}/bin/autoconf   >/dev/null 2>&1
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    GREP="grep" \
    ./configure \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/privoxy \
        --datarootdir=%{l_prefix} \
        --datadir=%{l_prefix}/share/privoxy \
        --mandir=%{l_prefix}/man \
        --localstatedir=%{l_prefix}/var/privoxy \
        --with-user=%{l_rusr} \
        --with-group=%{l_rgrp}
    %{l_make} %{l_mflags -O}

%install
    %{l_make} %{l_mflags} install \
        prefix=$RPM_BUILD_ROOT%{l_prefix} \
        exec_prefix=$RPM_BUILD_ROOT%{l_prefix} \
        datarootdir=$RPM_BUILD_ROOT%{l_prefix} \
        datadir=$RPM_BUILD_ROOT%{l_prefix}/share/privoxy \
        mandir=$RPM_BUILD_ROOT%{l_prefix}/man \
        localstatedir=$RPM_BUILD_ROOT%{l_prefix}/var/privoxy \
        MAN_DIR=$RPM_BUILD_ROOT%{l_prefix}/man \
        CONF_BASE=$RPM_BUILD_ROOT%{l_prefix}/etc/privoxy \
        SHARE_DEST=$RPM_BUILD_ROOT%{l_prefix}/share/privoxy \
        VAR_DEST=$RPM_BUILD_ROOT%{l_prefix}/var/privoxy
    chmod a+r $RPM_BUILD_ROOT%{l_prefix}/etc/privoxy/*
    strip $RPM_BUILD_ROOT%{l_prefix}/sbin/* >/dev/null 2>&1 || true
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/privoxy/doc
    rm -f $RPM_BUILD_ROOT%{l_prefix}/var/privoxy/log/*
    %{l_shtool} subst \
        -e 's;^\(user-manual\).*;\1 %{l_prefix}/share/privoxy/doc/user-manual/;' \
        -e 's;^\(confdir\).*;\1 %{l_prefix}/etc/privoxy;' \
        -e 's;^\(logdir\).*;\1 %{l_prefix}/var/privoxy/log;' \
        -e 's;logfile logfile;logfile privoxy.log;' \
        -e 's;jarfile jarfile;#jarfile privoxy.jar;' \
        $RPM_BUILD_ROOT%{l_prefix}/etc/privoxy/config
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.privoxy} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/privoxy/*' \
        '%config %{l_prefix}/etc/privoxy/templates/*' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/privoxy/*'

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} privoxy status 2>/dev/null`
    [ ".$privoxy_active" = .yes ] && %{l_rc} privoxy restart
    exit 0

%preun
    #   before erase, stop service and remove log files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} privoxy stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/privoxy/run/* >/dev/null 2>&1 || true
    rm -f $RPM_INSTALL_PREFIX/var/privoxy/log/* >/dev/null 2>&1 || true
    exit 0

