##
##  tripwire.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.
##

#   FIXME: thl fsl does not make it into the binary

#   package versions
%define       V_tripwire 2.3.1
%define       V_lvl      2
%define       V_openpkg  %{V_tripwire}.%{V_lvl}
%define       V_vendor   %{V_tripwire}-%{V_lvl}

#   package information
Name:         tripwire
Summary:      File and Directory Integrity Checker
URL:          http://www.tripwire.org/
Vendor:       Tripwire, Inc
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Security
License:      GPL
Version:      %{V_openpkg}
Release:      20080101

#   package options
%option       with_fsl  yes

#   list of sources
Source0:      http://download.sourceforge.net/tripwire/tripwire-%{V_vendor}.tar.gz
Source1:      tw.cfg
Source2:      sparc-solaris.inc
Source3:      sparc-solaris.mak
Source4:      rc.tripwire
Source5:      fsl.tripwire
Patch0:       tripwire.patch

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

%description
    Tripwire is a policy driven file system integrity checking tool that
    allows system administrators to verify the integrity of their data.

%track
    prog tripwire = {
        version   = %{V_vendor}
        url       = http://sourceforge.net/projects/tripwire/files/
        regex     = tripwire-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n tripwire-%{V_vendor}
    %patch -p0

%build
    case "%{l_platform -t}" in
        *-freebsd* ) syspre="i386-unknown-freebsd" ;;
        *-linux*   ) syspre="i686-pc-linux"        ;;
        *-sunos*   ) syspre="sparc-sunos"          ;;
        *-netbsd*  ) syspre="i386-unknown-openbsd" ;;
        *) echo "ERROR: Unsupport platform '%{l_platform -t}'"; exit 1 ;;
    esac
    cd src
    cp %{SOURCE sparc-solaris.inc} make_include/
    cp %{SOURCE sparc-solaris.mak} cryptlib/
    %{l_shtool} subst \
        -e '/^targets/s/STLport_r//' \
        Makefile
    touch STLport_r
    for f in cryptlib/*.mak make_include/*.inc; do
        %{l_shtool} subst \
            -e 's;-[IL]../STLPort[^[:blank:]]*;;' \
            -e 's;stlport_gcc;stdc++;' \
            $f
    done
    for f in *.pl; do
        %{l_shtool} subst \
            -e '1s;/usr/bin/perl;%{l_prefix}/bin/perl;' \
            $f
    done
    %{l_shtool} subst \
        -e 's;!(IS_SOLARIS && IS_IX86);0;' \
        tripwire/smtpmailmessage.cpp
    %{l_shtool} subst %{l_value -s -a} \
        core/stdcore.h
    %{l_shtool} subst \
        -e 's;<malloc\.h>;<stdlib.h>;g' \
        `find . -type f -print`
    %{l_make} %{l_mflags -O} release \
        CC="%{l_cc}" \
        CFLAGS="%{l_cflags -O}" \
        LDFLAGS="%{l_ldflags} %{l_fsl_ldflags}" \
        LIBS="%{l_fsl_libs}" \
        CXX="%{l_cxx}" \
        CXXFLAGS="%{l_cxxflags -O} -fpermissive" \
        CPPFLAGS="%{l_cppflags}" \
        GMAKE="%{l_make}" \
        SYSPRE="$syspre" \
        STLPORT="No-STLPort"

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/tripwire \
        $RPM_BUILD_ROOT%{l_prefix}/man/man4 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man5 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/var/tripwire

    for f in bin/*_r/*; do
        %{l_shtool} install -c -s -m 755 \
            $f $RPM_BUILD_ROOT%{l_prefix}/bin/
    done
    %{l_shtool} install -c -m 644 \
        policy/twpol.txt \
        $RPM_BUILD_ROOT%{l_prefix}/etc/tripwire/tw.pol
    %{l_shtool} install -c -m 644 \
        policy/policyguide.txt \
        $RPM_BUILD_ROOT%{l_prefix}/etc/tripwire/policyguide
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE tw.cfg} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/tripwire/
    for f in man/man[458]/*.[458]; do
        %{l_shtool} install -c -m 644 \
            $f $RPM_BUILD_ROOT%{l_prefix}/$f
    done

    #   install run-command script
    %{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.tripwire} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   install OSSP fsl configuration
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/etc/fsl
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fsl.tripwire} \
        $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/fsl.tripwire'

%files -f files

%clean

