##
##  milter-bogom.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:         milter-bogom
Summary:      Mail Filter for BogoFilter
URL:          http://www.usebox.net/jjm/bogom/
Vendor:       Juan J. Martinez
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Mail
License:      Open Source
Version:      1.9.2
Release:      20080626

#   package options
%option       with_fsl  yes

#   list of sources
Source0:      http://www.usebox.net/jjm/bogom/bogom-%{version}.tar.gz
Source1:      rc.milter-bogom
Source2:      fsl.milter-bogom
Patch0:       milter-bogom.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101, bogofilter
BuildPreReq:  milter
PreReq:       milter
%if "%{with_fsl}" == "yes"
BuildPreReq:  fsl
PreReq:       fsl
%endif

%description
    This is a Mail spam-filter using the bogofilter(1) bayesian filter,
    based on the MILTER API of MTAs.

%track
    prog milter-bogom = {
        version   = %{version}
        url       = http://www.usebox.net/jjm/bogom/
        regex     = bogom-(\d+(\.\d+)+)\.tar\.gz
    }

%prep
    %setup -q -n bogom-%{version}
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;\(DEF_USER\)[^"]*"[^"]*";\1 "%{l_rusr}";' \
        -e 's;\(DEF_CONN\)[^"]*"[^"]*";\1 "unix:%{l_prefix}/var/milter/socket/milter-bogom";' \
        -e 's;\(DEF_CONF\)[^"]*"[^"]*";\1 "%{l_prefix}/etc/milter-bogom/milter-bogom.conf";' \
        -e 's;\(DEF_PIDFILE\)[^"]*"[^"]*";\1 "%{l_prefix}/var/milter-bogom/milter-bogom.pid";' \
        -e 's;/usr/local/bin/bogofilter;%{l_prefix}/bin/bogofilter;' \
        milter.c
    libs="-lmilter"
    case "%{l_platform -p}" in
        *-solaris* ) libs="$libs -lsocket -lnsl" ;;
    esac
    %{l_make} %{l_mflags} \
        CC="%{l_cc}" \
        CPPFLAGS="%{l_cppflags}" \
        CFLAGS="%{l_cflags -O} -pthread" \
        LDFLAGS="%{l_ldflags} -pthread %{l_fsl_ldflags}" \
        LIBS="$libs %{l_fsl_libs}"

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl \
        $RPM_BUILD_ROOT%{l_prefix}/etc/milter-bogom \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/var/milter-bogom

    #   install program
    %{l_shtool} install -c -s -m 755 \
        bogom $RPM_BUILD_ROOT%{l_prefix}/sbin/

    #   install manual page
    %{l_shtool} install -c -m 644 \
        bogom.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/

    #   install configuration
    %{l_shtool} install -c -m 644 \
        bogom.conf-example $RPM_BUILD_ROOT%{l_prefix}/etc/milter-bogom/bogom.conf

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.milter-bogom} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   install OSSP fsl configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fsl.milter-bogom} $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/fsl/*' \
        '%attr(755,%{l_rusr},%{l_mgrp}) %{l_prefix}/var/milter-bogom'

%files -f files

%clean

%post
    #   after upgrade, restart service
    if [ $1 -eq 2 ]; then
        eval `%{l_rc} milter-bogom status 2>/dev/null`
        [ ".$milter_bogom_active" = .yes ] && %{l_rc} milter-bogom restart
    fi
    exit 0

%preun
    #   before erase, stop service and remove log files
    if [ $1 -eq 0 ]; then
        %{l_rc} milter-bogom stop 2>/dev/null
        rm -f $RPM_INSTALL_PREFIX/etc/milter-bogom/* >/dev/null 2>&1 || true
    fi
    exit 0

