File mattermost-server.spec of Package mattermost-server
#
# spec file for package mattermost-server
#
# 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/
#
%define debug_package %{nil}
%define mm_dir /srv/mattermost
Name: mattermost-server
Version: 10.9.1
Release: 0
Summary: Workplace messaging for the web, PCs and phones - Open Source Team Edition
License: MIT
Group: Productivity/Networking/Email/Servers
URL: https://about.mattermost.com/download/
Source: https://releases.mattermost.com/%{version}/mattermost-team-%{version}-linux-amd64.tar.gz
Source99: %{name}-rpmlintrc
Patch1: %{name}.patch
ExclusiveArch: x86_64
BuildRequires: fdupes
BuildRequires: systemd-rpm-macros
BuildRequires: shadow
Conflicts: mattermost-server-enterprise
%{?systemd_requires}
%description
Modern, self-hosted messaging across web, PC and phones, built on open source software
%prep
%setup -q -n mattermost
%patch -P1 -p1
# rpmlintrc
find ./client -type f -exec chmod -x {} \;
find ./fonts -type f -exec chmod -x {} \;
%build
%install
mkdir -p %{buildroot}/%{mm_dir}/ %{buildroot}/%{mm_dir}/data
mkdir -p %{buildroot}/%{_localstatedir}/log/mattermost
mkdir -p %{buildroot}/%{_prefix}/lib/systemd/system/
mkdir -p %{buildroot}/%{_sysconfdir}/mattermost
mkdir -p %{buildroot}/%{_sysconfdir}/nginx/vhosts.d
mkdir -p %{buildroot}/%{_sbindir}
mkdir -p %{buildroot}/%{_sysconfdir}/logrotate.d
mkdir -p %{buildroot}%{_sysconfdir}/apache2/vhosts.d
sed -i -s 's#^ *"DataSource":.*# "DataSource": "mmuser:THISISMYMMDBPASSWORD@tcp\(localhost:3306\)\/mattermost?charset=utf8mb4,utf8\&readTimeout=30s\&writeTimeout=30s",#g' config/config.json
sed -i -s 's#:8065#127.0.0.1:8065#' config/config.json
# disable builtin tracking https://jira.kopano.io/browse/KM-1
sed -i '/EnableDiagnostics/ s/true/false/g' config/config.json
# set some default values https://jira.kopano.io/browse/KM-15
sed -i '/EnablePostUsernameOverride/ s/false/true/g' config/config.json
sed -i '/EnablePostIconOverride/ s/false/true/g' config/config.json
sed -i '/EnableTeamCreation/ s/true/false/g' config/config.json
# enable mail batching by default
sed -i '/EnableEmailBatching/ s/false/true/g' config/config.json
sed -i'' -e 's|"SiteURL": "",|"SiteURL": "http://mattermost.example.org",|g' config/config.json
cp -a MIT-COMPILED-LICENSE.md NOTICE.txt README.md bin fonts i18n mattermost.nginx templates client %{buildroot}/%{mm_dir}/
cp -a config/config.json %{buildroot}/%{_sysconfdir}/mattermost
#cp -a config/README.md %%{buildroot}/%%{_sysconfdir}/mattermost
# systemd
cp -a mattermost.service %{buildroot}%{_unitdir}/
install -d -m 0755 %{buildroot}%{_sbindir}/
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcmattermost
#
cp -a mattermost.nginx %{buildroot}/%{_sysconfdir}/nginx/vhosts.d/mattermost.conf
cp -a mattermost.apache2 %{buildroot}%{_sysconfdir}/apache2/vhosts.d/mattermost.conf
cp -a mattermost.logrotate %{buildroot}/%{_sysconfdir}/logrotate.d/mattermost
cp -a mattermost-db-configure %{buildroot}/%{_sbindir}/mattermost-db-configure
cp -a mattermost-platform %{buildroot}/%{_sbindir}/mattermost-platform
ln -sfv %{_localstatedir}/log/mattermost %{buildroot}/%{mm_dir}/logs
ln -sfv %{_sysconfdir}/mattermost %{buildroot}/%{mm_dir}/config
%fdupes %{buildroot}/srv/mattermost/client
%pre
%{?_unitdir:%{?suse_version:%service_add_pre mattermost.service}}
%{_bindir}/getent group mattermost >/dev/null 2>/dev/null || \
%{_sbindir}/groupadd -r mattermost
%{_bindir}/getent passwd mattermost >/dev/null 2>/dev/null || \
%{_sbindir}/useradd -c "Mattermost unprivileged account" \
-g mattermost -r mattermost
%post
chown -Rh mattermost:mattermost %{_localstatedir}/log/mattermost 2>/dev/null || :
chown mattermost:mattermost %{mm_dir} 2>/dev/null || :
%{?_unitdir:%{?suse_version:%service_add_post mattermost.service}}
%{?_unitdir:%{!?suse_version:%systemd_post mattermost.service}}
echo "If you want to create the mattermost database easily, you can use the command \"mattermost-db-configure\"."
%preun
%{?_unitdir:%{?suse_version:%service_del_preun mattermost.service}}
%{?_unitdir:%{!?suse_version:%systemd_preun mattermost.service}}
%{!?_unitdir:%stop_on_removal mattermost}
%postun
%{?_unitdir:%{?suse_version:%service_del_postun mattermost.service}}
%{?_unitdir:%{!?suse_version:%systemd_postun_with_restart mattermost.service}}
%{!?_unitdir:%insserv_cleanup}
%{!?_unitdir:%restart_on_update mattermost}
%files
%license MIT-COMPILED-LICENSE.md
%doc NOTICE.txt README.md
%attr(0770,mattermost,mattermost) %dir %{mm_dir}
%attr(0770,mattermost,mattermost) %dir %{mm_dir}/data
%attr(0640,mattermost,mattermost) %config(noreplace) %{_sysconfdir}/mattermost/config.json
%attr(0770,mattermost,mattermost) %dir %{_localstatedir}/log/mattermost
%attr(0755,root,root) %{_sbindir}/mattermost-db-configure
%attr(0755,root,root) %{_sbindir}/mattermost-platform
%dir %{_sysconfdir}/nginx
%dir %{_sysconfdir}/nginx/vhosts.d
%dir %{_sysconfdir}/mattermost
%dir %{_sysconfdir}/logrotate.d
%config(noreplace) %{_sysconfdir}/nginx/vhosts.d/mattermost.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/mattermost
%{mm_dir}/bin/
%{mm_dir}/config
%{mm_dir}/fonts/
%{mm_dir}/i18n/
%{mm_dir}/logs
%{mm_dir}/templates/
%{mm_dir}/client/
%{mm_dir}/MIT-COMPILED-LICENSE.md
%{mm_dir}/NOTICE.txt
%{mm_dir}/README.md
%{mm_dir}/mattermost.nginx
%{_unitdir}/mattermost.service
%{_sbindir}/rcmattermost
%dir %{_sysconfdir}/apache2
%dir %{_sysconfdir}/apache2/vhosts.d
%config(noreplace) %attr(0640,root,www) %{_sysconfdir}/apache2/vhosts.d/mattermost.conf
%changelog