File gobgp.spec of Package gobgp

#
# spec file for package gobgp
#
# Copyright (c) 2021-2025, Martin Hauke <mardnh@gmx.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/
#

%define gobgpd_user  gobgpd
%define gobgpd_group gobgpd
%define gobgpd_home  %{_localstatedir}/lib/gobgp

Name:           gobgp
Version:        3.37.0
Release:        0
Summary:        BGP daemon and client implemented in Go
License:        MIT
Group:          BGP implemented in Go
URL:            https://osrg.github.io/gobgp/
#Git-Clone:     https://github.com/osrg/gobgp.git
Source:         https://github.com/osrg/gobgp/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        gobgpd.conf
BuildRequires:  go >= 1.22.7
BuildRequires:  golang-packaging
Requires(pre):  shadow
%{go_provides}

%description
GoBGP is an open source BGP implementation designed from scratch for
modern environment and implemented in Go. It is designed to exploit
multicore processors and can be easily integrated with othersoftware
through an RPC API.

%prep
%autosetup -a 1

%build
for f in gobgp gobgpd; do
  go build \
  -mod=vendor \
  -buildmode=pie \
  -o "$f" "./cmd/$f"
done

%install
for f in gobgp gobgpd; do
  install -D -m0755 "$f" "%{buildroot}%{_bindir}/$f"
done

install -d %{buildroot}%{_sysconfdir}/gobgpd
install -m 0640 %{SOURCE2} %{buildroot}%{_sysconfdir}/gobgpd/gobgpd.conf

install -d %{buildroot}%{_localstatedir}/lib/gobgp/
install -D -m 0644 ./tools/contrib/centos/gobgpd.service %{buildroot}%{_unitdir}/gobgpd.service

install -D -m 0644 tools/completion/gobgp-completion.bash %{buildroot}%{_datadir}/bash-completion/completions/gobgp-completion.bash
install -D -m 0644 tools/completion/zsh/_gobgp %{buildroot}%{_sysconfdir}/zsh_completion.d/_gobgp

%pre
%service_add_pre gobgpd.service
%{_sbindir}/groupadd -r %{gobgpd_group} &>/dev/null || :
%{_sbindir}/useradd -g %{gobgpd_group} -s /bin/false -r -c "GoBGP Daemon" -d %{gobgpd_home} %{gobgpd_group} &>/dev/null || :

%preun
%service_del_preun gobgpd.service

%post
%service_add_post gobgpd.service

%postun
%service_del_postun gobgpd.service

%files
%license LICENSE
%doc README.md
%doc docs/sources/*
%{_bindir}/gobgp
%{_bindir}/gobgpd
%{_datadir}/bash-completion/completions/gobgp-completion.bash
%{_unitdir}/gobgpd.service
%dir %{_sysconfdir}/zsh_completion.d
%config %{_sysconfdir}/zsh_completion.d/
%dir               %attr(-,%{gobgpd_user},%{gobgpd_group}) %{_localstatedir}/lib/%{name}/
%dir               %attr(-,%{gobgpd_user},%{gobgpd_group}) %{_sysconfdir}/gobgpd/
%config(noreplace) %attr(-,%{gobgpd_user},%{gobgpd_group}) %{_sysconfdir}/gobgpd/gobgpd.conf

%changelog
openSUSE Build Service is sponsored by