File rest-server.spec of Package rest-server

#
# spec file for package restic
#
# Copyright (c) 2021 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

Name:           rest-server
Version:        0.13.0
Release:        0
License:        BSD-2-Clause
Summary:        Implementation of restic's REST backend API
Url:            https://github.com/restic/rest-server/releases
Group:          Productivity/Archiving/Backup
Source:         %{name}-%{version}.tar.xz
Source1:	vendor.tar.gz
Source2:        rest-server.sysconfig
Source3:	rest-server-user.conf
Source4:	rest-server.conf
Patch1:         rest-server-0.12.0_fix_service_file.patch
BuildRequires:  golang(API) >= 1.17
BuildRequires:  golang-packaging
Requires(pre):  shadow
BuildRequires:  pkgconfig(systemd)
BuildRequires:  sysuser-tools
Requires(post): %fillup_prereq
%{?systemd_requires}
%sysusers_requires

%description
Rest Server is a high performance HTTP server that implements restic's REST backend API.

%prep
%setup -q
%setup -q -T -D -a 1
%patch -p1 -P 1

%build
%sysusers_generate_pre %{SOURCE3} %{name} %{name}-user.conf
go run build.go

%install
install -D -m 0755 rest-server %{buildroot}%{_sbindir}/rest-server
install -D -m 0644 examples/systemd/rest-server.service %{buildroot}%{_unitdir}/rest-server.service
install -D -m 0644 examples/systemd/rest-server.socket %{buildroot}%{_unitdir}/rest-server.socket
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
install -D -m 0644 %{SOURCE2} %{buildroot}%{_fillupdir}/sysconfig.%{name}
install -D -m 0644 %{SOURCE4} %{buildroot}%{_tmpfilesdir}/rest-server.conf
mkdir -p %{buildroot}%{_sysusersdir}
install -m 0644 %{SOURCE3} %{buildroot}%{_sysusersdir}/

%pre
%service_add_pre rest-server.service

%post
%fillup_only rest-server
%service_add_post rest-server.service
%tmpfiles_create %{_tmpfilesdir}/rest-server.conf

%preun
%service_del_preun rest-server.service

%postun
%service_del_postun rest-server.service

%files
%defattr(-,root,root)
%doc *.md LICENSE
%doc docker/
%{_sbindir}/rest-server
%{_sbindir}/rcrest-server
%{_unitdir}/rest-server.service
%{_unitdir}/rest-server.socket
%{_fillupdir}/sysconfig.%{name}
%{_tmpfilesdir}/rest-server.conf
%{_sysusersdir}/%{name}-user.conf
%dir %attr(0755,rest-server,rest-server) %ghost /run/%{name}
openSUSE Build Service is sponsored by