##
##  rsyslog.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:         rsyslog
Summary:      Enhanced Logging Server
URL:          http://www.rsyslog.com/
Vendor:       R. Gerhards, M. Meckelein
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Logfile
License:      GPL
Version:      6.3.12
Release:      20120703

#   package options
%option       with_kerberos no
%option       with_mysql    no
%option       with_pgsql    no

#   list of sources
Source0:      http://www.rsyslog.com/files/download/rsyslog/rsyslog-%{version}.tar.gz
Source1:      rsyslog.conf
Source2:      rc.rsyslog
Patch0:       rsyslog.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  zlib, librelp >= 0.1.1, libestr, libee
PreReq:       zlib, librelp >= 0.1.1, libestr, libee
%if "%{with_kerberos}" == "yes"
BuildPreReq:  KERBEROS
PreReq:       KERBEROS
%endif
%if "%{with_mysql}" == "yes"
BuildPreReq:  mysql
PreReq:       mysql
%endif
%if "%{with_pgsql}" == "yes"
BuildPreReq:  postgresql, openssl
PreReq:       postgresql, openssl
%endif

%description
    Rsyslog is an enhanced multi-threaded syslogd(8) supporting, among
    others, RDBMS, syslog/tcp, RFC 3195, permitted sender lists,
    filtering on any message part, and fine grain output format control.
    It is quite compatible to stock syslogd(8) and can be used as a
    drop-in replacement. Its advanced features make it suitable for
    enterprise-class, encryption protected syslog relay chains while at
    the same time being very easy to setup for the novice user.

%track
    prog rsyslog = {
        version   = %{version}
        url       = http://www.rsyslog.com/download/
        regex     = rsyslog-(\d+(\.\d+)+)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    #   configure program
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
%if "%{with_pgsql}" == "yes"
    LIBS="`pg_config --libs` -lz" \
%else
    LIBS="-lz" \
%endif
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --enable-relp \
        --enable-regexp \
        --enable-zlib \
%if "%{with_kerberos}" == "yes"
        --enable-gssapi-krb5 \
%endif
%if "%{with_mysql}" == "yes"
        --enable-mysql \
%endif
%if "%{with_pgsql}" == "yes"
        --enable-pgsql \
%endif
        --disable-klog

    #   build program
    %{l_make} %{l_mflags}

%install

    #   install program
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   strip down installation
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/rsyslog/*.la >/dev/null 2>&1 || true
    rm -f $RPM_BUILD_ROOT%{l_prefix}/sbin/rfc3195d
    rm -f $RPM_BUILD_ROOT%{l_prefix}/sbin/rklogd
    rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man8/rfc3195d.8
    rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man8/rklogd.8

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

    #   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.rsyslog} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   create run-time directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/var/rsyslog/run \
        $RPM_BUILD_ROOT%{l_prefix}/var/rsyslog/log

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

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} rsyslog status 2>/dev/null`
    [ ".$rsyslog_active" = .yes ] && %{l_rc} rsyslog restart
    exit 0

%preun
    #   before erase, stop service and remove run-time files
    [ $1 -eq 0 ] || exit 0
    %{l_rc} rsyslog stop 2>/dev/null
    rm -f $RPM_INSTALL_PREFIX/var/rsyslog/log/* >/dev/null 2>&1 || true
    rm -f $RPM_INSTALL_PREFIX/var/rsyslog/run/* >/dev/null 2>&1 || true
    exit 0

