File mattermost-server.spec of Package mattermost-server

#
# spec file for package mattermost-server
#
# 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 debug_package %{nil}
%define mm_dir /opt/mattermost
Name:           mattermost-server
Version:        10.12.2
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/
Source0:        mattermost-team-%{version}-linux-amd64.tar.gz
#Source: https://releases.mattermost.com/%{mattermost_release}/mattermost-team-%{mattermost_release}-linux-amd64.tar.gz
Source1:        system-user-mattermost.conf
#PATCH-FEATURE kopano.patch
Patch1:         kopano.patch
BuildRequires:  fdupes
BuildRequires:	shadow
BuildRequires:  sysuser-shadow
BuildRequires:  sysuser-tools
%{?systemd_requires}
PreReq:         permissions
Requires:       user(mattermost)
Provides:       system-user-mattermost = %{version}-%{release}
Obsoletes:      system-user-mattermost < %{version}-%{release}
Conflicts:      mattermost-server-enterprise

%description
Modern, self-hosted messaging across web, PC and phones, built on open source software

%define apache_dir %{_sysconfdir}/apache2

%package -n system-user-mattermost
Summary:        System user for the mattermost
%{sysusers_requires}

%description -n system-user-mattermost
System user for the mattermost.

%prep
%autosetup -n mattermost -p1

%build

%install
b="%{buildroot}";
bdir="$b/%{mm_dir}/";
mkdir -p "$bdir" "$bdir/data" "$b/%{_localstatedir}/log/mattermost" "$b/%{_prefix}/lib/systemd/system/" "$b/%{_sysconfdir}/mattermost" "$b/%{_sysconfdir}/nginx/vhosts.d" "$b/%{_sbindir}" "$b/%{_sysconfdir}/logrotate.d";
mkdir -p "$b/%{apache_dir}/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 valuetuptimes 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 ENTERPRISE-EDITION-LICENSE.txt NOTICE.txt README.md bin fonts i18n mattermost.nginx templates webapp "$bdir/"
cp -a MIT-COMPILED-LICENSE.md NOTICE.txt README.md bin fonts i18n mattermost.nginx templates client "$bdir/"
cp -a config/config.json "$b/%{_sysconfdir}/mattermost"
cp -a config/README.md "$b/%{_sysconfdir}/mattermost"
echo "[Install]
WantedBy=multi-user.target" >> mattermost.service
cp -a mattermost.service "$b/%{_unitdir}"
cp -a mattermost.nginx "$b/%{_sysconfdir}/nginx/vhosts.d/mattermost.conf"
cp -a mattermost.apache2 "$b/%{apache_dir}/vhosts.d/mattermost.conf"
cp -a mattermost.logrotate "$b/%{_sysconfdir}/logrotate.d/mattermost"
cp -a mattermost-db-configure "$b/%{_sbindir}/mattermost-db-configure"
cp -a mattermost-platform "$b/%{_sbindir}/mattermost-platform"
ln -sfv %{_localstatedir}/log/mattermost "$bdir/logs"
ln -sfv %{_sysconfdir}/mattermost "$bdir/config"
install -D -m 0644 %{SOURCE1} %{buildroot}%{_sysusersdir}/system-user-mattermost.conf

%fdupes %{buildroot}/opt

%pre
%{?_unitdir:%{?suse_version:%service_add_pre mattermost.service}}

%post
chown -Rh mattermost:mattermost %{_localstatedir}/log/mattermost 2>/dev/null || :
chown mattermost:mattermost /opt/mattermost 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
%attr(0770,mattermost,mattermost) /opt/mattermost/
%attr(0640,mattermost,mattermost) %config(noreplace) %{_sysconfdir}/mattermost/config.json
%attr(0640,mattermost,mattermost) %{_sysconfdir}/mattermost/README.md
%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
%{_unitdir}/mattermost.service
%dir %{apache_dir}
%dir %{apache_dir}/vhosts.d
%config(noreplace) %attr(0640,root,www) %{apache_dir}/vhosts.d/mattermost.conf

%files -n system-user-mattermost
%{_sysusersdir}/system-user-mattermost.conf

%changelog
openSUSE Build Service is sponsored by