File consul.spec of Package consul

# spec file for package consul
# Copyright (c) 2015 SUSE LINUX Products 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

%if 0%{?suse_version} > 1230
%bcond_without systemd
%bcond_with systemd

%define home_dir %{_localstatedir}/lib/%{name}
%define go_arches %ix86 x86_64 ppc64le aarch64

%ifarch %go_arches
%define go_tool go
%define go_tool go-5

Name:           consul
Version:        0.8.3
Release:        0
Summary:        A tool for service discovery, monitoring and configuration
License:        Apache-2.0
Group:          System/Management

Source0:        v%{version}.tar.gz
Source1:        %{name}-rpmlintrc
Source2:        %{name}.service
Source10:       %{name}.sysconfig
Source11:       %{name}.json

%if 0%{?suse_version} >= 1210
BuildRequires: systemd-rpm-macros
BuildRequires:  golang-packaging
BuildRequires:  xz
%ifarch %go_arches
BuildRequires:  go >= 1.6
BuildRequires:  gcc5-go >= 5.0

%if %{with systemd}
BuildRequires:  pkgconfig(systemd)

%if 0%{?suse_version} > 1110
Requires(pre):  pwdutils
Requires(pre):  shadow-utils

Requires(pre):  %{fillup_prereq}


BuildRoot:      %{_tmppath}/%{name}-%{version}-build

A tool for service discovery and configuration, it is distributed, highly
available, and extremely scalable.

%setup -q -n %{name}-%{version}

export GOPATH=$PWD/go
mkdir -p $GOPATH/src/

# Copy the vendor directory into the GOPATH.
cp -r $PWD/vendor/* $GOPATH/src
ln -s $PWD $GOPATH/src/{name}

%go_tool build -x -o %{name}-%{version}

install -d -m 0755 %{buildroot}%{_bindir}
install -D -m 0755 %{name}-%{version} %{buildroot}%{_bindir}/%{name}

%if %{with systemd}
install -d -m 0755 %{buildroot}%{_unitdir}
install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/%{name}.service

install -d -m 0755 %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}

install -d -m 0755 %{buildroot}%{_localstatedir}/adm/fillup-templates
install -m 0644 %{SOURCE10} %{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}

install -d -m 0755 %{buildroot}%{_sysconfdir}/%{name}
install -D -m 0644 %{SOURCE11} %{buildroot}%{_sysconfdir}/%{name}/%{name}.json

install -d -m 750 %{buildroot}%{_localstatedir}/lib/%{name}

getent group %{name} >/dev/null || %{_sbindir}/groupadd -r %{name}
getent passwd %{name} >/dev/null || %{_sbindir}/useradd -r -g %{name} -d %{home_dir} -s /bin/false -c "Consul daemon" %{name}

%if %{with systemd}
%service_add_pre %{name}.service

%if %{with systemd}
%{fillup_only -n %{name} %{name}}
%service_add_post %{name}.service

%if %{with systemd}
%service_del_preun %{name}.service

%if %{with systemd}
%service_del_postun %{name}.service


%if %{with systemd}
%attr(0644,root,root) %{_unitdir}/%{name}.service


%dir %attr(0750,%{name},root) %{_localstatedir}/lib/%{name}
%dir %config(noreplace) %attr(0750,root,%{name}) %{_sysconfdir}/%{name}
%config(noreplace) %attr(0640,root,%{name}) %{_sysconfdir}/%{name}/%{name}.json