File couchdb.spec of Package couchdb

# spec file for package couchdb
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# 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

%define couchdb_user couchdb
%define couchdb_group couchdb
%define couchdb_home %{_localstatedir}/lib/couchdb

Name:           couchdb
Version:        1.6.1
Release:        0
Summary:        A document database server, accessible via a RESTful JSON API
License:        Apache-2.0
Group:          Productivity/File utilities
Source1:        %{name}.init
Source2:        %{name}.sysconfig
Patch0:         couchdb-futon-default-view-language.patch
# OTP-18.x support from upstream
Patch1:         95cb436be30305efa091809813b64ef31af968c8.patch
# OTP-19.x support from upstream
Patch2:         41304b83946f029f9712714cc89e9f630442d668.patch
# backport of OTP-20.x support in 1.7.x branch (5f88da2a5ee8ba78917fafd572c7b9fa37e76460)
Patch3:         0001-R20-compat-for-1.x.x-952.patch
Patch4:         erlang-20.x-no-autoreconf.patch
# PATCH-FIX-UPSTREAM couchdb-1.6.1-fix-restart.patch -- Fix heartbeat restart bnc#919927
Patch5:         couchdb-1.6.1-fix-restart.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  erlang
BuildRequires:  gcc-c++
BuildRequires:  help2man
BuildRequires:  libicu-devel
BuildRequires:  libtool
%if 0%{?suse_version} < 1200
BuildRequires:  mozilla-xulrunner192-devel
BuildRequires:  js-devel
BuildRequires:  pkgconfig
Requires:       erlang
Requires:       logrotate
Requires(post): aaa_base
Requires(post): info
# Users and groups
Requires(pre):  pwdutils
PreReq:         %insserv_prereq %fillup_prereq

Apache CouchDB is a distributed, fault-tolerant and schema-free
document-oriented database accessible via a RESTful HTTP/JSON API.
Among other features, it provides robust, incremental replication
with bi-directional conflict detection and resolution, and is
queryable and indexable using a table-oriented view engine with
JavaScript acting as the default view definition language.

%setup -q -n apache-couchdb-%{version}
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1


# Versions of SpiderMonkey after the js185-1.0.0 release remove the optional
# enforcement of preventing anonymous functions in a statement context. This
# will most likely break your existing JavaScript code as well as render all
# example code invalid.
# If you wish to ignore this error pass --enable-js-trunk to ./configure.
# We need to define the use of gnu99 standard. It seems expected in the code, but not passed.
export CFLAGS="%{optflags} -std=gnu99"
%configure --enable-js-trunk
make %{?_smp_mflags}

## Install couchdb initscript
install -D -m 0755 %{SOURCE1} %{buildroot}%{_initddir}/%{name}
install -d %{buildroot}%{_sbindir}
ln -s %{_initddir}/couchdb %{buildroot}%{_sbindir}/rccouchdb
# Sysconfig template
mkdir -p %{buildroot}%{_var}/adm/fillup-templates/
install -p -D -m 644 %{SOURCE2} %{buildroot}%{_var}/adm/fillup-templates/sysconfig.couchdb
# Create needed directories
install -d %{buildroot}%{_localstatedir}/{log,lib}/couchdb
install -d %{buildroot}%{_sysconfdir}/couchdb/{default.d,local.d}
# Remove unecessary files
rm %{buildroot}%{_sysconfdir}/rc.d/couchdb
rm -rf  %{buildroot}%{_datadir}/doc/couchdb
# clean-up .la archives
find %{buildroot} -name '*.la' -delete -print

getent group %{couchdb_group} >/dev/null || groupadd -r %{couchdb_group} || :
if getent passwd %{couchdb_user} >/dev/null ; then
    # There was a bad login shell up to openSUSE 12.2 (bnc#796242), SLE11SP2 used /bin/bash. Fix it.
    usermod -s /sbin/nologin %{couchdb_user} || :
    useradd -r -g %{couchdb_group} -d %{couchdb_home} -s /sbin/nologin \
    -c "Couchdb Database Server" %{couchdb_user} || :

%{fillup_and_insserv couchdb}
mkdir -p %{_localstatedir}/run/couchdb
%install_info --info-dir=%{_infodir} %{_infodir}/%{name}.info.gz

%restart_on_update couchdb
%install_info_delete --info-dir=%{_infodir} %{_infodir}/%{name}.info.gz

%stop_on_removal couchdb

%dir %{_sysconfdir}/couchdb
%dir %{_sysconfdir}/couchdb/local.d
%dir %{_sysconfdir}/couchdb/default.d
%config(noreplace) %attr(0644, %{couchdb_user}, root) %{_sysconfdir}/couchdb/default.ini
%config(noreplace) %attr(0644, %{couchdb_user}, root) %{_sysconfdir}/couchdb/local.ini
%config(noreplace) %{_sysconfdir}/default/couchdb
%config(noreplace) %{_sysconfdir}/logrotate.d/couchdb
%dir %attr(0755, %{couchdb_user}, root) %{_localstatedir}/log/couchdb
%ghost %dir %attr(0755, %{couchdb_user}, root) %{_localstatedir}/run/couchdb
%dir %attr(0755, %{couchdb_user}, root) %{_localstatedir}/lib/couchdb