##
##  logstash.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:         logstash
Summary:      Log Collector Service
URL:          http://logstash.net/
Vendor:       Jordan Sissel, Pete Fritchman
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Networking
License:      Apache
Version:      2.4.0
Release:      20160903

#   list of sources
Source0:      https://download.elasticsearch.org/logstash/logstash/logstash-%{version}.tar.gz
Source1:      logstash.conf
Source2:      rc.logstash

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101, java, JAVA-JDK, x509

%description
    Logstash is a data pipeline that helps you process logs and other
    event data from a variety of systems. With hundreds of plugins,
    Logstash can connect to a variety of sources and stream data at
    scale to a central analytics system.

%track
    prog logstash = {
        version   = %{version}
        url       = https://www.elastic.co/downloads/logstash
        regex     = logstash-(\d+\.\d+\.\d+)\.tar\.gz
    }

%prep
    %setup -q

%build

%install
    #   create installation directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/logstash \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/logstash \
        $RPM_BUILD_ROOT%{l_prefix}/var/logstash/input \
        $RPM_BUILD_ROOT%{l_prefix}/var/logstash/output \
        $RPM_BUILD_ROOT%{l_prefix}/var/logstash/run \
        $RPM_BUILD_ROOT%{l_prefix}/var/logstash/log

    #   install program parts
    cp -rp * $RPM_BUILD_ROOT%{l_prefix}/libexec/logstash/

    #   install command wrapper
    (   echo "#!/bin/sh"
        echo "exec %{l_prefix}/libexec/logstash/bin/logstash \${1+\"\$@\"}"
    ) >logstash.sh
    %{l_shtool} install -c -m 755 \
        logstash.sh $RPM_BUILD_ROOT%{l_prefix}/sbin/logstash

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

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.logstash} $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/logstash/*' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/logstash/*'

%files -f files

%clean

