File gotosocial.spec of Package gotosocial

#
# spec file for package gotosocial
#
# Copyright (c) 2022 SUSE LLC
#
# 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:           gotosocial
Version:        0.20.1
Release:        0
Summary:        An ActivityPub social network server, written in Golang
License:        AGPL-3.0-only
Url:            https://docs.gotosocial.org/en/latest/
Source0:        https://codeberg.org/superseriousbusiness/%{name}/releases/download/v%{version}/%{name}-%{version}-source-code.tar.gz#/%{name}-%{version}.tar.gz
Source1:        https://codeberg.org/superseriousbusiness/%{name}/releases/download/v%{version}/%{name}_%{version}_web-assets.tar.gz#/%{name}-%{version}_web-assets.tar.gz
Source2:        gotosocial.sysusers
BuildRequires:  golang(API) = 1.24
BuildRequires:  golang-packaging
BuildRequires:  pkgconfig(systemd)
BuildRequires:  sysuser-shadow
BuildRequires:  sysuser-tools
BuildRequires:  git
BuildRequires:  rsync
BuildRequires:  sed
BuildRequires:  zstd
%{?systemd_ordering}
%sysusers_requires

%description
With GoToSocial, you can keep in touch with your friends, post, read, and share
images and articles. All without being tracked or advertised to!

%prep
%autosetup -p1 -a1 -c

%build
sed -i 's/\${VERSION:-$(git describe --tags --abbrev=0)}/%{version}/' ./scripts/build.sh
./scripts/build.sh

%sysusers_generate_pre %{SOURCE2} %{name}

%install
install -D -m 0755 gotosocial %{buildroot}%{_sbindir}/gotosocial

install -D -m 0750 -d %{buildroot}/var/lib/%{name}/{,.cache/} %{buildroot}/etc/%{name}/
install -D -m 0755 -d %{buildroot}%{_datadir}/%{name}/ %{buildroot}%{_docdir}/%{name}/

install -D -m 0644 example/gotosocial.service   %{buildroot}%{_unitdir}/%{name}.service
install -D -m 0644 %{SOURCE2}                   %{buildroot}%{_sysusersdir}/%{name}.conf
install    -m 0640 example/config.yaml          %{buildroot}/etc/%{name}/config.yaml
rsync -qa --chmod=u=rwX,go=rX   web/template    %{buildroot}/var/lib/%{name}/web/
rsync -qa --chmod=u=rwX,go=rX   web/assets      %{buildroot}%{_datadir}/%{name}/web/
rsync -qa --exclude=**/.cache   docs            %{buildroot}%{_docdir}/%{name}/
tar -xzf %{SOURCE1} -C %{buildroot}%{_datadir}/%{name}/web/assets/ web/assets/dist --strip-components=2

sed -i 's|ExecStart=/gotosocial/gotosocial|ExecStart=/usr/sbin/gotosocial|' %{buildroot}%{_unitdir}/%{name}.service
sed -i 's|WorkingDirectory=/gotosocial|WorkingDirectory=/var/lib/gotosocial|' %{buildroot}%{_unitdir}/%{name}.service
sed -i 's|config\.yaml|/etc/gotosocial/config.yaml|g' %{buildroot}%{_unitdir}/%{name}.service
sed -i '/^#/d' %{buildroot}%{_unitdir}/%{name}.service

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

%post
%service_add_post %{name}.service

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%files
%doc *.md
%license LICENSE
%{_sbindir}/gotosocial
%{_unitdir}/%{name}.service
%{_sysusersdir}/%{name}.conf
%dir                %attr(-,%{name},%{name})  /var/lib/%{name}/{,web/assets,.cache/}
%dir                %attr(-,%{name},%{name})  /var/lib/%{name}/web
%config(noreplace)  %attr(-,%{name},%{name})  /var/lib/%{name}/web/template
%config(noreplace)  %attr(-,%{name},%{name})  /etc/%{name}/
%dir                %attr(-,%{name},%{name})  %{_datadir}/%{name}
%dir                %attr(-,%{name},%{name})  %{_datadir}/%{name}/web
%attr(-,%{name},%{name})  %{_datadir}/%{name}/web/assets
%{_docdir}/%{name}

%changelog
openSUSE Build Service is sponsored by