File writefreely.spec of Package writefreely

#
# spec file for package writefreely
#
# Copyright (c) 2025 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:           writefreely
Version:        0.15.1
Release:        0
Summary:        Clean, Markdown-based publishing platform made for writers
License:        Apache-2.0
URL:            https://github.com/writefreely/writefreely
Source:         %{name}-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        static_css.tar.gz
Source3:        prose.tar.gz
Source11:       Makefile
Source12:       PACKAGING_README.md
Source13:       prepare_static_css.sh
Source21:       system-user-%{name}.conf
Source22:       %{name}.service
Source31:       README_openSUSE.md
BuildRequires:  golang(API) >= 1.23
BuildRequires:  rsync
BuildRequires:  git-core
BuildRequires:  sysuser-tools

%description
WriteFreely is a clean, minimalist publishing platform made for writers. Start
a blog, share knowledge within your organization, or build a community around
the shared act of writing.

%prep
%autosetup -p 1 -a 1
rm -rf static/css/
tar xf %{SOURCE2}
rm -rf prose
tar xf %{SOURCE3}

%build
go build \
   -mod=vendor \
   -buildmode=pie \
   -tags="netgo,sqlite" \
   -ldflags="-X github.com/writefreely/writefreely.softwareVer=v%{version}" \
   -o bin/%{name} ./cmd/%{name}

# system-user
%sysusers_generate_pre %{SOURCE21} user

%install
install -D -m 0755 bin/%{name} %{buildroot}/%{_bindir}/%{name}

mkdir -p %{buildroot}/%{_sysconfdir}/%{name}/
mkdir -p %{buildroot}/%{_sharedstatedir}/%{name}/

rsync -a --exclude=".*" templates %{buildroot}/%{_sharedstatedir}/%{name}/
rsync -a --exclude=".*" pages %{buildroot}/%{_sharedstatedir}/%{name}/
rsync -a --exclude=".*" static %{buildroot}/%{_sharedstatedir}/%{name}/
rm -rf %{buildroot}/%{_sharedstatedir}/%{name}/static/local
scripts/invalidate-css.sh %{buildroot}/%{_sharedstatedir}/%{name}/
mkdir %{buildroot}/%{_sharedstatedir}/%{name}/keys/

# remove executable bit from files
find %{buildroot}/%{_sharedstatedir}/%{name} -type f -print0 | xargs -0 chmod 644

# README_openSUSE.md
mkdir -p %{buildroot}/%{_docdir}/%{name}/
install -D -m 0644 %{SOURCE31} %{buildroot}/%{_docdir}/%{name}/

# systemd unit
install -D -m 0644 %{SOURCE22} %{buildroot}/%{_unitdir}/%{name}.service

# system user
install -Dm644 %{SOURCE21} %{buildroot}%{_sysusersdir}/system-user-%{name}.conf

%check
%{buildroot}/%{_bindir}/%{name} --version | grep v%{version}

%pre -f user.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 README.md
%license LICENSE
%{_bindir}/%{name}
%{_unitdir}/%{name}.service
%{_docdir}/%{name}/README_openSUSE.md
%{_sysusersdir}/system-user-%{name}.conf

# /etc/writefreely/config.ini
%dir %attr(750,root,%{name}) %{_sysconfdir}/%{name}/
%ghost %config(noreplace) %attr(640,%{name},%{name}) %{_sharedstatedir}/%{name}/config.ini

#
%dir %attr(750,%{name},%{name}) %{_sharedstatedir}/%{name}/
%dir %attr(750,%{name},%{name}) %{_sharedstatedir}/%{name}/keys/
%dir %attr(750,%{name},%{name}) %{_sharedstatedir}/%{name}/pages/
%dir %attr(750,%{name},%{name}) %{_sharedstatedir}/%{name}/static/
%dir %attr(750,%{name},%{name}) %{_sharedstatedir}/%{name}/templates/
%attr(-,%{name},%{name}) %{_sharedstatedir}/%{name}/pages/*
%attr(-,%{name},%{name}) %{_sharedstatedir}/%{name}/static/*
%attr(-,%{name},%{name}) %{_sharedstatedir}/%{name}/templates/*
%ghost %config(noreplace) %attr(640,%{name},%{name}) %{_sharedstatedir}/%{name}/writefreely.db
%ghost %config(noreplace) %attr(640,%{name},%{name}) %{_sharedstatedir}/%{name}/keys/*

%changelog
openSUSE Build Service is sponsored by