##
##  bdc.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_openpkg   7.0.1
%define       V_freebsd   7.0.1.2
%define       V_linux     7.0.1-3

#   package information
Name:         bdc
Summary:      Bitdefender Anti-Virus
URL:          http://www.bitdefender.com/
Vendor:       Bitdefender
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        AntiVirus
License:      Commercial/Free-Trail
Version:      %{V_openpkg}
Release:      20080101

#   list of sources
Source0:      http://download.bitdefender.com/freebsd/5/final/bdc-%{V_freebsd}-fbsd5.tar.gz
Source1:      http://download.bitdefender.com/linux/free/bitdefender-console/en/BitDefender-Console-Antivirus-%{V_linux}.linux-gcc29x.i586.rpm
Source2:      bdc.sh
Source3:      rc.bdc

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, cpio
PreReq:       OpenPKG, openpkg >= 20160101

%description
    This is the free-trail version of the Bitdefender command line virus
    scanner for Unix.

%track
    prog bdc:freebsd = {
        version   = %{V_freebsd}
        url       = http://download.bitdefender.com/freebsd/5/final/
        regex     = bdc-(__VER__)-fbsd5\.tar\.gz
    }
    prog bdc:linux = {
        version   = %{V_linux}
        url       = http://download.bitdefender.com/linux/free/bitdefender-console/en/
        regex     = BitDefender-Console-Antivirus-(__VER__)\.linux-gcc29x\.i586\.rpm
    }

%prep
    %setup -q -c -T

    #   unpack platform-specific Engine
    case "%{l_platform -t}" in
        *-freebsd* )
            %{l_gzip} -d -c %{SOURCE0} | %{l_tar} xf -
            mv bdc/bdc.bin bdc/bdc
            echo "subdir=bdc" >sh.sh
            ;;
        *-linux* )
            %{l_rpm2cpio} %{SOURCE1} | %{l_prefix}/bin/cpio -idvmu
            echo "subdir=opt/bdc" >sh.sh
            ;;
        * )
            echo "Sorry, platform %{l_platform -t} not supported" 1>&2
            exit 1
            ;;
    esac

%build

%install

    #   redetermine information
    . sh.sh

    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/bdc \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/lib/bdc \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1

    #   install package
    ( cd $subdir
      cp -rp Plugins bdc bdc.ini *.so \
          $RPM_BUILD_ROOT%{l_prefix}/lib/bdc/
      %{l_shtool} install -c -m 644 \
          man/bdc.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/
      ln  $RPM_BUILD_ROOT%{l_prefix}/lib/bdc/bdc.ini \
          $RPM_BUILD_ROOT%{l_prefix}/etc/bdc/bdc.ini
    ) || exit $?

    #   install engine command line wrapper
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE bdc.sh} $RPM_BUILD_ROOT%{l_prefix}/bin/bdc

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

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

%files -f files

%clean

