File kibana.spec of Package kibana

#
# spec file for package kibana
#
# Copyright (c) 2021 SUSE LLC
# Copyright (c) 2015 Thomas Neuburger, t.neuburger@telekom.de
# Copyright 2017 Fujitsu LIMITED
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define arch x86_64

Name:           kibana
Version:        4.6.6
Release:        0
Summary:        Make sense of a mountain of logs
License:        Apache-2.0
Group:          Productivity/Networking/Web/Frontends
URL:            https://github.com/elastic/kibana
Source:         https://download.elastic.co/kibana/kibana/kibana-%{version}-linux-x86_64.tar.gz
Source1:        kibana.service
Source2:        kibana.logrotate
Source3:        kibana.sysconfig
Source4:        kibana.init
Source5:        kibana.conf
Source6:        kibana.conf.sysv
Source7:        kibana-rpmlintrc
Patch0:         0001-Configurable-custom-response-headers-for-server.patch
Patch1:         CVE-2017-11481.patch
Patch2:         0003-6.8-core.http-Cleanup-catch-all-route-for-paths-with.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Requires:       logrotate
Requires(pre):  pwdutils
BuildRequires:  fdupes

# needed for brp-check-bytecode-version (jar, fastjar would do as well)
BuildRequires:  unzip

%if 0%{?suse_version} >= 1210
BuildRequires:  systemd-rpm-macros
%{?systemd_requires}
%define has_systemd 1
%else
%define has_systemd 0
%endif

%description
Kibana is a highly scalable interface for kibana and ElasticSearch that allows you to
efficiently search, graph, analyze and otherwise make sense of a mountain of logs.

%prep
%setup -q -n %{name}-%{version}-linux-%{arch}
%patch0 -p1
%patch1 -p1
%patch2 -p1

%build

%install
export NO_BRP_CHECK_BYTECODE_VERSION=true

## usr
%{__install} -d -m 755 %{buildroot}/%{_sbindir}

## etc
%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/%{name}

## config without or with pidfile enabled(systemd or sysVinit)
%if 1%{?has systemd}
%{__install} -D -m 644 %{S:5} %{buildroot}%{_sysconfdir}/%{name}/kibana.yml
%else
%{__install} -D -m 644 %{S:6} %{buildroot}%{_sysconfdir}/%{name}/kibana.yml
%endif

# Plugin installation gets confused if the kibana.yml does not reside in /opt/kibana/config
mkdir -p %{buildroot}/opt/%{name}/config
ln -sr %{buildroot}%{_sysconfdir}/%{name}/kibana.yml %{buildroot}/opt/%{name}/config/kibana.yml

%{__install} -D -m 644 %{S:2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

## opt
%{__install} -d -m 755 %{buildroot}/opt/%{name}/
%{__install} -m 644 package.json %{buildroot}/opt/%{name}/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/bin
%{__install} -m 755 bin/kibana %{buildroot}/opt/%{name}/bin/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/installedPlugins
%{__install} -d -m 755 %{buildroot}/opt/%{name}/node
cp -rp node/* %{buildroot}/opt/%{name}/node/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/node_modules
cp -rp node_modules/* %{buildroot}/opt/%{name}/node_modules/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/optimize
cp -rp optimize/* %{buildroot}/opt/%{name}/optimize/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/src
cp -rp src/* %{buildroot}/opt/%{name}/src/
%{__install} -d -m 755 %{buildroot}/opt/%{name}/webpackShims
cp -rp webpackShims/* %{buildroot}/opt/%{name}/webpackShims/

## var
%{__install} -d -m 755 %{buildroot}/var/log/%{name}/
%{__install} -d -m 755 %{buildroot}/var/lib/%{name}/

## sysconfig template
%{__mkdir} -p %{buildroot}/var/adm/fillup-templates/
%{__install} -m 644 %{S:3} %{buildroot}/var/adm/fillup-templates/sysconfig.%{name}

## service (systemd or sysVinit)
%if 1%{?has systemd}
%{__mkdir} -p %{buildroot}%{_unitdir}
%{__install} -m 444 %{S:1} %{buildroot}%{_unitdir}/%{name}.service
ln -sf /usr/sbin/service %{buildroot}%{_sbindir}/rc%{name}
%else
%{__install} -D -m 755 %{S:4} %{buildroot}%{_initrddir}/%{name}
%{__mkdir} -p %{buildroot}%{_sbindir}
ln -sf %{_initrddir}/%{name} %{buildroot}%{_sbindir}/rc%{name}
%endif

## delete waste files
find %{buildroot} -type f -name "*.un~" -delete
find %{buildroot} -type f -name "*.npmignore" -delete
find %{buildroot} -type f -name "*.eslintignore" -delete
find %{buildroot} -type f -name "*.tern-project" -delete
find %{buildroot} -type f -name "*.travis.yml" -delete
rm -f %{buildroot}/opt/%{name}/node/lib/node_modules/npm/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c
rm -f %{buildroot}/opt/%{name}/node_modules/node-uuid/benchmark/benchmark-native.c
rm -f %{buildroot}/opt/%{name}/src/server/http/index.js.orig

# Make sure license directory exists
%{__mkdir} -p %{buildroot}/%{_datadir}/licenses

## finds duplicate files in a given set of directories.
%fdupes $(find %{buildroot}/opt/%{name} -maxdepth 1 | grep -v optimize)

%pre
## Register service systemd
%if 1%{?has systemd}
%service_add_pre %{name}.service
%endif

## create kibana group and user
getent group kibana >/dev/null || groupadd -r kibana
getent passwd kibana >/dev/null || useradd -r -g kibana -d /var/lib/empty -s /sbin/nologin -c "service user for kibana" kibana
exit 0

%post

## Register service systemd
%if 1%{?has systemd}
%service_add_post %{name}.service
%{fillup_and_insserv -n -i %{name}}
%else
## fill up sysconfig file
%{fillup_and_insserv -n -y %{name}}
%endif

cat <<EOF

================================================================================
kibana 4.6 requires elasticsearch >= 2.4
=> this is not a requirement in the rpm cause elasticsearch
   can be installed on a different host
================================================================================

EOF

%preun
## Stop service (systemd or sysVinit)
%if 1%{?has systemd}
%service_del_preun %{name}.service
%else
%stop_on_removal
%endif

%postun
## Unregister service (systemd or sysVinit)
%if 1%{?has systemd}
%service_del_postun %{name}.service
%else
%insserv_cleanup
%endif

# only execute in case of package removal, not on upgrade
if [ $1 -eq 0 ] ; then

    getent passwd kibana > /dev/null
    if [ "$?" == "0" ] ; then
        userdel kibana
    fi

    getent group kibana >/dev/null
    if [ "$?" == "0" ] ; then
        groupdel kibana
    fi
fi

%files
%defattr(-,root,root)
%license LICENSE.txt
%doc README.txt
%dir %{_datadir}/licenses/

%if 1%{?has systemd}
%{_unitdir}/%{name}.service
%else
%{_initrddir}/%{name}
%endif

%{_sbindir}/rc%{name}
%dir /opt/%{name}
/opt/%{name}/bin
/opt/%{name}/config
/opt/%{name}/installedPlugins
/opt/%{name}/node
/opt/%{name}/node_modules
/opt/%{name}/package.json
/opt/%{name}/src
/opt/%{name}/webpackShims
%dir /etc/%{name}/
%config /etc/%{name}/kibana.yml
/var/adm/fillup-templates/sysconfig.%{name}
%config(noreplace) /etc/logrotate.d/%{name}

# These need to be writeable by the Kibana service
%attr(-, kibana, kibana) /opt/%{name}/optimize
%attr(-, kibana, kibana) %dir /var/log/%{name}
%attr(-, kibana, kibana) %dir /var/lib/%{name}

%changelog
openSUSE Build Service is sponsored by