# Do not try to package empty debug_package
%global debug_package %{nil}

Name:		dendrite
Version:	0.8.5
Release:	1%{?dist}
Summary:	Dendrite is a second-generation Matrix homeserver written in Go!

License:	ASL 2.0
URL:		https://github.com/matrix-org/%{name}
Source0:	%{url}/archive/v%{version}.tar.gz
Source1:	dendrite-monolith-server.service

BuildRequires:	golang >= 1.15
BuildRequires:	sqlite-devel
BuildRequires:	pam-devel
BuildRequires:	systemd
Recommends:	postgresql-server

%description
Dendrite is a second-generation Matrix homeserver written in Go. It intends to provide an efficient, reliable and scalable alternative to Synapse

%prep
%setup -q -n %{name}-%{version}

%build
./build.sh

%install
%{__rm} -rf %{buildroot}
install -d -m 0755 %{buildroot}%{_bindir}
install -d -m 0755 %{buildroot}%{_bindir}/%{name}
for bin in $(ls bin); do
	install -m 755 bin/$bin %{buildroot}%{_bindir}/%{name}/$bin
done
install -d -m 0755 %{buildroot}%{_sysconfdir}/%{name}
install -m 660 dendrite-sample.monolith.yaml %{buildroot}%{_sysconfdir}/%{name}/dendrite.yaml
install -d -m 0755 %{buildroot}/%{_unitdir}
install -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}-monolith-server.service
install -d -m 0755 %{buildroot}%{_sharedstatedir}/%{name}
install -d -m 0755 %{buildroot}%{_localstatedir}/log/%{name}

%clean
%{__rm} -rf %{buildroot}

%pre
getent group %{name} > /dev/null || groupadd -r %{name}
getent passwd %{name} > /dev/null || \
	useradd -r -g %{name} -s /bin/bash \
	-d %{_sharedstatedir}/%{name} \
	-c "Dendrite account" %{name}

%post
%systemd_post %{name}-monolith-server.service

%preun
%systemd_preun %{name}-monolith-server.service

%postun
%systemd_postun %{name}-monolith-server.service

# find a better way to package these...
%files
%defattr(-,root,root,-)
%{_unitdir}/%{name}-monolith-server.service
%{_bindir}/%{name}/create-account
%{_bindir}/%{name}/dendrite-demo-pinecone
%{_bindir}/%{name}/dendrite-demo-yggdrasil
%{_bindir}/%{name}/dendrite-monolith-server
%{_bindir}/%{name}/dendrite-polylith-multi
%{_bindir}/%{name}/dendritejs-pinecone
%{_bindir}/%{name}/dendrite-upgrade-tests
%{_bindir}/%{name}/furl
%{_bindir}/%{name}/generate-config
%{_bindir}/%{name}/generate-keys
%{_bindir}/%{name}/goose
%{_bindir}/%{name}/main.wasm
%{_bindir}/%{name}/resolve-state
%attr(0664,%{name},%{name}) %config(noreplace) %{_sysconfdir}/%{name}/dendrite.yaml
%attr(0755,%{name},%{name}) %dir %{_sharedstatedir}/%{name}
%attr(0755,%{name},%{name}) %dir %{_localstatedir}/log/%{name}

%changelog
* Sat May 14 2022 voidanix <voidanix@keyedlimepie.org> 0.8.5-1
- Update to 0.8.5

* Sun Apr 24 2022 voidanix <voidanix@keyedlimepie.org> 0.8.1-1
- Update to 0.8.1

* Sun Nov 28 2021 voidanix <voidanix@keyedlimepie.org> 0.5.1-1
- Update to 0.5.1

* Wed Aug 18 2021 voidanix <voidanix@keyedlimepie.org> 0.5.0rc1-1
- Update to latest git snapshot

* Sun Jul 4 2021 voidanix <voidanix@keyedlimepie.org> 0.3.11-4
- Update to latest git snapshot

* Fri May 28 2021 voidanix <voidanix@keyedlimepie.org> 0.3.11-3
- Update to latest git snapshot, add patch for room regexes

* Wed Mar 31 2021 voidanix <voidanix@keyedlimepie.org> 0.3.11-2
- Update to git snapshot to unblock appservices

* Wed Mar 3 2021 voidanix <voidanix@keyedlimepie.org> 0.3.11-1
- Update to 0.3.11

* Wed Feb 17 2021 voidanix <voidanix@keyedlimepie.org> 0.3.10-1
- Update to 0.3.10
- Don't require postgres for the systemd unit

* Sun Feb 14 2021 voidanix <voidanix@keyedlimepie.org> 0.3.9-1
- Initial build