File webtrees.spec of Package webtrees

#
# spec file for package webtrees
#
# Copyright (c) 2020 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         webtreesdir       %{phplibdir}/%{name}
%if 0%{?suse_version}
# opensuse
%define         phplibdir         %{_datadir}/php7
%else
# non opensuse
%define         apache_user         apache
%define         apache_group        apache
%define         phplibdir         %{_datadir}/php
%endif
Name:           webtrees
Version:        2.0.10
Release:        0
Summary:        Online collaborative genealogy application
License:        GPL-3.0-only
Group:          Productivity/Networking/Web/Frontends
URL:            https://www.webtrees.net
Source0:        https://github.com/fisharebest/webtrees/releases/download/%{version}/webtrees-%{version}.zip
Source1:        webtrees.conf
BuildRequires:  apache-rpm-macros
BuildRequires:  php-devel >= 7.1
BuildRequires:  unzip
Requires:       httpd
Requires:       mysql
Requires:       php-curl
Requires:       php-gd
Requires:       php-iconv
Requires:       php-intl
Requires:       php-json
Requires:       php-mbstring
Requires:       php-mysql
Requires:       php-pdo
Requires:       php-session >= 7.1.8
Requires:       php-xml
Requires:       php-zip
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  fdupes
BuildRequires:  php-pear(htmlpurifier/HTMLPurifier)
Requires:       php-pear(htmlpurifier/HTMLPurifier)
%endif

%description
View and edit family history on your website, with collaboration, privacy, and
photo features. Webtrees works from standard GEDCOM files, and is therefore
compatible with every major desktop application; and it aims to be efficient
and effective by using the right combination of third-party tools, design
techniques and open standards.

%package config-apache
Summary:        Apache configuration for %{name}
Group:          Productivity/Networking/Web/Utilities
BuildRequires:  apache2
Requires:       apache2
Supplements:    packageand(apache2:%name)

%description config-apache
This subpackage contains the Apache configuration files

%prep
%setup -q -n webtrees
# remove .htaccess files
#find . -name \.htaccess -print | xargs rm -f

# remove several scripts not used in the package
rm -rf	vendor/ezyang/htmlpurifier/maintenance/

%build
# build .mo files
#find -type f -name '*.po' -exec "FN=`echo {} | cut -d'.' --complement -f2-` ; msgcat $FN.po | msgfmt -o $FN.mo - " -exec rm {} \;

%install
install -m 755 -d %{buildroot}%{webtreesdir}
cp -r . %{buildroot}%{webtreesdir}

# move data directory to /var/lib/ and set symlink
install -m 755 -d %{buildroot}%{_localstatedir}/lib/
mv %{buildroot}%{webtreesdir}/data %{buildroot}%{_localstatedir}/lib/%{name}
ln -s %{_localstatedir}/lib/%{name} %{buildroot}%{webtreesdir}/data

# install (empty) configuration-file
touch %{buildroot}%{_localstatedir}/lib/%{name}/config.ini.php

# install apache config-file and fix paths
install -m 755 -d %{buildroot}%{apache_sysconfdir}/conf.d
install -m 644 %{SOURCE1} %{buildroot}%{apache_sysconfdir}/conf.d/%{name}.conf
sed -i -e 's|WEBTREESDIR|%{webtreesdir}|g ;
	s|WEBDATAROOT|%{_localstatedir}/lib/%{name}|g ;
	s|PHPLIBDIR|%{phplibdir}|g' %{buildroot}%{apache_sysconfdir}/conf.d/%{name}.conf

%if 0%{?suse_version}
# replace htmlpurifier with shared pear library
ls -la %{buildroot}%{webtreesdir}/
ls -la %{buildroot}%{webtreesdir}/vendor
rm -rf %{buildroot}%{webtreesdir}/vendor/ezyang/htmlpurifier/library/*
for F in %{pear_phpdir}/HTMLPurifier* ;
	do ln -s $F %{buildroot}%{webtreesdir}/vendor/ezyang/htmlpurifier/library/
done
%endif

%if 0%{?suse_version} > 1020
%fdupes %{buildroot}%{webtreesdir}
%endif

%post
# move data directory from old locations to the new location
if [ -d '/srv/www/webtrees' ] ; then
	OLDDIR='/srv/www/webtrees'
fi
if [ -d '%{_localstatedir}/www/webtrees' ] ; then
	OLDDIR='%{_localstatedir}/www/webtrees'
fi
if [ -n "$OLDDIR" ] ; then
	if [ -d "$OLDDIR/data" ] ; then
		# move data directory from old /srv/www and %#{_localstatedir}/www locations
		mv $OLDDIR/data/* %{_localstatedir}/lib/%{name}/
		rmdir "$OLDDIR/data"
	fi
	rmdir --ignore-fail-on-non-empty "$OLDDIR"
	if [ -d "$OLDDIR" ] ; then
		mv $OLDDIR/* %{_localstatedir}/lib/%{name}/
		rmdir "$OLDDIR/"
	fi
fi
if [ -d "$OLDDIR" ] ; then
	mv "$OLDDIR" "$OLDDIR.backup"
	echo "WARNING: Check content of $OLDDIR.backup! Should have been migrated to %{_localstatedir}/lib/%{name}"
fi

if [ -x %{_sbindir}/semanage ] ; then
	# check is SELinux is installed and update settings
	semanage fcontext -a -t httpd_var_lib_t %{_localstatedir}/lib/%{name}
fi

%files
%defattr(644,root,root,755)

%dir %{webtreesdir}
%{webtreesdir}/*

# configuration and data repository
%dir %attr(750, %{apache_user}, %{apache_group}) %{_localstatedir}/lib/%{name}
%{_localstatedir}/lib/%{name}/index.php
%config(noreplace) %{_localstatedir}/lib/%{name}/config.ini.php
%defattr(660,root,root,-)

%files config-apache
%{_localstatedir}/lib/%{name}/.htaccess
%config(noreplace) %{apache_sysconfdir}/conf.d/%{name}.conf

%changelog
openSUSE Build Service is sponsored by