##
##  sophie.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:         sophie
Summary:      Sophie Anti-Virus Scanner Daemon
URL:          http://www.clanfield.info/sophie/
Vendor:       Vanja Hrustic et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        AntiVirus
License:      GPL
Version:      3.05
Release:      20080101

#   package options
%option       with_fsl yes

#   list of sources
Source0:      http://www.clanfield.info/sophie/sophie-%{version}.tar.bz2
Source1:      fsl.sophie
Source2:      rc.sophie
Source3:      sophie.cfg
Source4:      sophie.savi
Source5:      sophie.sh
Patch0:       sophie.patch

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

%description
    Sophie is a daemon which uses the libsavi library from Sophos
    Anti-Virus. On startup, Sophie initializes SAVI (Sophos Anti-Virus
    Interface), loads virus patterns into memory, opens local UNIX
    domain socket, and waits for someone to connect and instructs it
    which path to scan. Since it is loaded in RAM, scanning is very
    fast. Of course, speed of scanning also depends on SAVI settings and
    size of the file.

%track
    prog sophie = {
        version   = %{version}
        url       = http://www.clanfield.info/sophie/
        regex     = sophie-(\d+(\.\d+)+)\.tar\.bz2
    }

%prep
    %setup -q
    %patch -p1
    %{l_shtool} subst %{l_value -s -a} \
        sophie.c \
        sophie_init.c
    %{l_shtool} subst \
        -e 's;^\(#define[ 	]*DEFAULT_PIDFILE\)[ 	].*$;\1 "%{l_prefix}/var/sophie/sophie.pid";' \
        -e 's;^\(#define[ 	]*DEFAULT_SOCKETFILE\)[ 	].*$;\1 "%{l_prefix}/var/sophie/sophie.sock";' \
        sophie.h
    case "%{l_platform -t}" in
        *-freebsd* ) %{l_shtool} subst -e 's; -lrt;;' configure ;;
    esac

%build
    LD_LIBRARY_PATH="%{l_prefix}/lib/sav:${LD_LIBRARY_PATH-/usr/lib}"
    export LD_LIBRARY_PATH
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags} %{l_fsl_ldflags}" \
    LIBS="%{l_fsl_libs}" \
    ./configure \
        --prefix=%{l_prefix} \
        --with-savilib=%{l_prefix}/lib/sav \
        --disable-net
    %{l_make} %{l_mflags -O}

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/sophie \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/sophie \
        $RPM_BUILD_ROOT%{l_prefix}/var/sophie
    %{l_shtool} install -c -s -m 755 \
        sophie \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/sophie/
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE sophie.sh} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/sophie
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fsl.sophie} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.sophie} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE sophie.cfg} \
        %{SOURCE sophie.savi} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/sophie/
    %{l_shtool} install -c -m 644 \
        sophie.8 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} \
        '%config %{l_prefix}/etc/fsl/fsl.sophie' \
        '%config %{l_prefix}/etc/sophie/*' \
        '%dir %attr(1777,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/sophie'

%files -f files

%clean

