File kibana.spec of Package kibana

#
# spec file for package kibana
#
# Copyright (c) 2020 SUSE LLC
# Copyright (c) 2015 Thomas Neuburger, t.neuburger@telekom.de
#
# 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/
#


%if 0%{?suse_version} < 1500
%define _fillupdir %{_localstatedir}/adm/fillup-templates
%endif

Name:           kibana
Version:        7.10.2
Release:        0
Summary:        Visualize your Elasticsearch data and navigate the Elastic Stack
License:        Apache-2.0 AND MIT
Group:          Productivity/Networking/Web/Frontends
URL:            https://github.com/elastic/kibana
Source:         https://artifacts.elastic.co/downloads/kibana/%{name}-oss-%{version}-linux-x86_64.tar.gz
Source1:        kibana.service
Source2:        kibana.logrotate
Source3:        kibana.sysconfig
Source4:        kibana.init
Source7:        kibana-rpmlintrc
BuildRequires:  -rpm-build-check
BuildRequires:  dos2unix
BuildRequires:  fdupes
BuildRequires:  systemd-rpm-macros
# needed for brp-check-bytecode-version (jar, fastjar would do as well)
BuildRequires:  unzip
Requires:       logrotate
Requires(pre):  shadow

%{?systemd_requires}

%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
#echo "`cat %{SOURCE99}`  %{SOURCE0}" | sha1sum -c
%setup -q -n %{name}-%{version}-linux-x86_64
find . -type f -exec sed -i -e 's|\/usr\/bin\/env node|\/usr\/bin\/node|g' {} \;
find . -type f -exec sed -i -e 's|\/usr\/bin\/env python|\/usr\/bin\/python|g' {} \;
find . -type f -exec sed -i -e 's|\/usr\/bin\/env bash|\/bin\/bash|g' {} \;
find . -type f -exec sed -i -e 's|\/usr\/bin\/env sh|\/bin\/sh|g' {} \;
find . -type f -name "*.js" -exec chmod -x {} \;
find . -type f -name "*.md" -exec chmod -x {} \;
find . -type f -name "*.svg" -exec chmod -x {} \;
find . -type f -name "*.json" -exec chmod -x {} \;
find . -type f -name "LICENSE" -exec chmod -x {} \;
find . -type f -name "*.js" -exec dos2unix {} \;
find . -type f -name "*.txt" -exec dos2unix {} \;

%build


%install
export NO_BRP_CHECK_BYTECODE_VERSION=true

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

## etc + sysconfig + logrotate
install -d -m 755 %{buildroot}%{_sysconfdir}/%{name}
install -D -m 644 config/%{name}.yml %{buildroot}%{_sysconfdir}/%{name}
install -D -m 644 config/node.options %{buildroot}%{_sysconfdir}/%{name}
install -D -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

## opt
install -d -m 755 %{buildroot}%{_datadir}/%{name}/
install -m 644 LICENSE.txt %{buildroot}%{_datadir}/%{name}/
install -m 644 README.txt %{buildroot}%{_datadir}/%{name}/
install -m 644 package.json %{buildroot}%{_datadir}/%{name}/
install -d -m 755 %{buildroot}%{_datadir}/%{name}/bin
install -m 755 bin/kibana* %{buildroot}%{_datadir}/%{name}/bin/
install -d -m 755 %{buildroot}%{_datadir}/%{name}/installedPlugins
install -d -m 755 %{buildroot}%{_datadir}/%{name}/node
cp -rp node/* %{buildroot}%{_datadir}/%{name}/node/
install -d -m 755 %{buildroot}%{_datadir}/%{name}/node_modules
cp -rp node_modules/* %{buildroot}%{_datadir}/%{name}/node_modules/
###install -d -m 755 %%{buildroot}%%{_datadir}/%%{name}/optimize
###cp -rp optimize/* %%{buildroot}%%{_datadir}/%%{name}/optimize/
install -d -m 755 %{buildroot}%{_datadir}/%{name}/src
cp -rp src/* %{buildroot}%{_datadir}/%{name}/src/
###install -d -m 755 %%{buildroot}%%{_datadir}/%%{name}/webpackShims
###cp -rp webpackShims/* %%{buildroot}%%{_datadir}/%%{name}/webpackShims/
###install -d -m 755 %%{buildroot}%%{_datadir}/%%{name}/built_assets
###cp -rp built_assets/* %%{buildroot}%%{_datadir}/%%{name}/built_assets/

## log + data
install -d -m 755 %{buildroot}%{_localstatedir}/log/%{name}/
install -d -m 755 %{buildroot}%{_localstatedir}/lib/%{name}/

## Plugins
install -d -m 755 %{buildroot}%{_datadir}/%{name}/plugins

## sysconfig template
mkdir -p %{buildroot}%{_fillupdir}/
install -m 644 %{SOURCE3} %{buildroot}%{_fillupdir}/sysconfig.%{name}

## systemd
mkdir -p %{buildroot}%{_unitdir}
install -m 444 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
ln -sf %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}

## delete waste files
find %{buildroot} -type f -name "*~" -delete
rm -r `find . -name ".github"`

## finds duplicate files in a given set of directories
%fdupes %{buildroot}


%pre
%service_add_pre %{name}.service

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

%post
%service_add_post %{name}.service
## fill up sysconfig file
%{fillup_and_insserv -n -y %{name}}

cat <<EOF

================================================================================
kibana 7.x requires elasticsearch >= 7.0.0
=> this is not a requirement in the rpm cause elasticsearch
   can be installed on a different host
================================================================================

EOF

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

## no auto restart on update
export DISABLE_RESTART_ON_UPDATE=1


# 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
%license LICENSE.txt NOTICE.txt
%doc README.txt
%dir %{_datadir}/%{name}/
%dir %{_sysconfdir}/%{name}/
%config(noreplace) %{_sysconfdir}/%{name}/kibana.yml
%config(noreplace) %{_sysconfdir}/%{name}/node.options
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%{_datadir}/%{name}/*
%{_fillupdir}/sysconfig.%{name}
%{_sbindir}/rc%{name}
%{_unitdir}/%{name}.service

%defattr(-,kibana,kibana)
%dir %{_localstatedir}/lib/%{name}
%dir %{_localstatedir}/log/%{name}
%dir %{_datadir}/%{name}/plugins

%changelog
openSUSE Build Service is sponsored by