File frp.spec of Package frp

#
# spec file for package frp
#
# Copyright (c) 2022-2023, 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 services frpc.service frps.service frpc@.service frps@.service
%define binaries frpc frps
Name:           frp
Version:        0.60.0
Release:        0
Summary:        A fast reverse proxy
License:        Apache-2.0
Group:          Productivity/Networking/Web/Proxy
URL:            https://github.com/fatedier/frp
#Git-Clone:     https://github.com/fatedier/frp.git
Source:         %{name}-%{version}.tar.zst
Source1:        vendor.tar.gz
Source2:        frpc.service
Source3:        frpc@.service
Source4:        frps.service
Source5:        frps@.service
Source6:        frp.sysusers
BuildRequires:  go >= 1.22
BuildRequires:  golang-packaging
BuildRequires:  systemd-rpm-macros
BuildRequires:  sysuser-tools
Provides:       group(frp)
Provides:       user(frp)
%{go_provides}
%{sysusers_requires}

%description
A reverse proxy that exposes a server behind a NAT or firewall to
the internet.

%prep
%autosetup -p 1 -a 1

%build
for f in %{binaries}; do
  go build \
  -mod=vendor \
  -buildmode=pie \
  -o "$f" "./cmd/$f"
done
%sysusers_generate_pre %{SOURCE6} %{name} %{name}.conf

%install
for f in %{binaries}; do
  install -Dm0755 "$f" "%{buildroot}%{_bindir}/$f"
done

#install -dm0750 %{buildroot}%{_sysconfdir}/%{name}
for f in %{binaries}; do
  install -Dm0640 "conf/$f.toml" "%{buildroot}%{_sysconfdir}/%{name}/$f.toml"
done
#install -m 0640 conf/frpc.ini %{buildroot}%{_sysconfdir}/%{name}/frpc.ini
#install -m 0640 conf/frps.ini %{buildroot}%{_sysconfdir}/%{name}/frps.ini

for service in %{services}; do
  install -Dm0644 %{_sourcedir}/$service %{buildroot}%{_unitdir}/$service
done

install -Dm0644 %{SOURCE6} %{buildroot}%{_sysusersdir}/%{name}.conf

%pre
%service_add_pre %{services}

%post
%service_add_post %{services}

%preun
%service_del_preun %{services}

%postun
%service_del_postun %{services}

%files
%license LICENSE
%doc README.md
#%doc conf/{frpc_full.ini,frps_full.ini}
%{_bindir}/frpc
%{_bindir}/frps
%dir               %attr(-,frp,frp) %{_sysconfdir}/frp
%config(noreplace) %attr(-,frp,frp) %{_sysconfdir}/frp/*.toml
#%config(noreplace) %attr(-,frp,frp) %{_sysconfdir}/frp/frps.ini
%{_unitdir}/frpc.service
%{_unitdir}/frps.service
%{_unitdir}/frpc@.service
%{_unitdir}/frps@.service
%{_sysusersdir}/%{name}.conf

%changelog
openSUSE Build Service is sponsored by