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 http://bugs.opensuse.org/
#

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

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

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

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

Name:           consul
Version:        1.16.2
Release:        0
Summary:        A tool for service discovery, monitoring and configuration
License:        Apache-2.0
Group:          System/Management
Url:            https://github.com/hashicorp/consul

Source0:        %{name}-%{version}.tar.gz
Source1:        %{name}-rpmlintrc
Source2:        %{name}.service
Source10:       %{name}.sysconfig
Source11:       %{name}.json
Source20:       consul-dns.xml
Source21:       consul-grpc.xml
Source22:       consul-https.xml
Source23:       consul-http.xml
Source24:       consul-lan-serf.xml
Source25:       consul-rpc.xml
Source26:       consul-wan-serf.xml
Source99:       vendor.tar.gz

BuildRequires:  golang(API) >= 1.21
%if 0%{?suse_version} >= 1210
BuildRequires: systemd-rpm-macros
%endif
%{?systemd_requires}
BuildRequires:  golang-packaging
BuildRequires:  xz

%if %{with systemd}
BuildRequires:  pkgconfig(systemd)
%{?systemd_requires}
%endif

Requires:  system-user-consul
Requires(pre):  %{fillup_prereq}

%go_provides
%{go_nostrip}

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


%prep
%setup -q -n %{name}-%{version} -a 99

%build
%go_tool build -mod=vendor -buildmode=pie -x -o %{name}-%{version}

%install
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}
%endif

install -D -m 0644 %{SOURCE10} %{buildroot}%{_fillupdir}/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}

# Install firewalld files
install -D -m644 %{SOURCE20} %{buildroot}%{_prefix}/lib/firewalld/services/consul-dns.xml
install -D -m644 %{SOURCE21} %{buildroot}%{_prefix}/lib/firewalld/services/consul-grpc.xml
install -D -m644 %{SOURCE22} %{buildroot}%{_prefix}/lib/firewalld/services/consul-https.xml
install -D -m644 %{SOURCE23} %{buildroot}%{_prefix}/lib/firewalld/services/consul-http.xml
install -D -m644 %{SOURCE24} %{buildroot}%{_prefix}/lib/firewalld/services/consul-lan-serf.xml
install -D -m644 %{SOURCE25} %{buildroot}%{_prefix}/lib/firewalld/services/consul-rpc.xml
install -D -m644 %{SOURCE26} %{buildroot}%{_prefix}/lib/firewalld/services/consul-wan-serf.xml

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


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


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


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


%files
%defattr(-,root,root,-)
%{_bindir}/consul

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

%{_sbindir}/rc%{name}
%{_fillupdir}/sysconfig.%{name}

%dir %{_prefix}/lib/firewalld
%dir %{_prefix}/lib/firewalld/services
%{_prefix}/lib/firewalld/services/*.xml

%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


%changelog
openSUSE Build Service is sponsored by