##
##  sav.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 version
%define       V_engine   3.2.07.185
%define       V_ides_maj 4
%define       V_ides_min 22

#   package information
Name:         sav
Summary:      Sophos Anti-Virus
URL:          http://www.sophos.com/products/sav/
Vendor:       Sophos Plc.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        AntiVirus
License:      Commercial/Free-Trial
Version:      %{V_engine}.%{V_ides_maj}.%{V_ides_min}
Release:      20080101

#   list of sources
Source0:      http://download.openpkg.org/components/versioned/sav/sav-%{V_ides_maj}.%{V_ides_min}-freebsd.elf.tar.Z
Source1:      http://download.openpkg.org/components/versioned/sav/sav-%{V_ides_maj}.%{V_ides_min}-linux.intel.libc6.tar.Z
Source2:      http://download.openpkg.org/components/versioned/sav/sav-%{V_ides_maj}.%{V_ides_min}-solaris.sparc.tar.Z
Source3:      rc.sav
Source4:      sav.conf
Source5:      sweep.sh
Source6:      sweep.c
Source7:      sweep.mk
%NoSource     0
%NoSource     1
%NoSource     2

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc
PreReq:       OpenPKG, openpkg >= 20160101, curl, infozip

%description
    This is the free-trial version of the Sophos Anti-Virus virus
    scanner for Unix.

%track
    prog sav:local = {
        version   = %{V_ides_maj}.%{V_ides_min}
        url       = http://download.openpkg.org/components/versioned/sav/
        regex     = sav-(__VER__)-.*
    }
    prog sav:vendor = {
        #   download file from vendor, rename according to content and save versioned copy
        #   automated with script http://download.openpkg.org/components/versioned/sav/drs.sh
        comment   = "thl: download, rename and save instructions see spec"
        version   = %{V_ides_maj}%{V_ides_min}
        url       = http://www.sophos.com/downloads/ide/
        regex     = (__VER__)_ides.zip
    }

%prep
    %setup -q -T -c

    #   select and decompress platform specific anti-virus engine
    case "%{l_platform -t}" in
        *-freebsd* ) engine="%{SOURCE sav-%{V_ides_maj}.%{V_ides_min}-freebsd.elf.tar.Z}" ;;
        *-linux*   ) engine="%{SOURCE sav-%{V_ides_maj}.%{V_ides_min}-linux.intel.libc6.tar.Z}" ;;
        *-sunos*   ) engine="%{SOURCE sav-%{V_ides_maj}.%{V_ides_min}-solaris.sparc.tar.Z}" ;;
        * ) echo "Sorry, platform %{l_platform -t} not supported" 1>&2; exit 1 ;;
    esac
    %{l_gzip} -d -c $engine | %{l_tar} xf -

%build
    #   build open(2) wrapper DSO
    #   (for mapping hard-coded /etc/sav.conf to %{l_prefix}/etc/sav/sav.conf)
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE sweep.c} %{SOURCE sweep.mk} ./
    case "%{l_platform -t}" in
        *-freebsd* ) target="freebsd" ;;
        *-linux*   ) target="linux"   ;;
        *-sunos*   ) target="solaris" ;;
    esac
    %{l_make} %{l_mflags} -f sweep.mk $target

%install

    #   create directory structure
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/sav \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/lib/sav \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/sav \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/var/sav/data

    #   install open(2) wrapper library
    %{l_shtool} install -c -m 755 \
        sweep.so \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/sav/

    #   install binary wrapper script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE sweep.sh} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/sweep

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

    #   install default configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE sav.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/sav/

    #   install SAVI library and add compatibility links
    %{l_shtool} install -c -m 755 \
        sav-install/libsavi.so* \
        $RPM_BUILD_ROOT%{l_prefix}/lib/sav/
    ( cd $RPM_BUILD_ROOT%{l_prefix}/lib/sav
      %{l_shtool} mkln -s -f libsavi.so.3.* libsavi.so.3
      %{l_shtool} mkln -s -f libsavi.so.3.* libsavi.so
    ) || exit $?

    #   install original binary
    %{l_shtool} install -c -m 755 \
        sav-install/sweep \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/sav/sweep

    #   install man page
    %{l_shtool} install -c -m 644 \
        sav-install/sweep.1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1/

    #   install virus description and identity files
    %{l_shtool} install -c -m 644 \
        sav-install/vdl-%{V_ides_maj}.%{V_ides_min}.dat \
        $RPM_BUILD_ROOT%{l_prefix}/var/sav/data/vdl.dat
    %{l_shtool} install -c -m 644 \
        sav-install/vdl*.vdb \
        $RPM_BUILD_ROOT%{l_prefix}/var/sav/data/

    #   install message catalog
    %{l_shtool} install -c -m 644 \
        sav-install/swpmess.dat \
        $RPM_BUILD_ROOT%{l_prefix}/var/sav/data/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/sav/*'

%files -f files

%clean

%preun
    rm -f $RPM_INSTALL_PREFIX/var/sav/data/*.ide >/dev/null 2>&1 || true

