##
##  crossroads.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: 20070710: cs: regarding crossroads-mgr(1), provide start/stop
#   logic, fix paths, logging and log rotation

#   package information
Name:         crossroads
Summary:      Load Balancing Daemon
URL:          http://crossroads.e-tunity.com/
Vendor:       Karel Kubat
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Networking
License:      Open Source
Version:      1.80
Release:      20080519

#   package options
%option       with_fsl  yes

#   list of sources
Source0:      http://crossroads.e-tunity.com/downloads/versions/crossroads-%{version}.tar.gz
Source1:      crossroads.conf
Source2:      fsl.crossroads
Source3:      rc.crossroads
Patch0:       crossroads.patch

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

%description
    Crossroads is a load balance and fail over utility for TCP based
    services. It is a daemon program running in user space, and
    features extensive configurability, polling of back ends using
    'wakeup calls', detailed status reporting, 'hooks' for special
    actions when backend calls fail, and much more. Crossroads is
    service-independent: it is usable for HTTP(S), SSH, SMTP, DNS, etc.

%track
    prog crossroads = {
        version   = %{version}
        url       = http://crossroads.e-tunity.com/downloads/versions/
        regex     = crossroads-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0
    %{l_shtool} subst \
        -e 's;/usr/bin/perl;%{l_prefix}/bin/perl;' \
        etc/svnrev \
        src/crossroads-mgr/crossroads-mgr.in \
        tools/*
    %{l_shtool} subst \
        -e 's;^\(REVVER =\).*$;\1 %{l_openpkg_release -F "OpenPKG-%%t"};' \
        -e 's;^\(PREFIX =\).*$;\1 %{l_prefix};' \
        -e 's;^\(DEFAULT_CONF =\).*$;\1 %{l_prefix}/etc/crossroads/crossroads.conf;' \
        etc/Makefile.def
    %{l_shtool} subst \
        -e 's;/etc/\(crossroads\\.\.conf\);%{l_prefix}/etc/crossroads/\1;g' \
        doc/*.[1-9]

    #   man page regarding crossroads.conf shall rather go to section 5
    #   instead of section 7
    ( cd doc
      mv crossroads.conf.{7,5}
      %{l_shtool} subst \
          -e 's;\("crossroads\\.\.conf" \)"7";\1"5";g' \
          crossroads.conf.5
      %{l_shtool} subst \
          -e 's;\(crossroads\\.\.conf \)(7);\1(5);g' \
          crossroads.1
      %{l_shtool} subst \
          -e 's;\(crossroads\.conf\)\.7;\1.5;g' \
          Makefile
    ) || exit $?

%build
    #   build package
    ( cd src
      %{l_make} %{l_mflags} \
          CC="%{l_cc} %{l_cflags -O}" \
          LDFLAGS="%{l_ldflags} %{l_fsl_ldflags}" \
          LIBS="%{l_fsl_ldflags} %{l_fsl_libs} -lm" \
          BASE="`pwd`/.."
    ) || exit $?

%install

    #   create directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man5 \
        $RPM_BUILD_ROOT%{l_prefix}/var/crossroads

    #   perform standard installation procedure
    %{l_make} %{l_mflags} PREFIX=$RPM_BUILD_ROOT%{l_prefix} install

    #   install configuration file
    l_shmkey=`%{l_uuid} -v3 ns:URL "file://%{l_prefix}" |\
        sed -e 's;^.*\(........\)$;\1;'`
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/crossroads
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        -e "s;@l_shmkey@;$l_shmkey;" \
        %{SOURCE crossroads.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/crossroads/

    #   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.crossroads} \
        $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.crossroads} \
        $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/*' \
        '%config %{l_prefix}/etc/crossroads/*' \
        '%dir %attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/crossroads'

%files -f files

%clean

