File go-mmproxy.spec of Package go-mmproxy

#
# spec file for package go-mmproxy
#
# Copyright (c) 2024 SUSE LLC
# Copyright (c) 2024 Georg Pfuetzenreuter <mail+rpm@georg-pfuetzenreuter.net>
#
# 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/
#


Name:           go-mmproxy
Version:        2.1+git8.006247c
Release:        0
Summary:        Golang implementation of MMProxy
License:        BSD-3-Clause
Group:          Productivity/Networking/Routing
URL:            https://github.com/path-network/go-mmproxy
Source0:        %{name}-%{version}.tar.gz
Source1:        README.SUSE
Source2:        %{name}.sysuser
Source3:        %{name}.sysconfig
Source4:        %{name}.service
Source5:        %{name}.apparmor
Patch0:         gh-pr-31_comments.patch
BuildRequires:  apparmor-rpm-macros
BuildRequires:  go >= 1.21
BuildRequires:  golang-packaging
BuildRequires:  sysuser-tools
%systemd_ordering

%description
This is a Go reimplementation of mmproxy, created to improve on mmproxy's runtime stability while providing potentially greater performance in terms of connection and packet throughput.

go-mmproxy is a standalone application that unwraps HAProxy's PROXY protocol (also adopted by other projects such as NGINX) so that the network connection to the end server comes from client's - instead of proxy server's - IP address and port number.

%prep
%autosetup -p1

cp %{SOURCE1} .

%build
go build -mod=vendor -v -p 4 -x -buildmode=pie

%sysusers_generate_pre %{SOURCE2} %{name} system-user-%{name}

%install
install -vdm 0755 %{buildroot}%{_bindir} %{buildroot}%{_sbindir} %{buildroot}%{_fillupdir} %{buildroot}%{_unitdir} %{buildroot}%{_sysusersdir}
install -vm 0755 %{name} %{buildroot}%{_bindir}
install -vm 0644 %{SOURCE2} %{buildroot}%{_sysusersdir}
install -vm 0644 %{SOURCE3} %{buildroot}%{_fillupdir}/sysconfig.%{name}
install -vm 0644 %{SOURCE4} %{buildroot}%{_unitdir}/%{name}.service
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}

install -Dvm 0644 %{SOURCE5} %{buildroot}%{_sysconfdir}/apparmor.d/%{name}

%check
%{gotest} .

%pre -f %{name}.pre
%service_add_pre %{name}.service

%post
%{fillup_only -n %{name}}
%{apparmor_reload %{_sysconfdir}/apparmor.d/%{name}}
%service_add_post %{name}.service

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%files
%license LICENSE
%doc README.md README.SUSE
%{_bindir}/%{name}
%{_sbindir}/rc%{name}
%{_sysusersdir}/%{name}.sysuser
%{_unitdir}/%{name}.service
%{_fillupdir}/sysconfig.%{name}
%dir %{_sysconfdir}/apparmor.d
%config %{_sysconfdir}/apparmor.d/%{name}

%changelog
openSUSE Build Service is sponsored by