File matterbridge.spec of Package matterbridge
#
# spec file for package matterbridge
#
# Copyright (c) 2021 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/
#
%define         daemon_group matterbridge
%define         daemon_user matterbridge
Name:           matterbridge
Version:        1.26.0
Release:        0
Summary:        A simple chat bridge
License:        Apache-2.0
Group:          Productivity/Networking/Instant Messenger
URL:            https://github.com/42wim/matterbridge
Source0:        https://github.com/42wim/matterbridge/archive/v%{version}/%{name}-%{version}.tar.gz
#Source1:        %%{name}-vendor-%%{version}.tar.gz
Source10:       %{name}-cron
Source99:       matterbridge-rpmlintrc
BuildRequires:  gcc-c++
BuildRequires:  config(go1.17)
BuildRequires:  cron
BuildRequires:  golang-packaging
BuildRequires:  systemd-rpm-macros
Requires:       cron
Requires(pre):  shadow
%{?systemd_requires}
%{go_nostrip}
%{go_provides}
%{go_exclusivearch}
%description
Bridges between a growing number of protocols.
%prep
%setup -q
sed -i -e 's|bridge.toml|matterbridge.toml|g' contrib/matterbridge.service
# delay start, because some other services, like matrix, sould start before matterbridge starts.
# And we do not known which other service are use matterbridge.
# And it should not only restart after boot. It should also restart when other service restart.
sed -i -e '/^\[Service\]$/a ExecStartPre=\/bin\/sleep 30' contrib/matterbridge.service
# Try other
sed -i -e '/^After=network.target$/a \# Uncomment the following lines if you user matterbridge for such other service.' contrib/matterbridge.service
sed -i -e '/^\# Uncomment the following lines if you user matterbridge for such other service.$/a \#After=matrix-synapse.service' contrib/matterbridge.service
%build
export GOFLAGS="$GOFLAGS -mod=vendor"
%{goprep} github.com/42wim/matterbridge
%{gobuild}
%install
%{goinstall}
#%%{gosrc}
# DownloadPath
mkdir -p %{buildroot}%{_localstatedir}/lib/%{name}
# systemd
install -D -m 644 contrib/matterbridge.service %{buildroot}%{_unitdir}/matterbridge.service
install -D -m 644 contrib/matterbridge.service %{buildroot}%{_sysconfdir}/systemd/system/matterbridge.service # To unccomment After=foo.service lines
mkdir -p %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcmatterbridge
# config
install -D -m 644 matterbridge.toml.sample %{buildroot}%{_sysconfdir}/matterbridge/matterbridge.toml.sample
install -D -m 644 matterbridge.toml.simple %{buildroot}%{_sysconfdir}/matterbridge/matterbridge.toml.simple
# CronJob
install -d -m 0755 %{buildroot}%{_sysconfdir}/cron.d
install -D -m 0644 %{SOURCE10} %{buildroot}%{_sysconfdir}/cron.d/%{name}
%{gofilelist}
%check
export GOFLAGS="$GOFLAGS -mod=vendor"
%{gotest} github.com/42wim/matterbridge
%pre
%service_add_pre matterbridge.service
# create daemon group, if not existing
if
   getent group %{daemon_group} > /dev/null
then
   : OK group %{daemon_group} already present
else
   groupadd -r %{daemon_group} 2>/dev/null || :
fi
# create daemon user, if not existing
if
   getent passwd %{daemon_user} > /dev/null
then
   : OK user %{daemon_user} already present
else
   useradd -r -g %{daemon_group} -s /bin/bash -c "Matterbridge daemon" -d %{_localstatedir}/lib/%{name} %{daemon_user} 2>/dev/null || :
fi
%post
%service_add_post matterbridge.service
%preun
%service_del_preun matterbridge.service
%postun
%service_del_postun matterbridge.service
%files -f file.lst
%license LICENSE
%doc README.md
%dir %{_sysconfdir}/systemd
%dir %{_sysconfdir}/systemd/system
%config(noreplace) %{_sysconfdir}/systemd/system/matterbridge.service
%config(noreplace) %{_sysconfdir}/cron.d/%{name}
%{_unitdir}/matterbridge.service
%{_sbindir}/rc%{name}
%{_bindir}/%{name}
%defattr(0640,root,matterbridge,750)
%dir %{_sysconfdir}/%{name}
%{_sysconfdir}/%{name}/*.toml.*
%defattr(0660,root,matterbridge,770)
%{_localstatedir}/lib/%{name}
%changelog