File mariadb.spec of Package mariadb.6476

#
# spec file for package mariadb
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#


%define pretty_name MariaDB
%define libname mysqlclient
%define soname 18
%define preferred 1
%define builtin_plugins partition,csv,heap,aria,pbxt,myisam,myisammrg,xtradb
%define extra_provides mariadb_100
%define with_mandatory_boost 0
%define build_extras 0
%if 0%{build_extras} > 0
%define with_jemalloc 1
%define with_oqgraph 1
%define with_cassandra 1
%else
%define with_jemalloc 0
%define with_oqgraph 0
%define with_cassandra 0
%endif
Name:           mariadb
Version:        10.0.33
Release:        0
Summary:        Server part of %{pretty_name}
License:        SUSE-GPL-2.0-with-FLOSS-exception
Group:          Productivity/Databases/Servers
Url:            https://www.mariadb.org
Source:         https://downloads.mariadb.org/f/mariadb-%{version}/source/mariadb-%{version}.tar.gz
Source2:        baselibs.conf
Source3:        README.debug
Source4:        suse-test-run
Source5:        mysql.SuSEfirewall2
Source7:        README.install
Source8:        README.SUSE
Source9:        mysql-patches.tar.bz2
Source12:       series
Source13:       configuration-tweaks.tar.bz2
Source14:       my.ini
Source15:       mysql.service
Source16:       mysql.target
Source17:       mysql-systemd-helper
Source18:       mysql@.service
BuildRequires:  bison
BuildRequires:  cmake
BuildRequires:  dos2unix
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  libaio-devel
BuildRequires:  libbz2-devel
BuildRequires:  libevent-devel
BuildRequires:  libtool
BuildRequires:  libxml2-devel
BuildRequires:  lzo-devel
BuildRequires:  ncurses-devel
BuildRequires:  openssl-devel
BuildRequires:  pam-devel
BuildRequires:  pcre-devel
BuildRequires:  pkgconfig
BuildRequires:  perl(Data::Dumper)
BuildRequires:  perl(Env)
BuildRequires:  perl(Exporter)
BuildRequires:  perl(Fcntl)
BuildRequires:  perl(File::Temp)
BuildRequires:  perl(Getopt::Long)
BuildRequires:  perl(IPC::Open3)
BuildRequires:  perl(Socket)
BuildRequires:  perl(Sys::Hostname)
BuildRequires:  perl(Test::More)
BuildRequires:  perl(Time::HiRes)
# Tests requires time and ps and some perl modules
# Keep in sync with Requires of mysql-testsuite
BuildRequires:  procps
BuildRequires:  pwdutils
BuildRequires:  sqlite
BuildRequires:  tcpd-devel
BuildRequires:  time
BuildRequires:  unixODBC-devel
BuildRequires:  zlib-devel
BuildRequires:  pkgconfig(systemd)
# required by rcmysql
Requires:       %{name}-client
Requires:       %{name}-errormessages = %{version}
Requires:       perl-base
Requires(pre):  pwdutils
Recommends:     logrotate
Conflicts:      otherproviders(mariadb-server)
Conflicts:      otherproviders(mysql)
Conflicts:      otherproviders(mysql-debug)
Conflicts:      otherproviders(mysql-server)
# Compatibility with Fedora/CentOS
Provides:       mariadb-server = %{version}
Provides:       mysql-server = %{version}
# Compatibility with old version
Provides:       %{name}-debug-version = %{version}
Obsoletes:      %{name}-debug-version < %{version}
Provides:       %{name}-debug = %{version}
Obsoletes:      %{name}-debug < %{version}
Provides:       %{extra_provides} = %{version}
Provides:       mysql = %{version}
Provides:       mysql-debug = %{version}
Obsoletes:      %{extra_provides} < %{version}
Provides:       %{extra_provides}-debug-version = %{version}
Obsoletes:      %{extra_provides}-debug-version < %{version}
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%{?systemd_requires}
%if 0%{with_mandatory_boost} > 0
BuildRequires:  boost-devel >= 1.57.0
%endif
%if 0%{with_oqgraph} > 0 || 0%{with_cassandra} > 0
BuildRequires:  boost-devel
%endif
%if 0%{with_jemalloc} > 0
BuildRequires:  jemalloc-devel
%endif
%if 0%{with_oqgraph} > 0
BuildRequires:  judy-devel
%endif
%if 0%{with_cassandra} > 0
BuildRequires:  libthrift-devel
%endif
%if 0%{?preferred} > 0
Obsoletes:      mysql < %{version}
Obsoletes:      mysql-debug < %{version}
%endif

%description
MariaDB is a backward compatible, drop-in replacement branch of the MySQL
Database Server. It includes all major open source storage engines, including
the Maria storage engine.

This package only contains the server-side programs.

%if 0%{?preferred} > 0
%package -n libmysqlclient-devel
Summary:        %{pretty_name} development header files and libraries
Group:          Development/Libraries/C and C++
Requires:       glibc-devel
Requires:       libmysqlclient%{soname} = %{version}
Requires:       libmysqlclient_r%{soname} = %{version}
Requires:       zlib-devel
Requires:       pkgconfig(libssl)
# mysql-devel needs to be provided as some pkgs still depend on it
Provides:       mysql-devel = %{version}
Obsoletes:      mysql-devel < %{version}

%description -n libmysqlclient-devel
This package contains the development header files and libraries
necessary to develop client applications for %{pretty_name}.

%package -n libmysqld%{soname}
Summary:        %{pretty_name} embedded server development files
Group:          Development/Libraries/C and C++
Requires:       %{name}-errormessages >= %{version}

%description -n libmysqld%{soname}
This package contains the development header files and libraries
for developing applications that embed the %{pretty_name}.

%package -n libmysqld-devel
Summary:        %{pretty_name} embedded server development files
# the headers files are the shared
Group:          Development/Libraries/C and C++
Requires:       libmysqlclient-devel = %{version}
Requires:       libmysqld%{soname} = %{version}
Requires:       tcpd-devel

%description -n libmysqld-devel
This package contains the development header files and libraries
for developing applications that embed the %{pretty_name}.
%endif

%package -n lib%{libname}%{soname}
Summary:        Shared Libraries for %{pretty_name}
Group:          Development/Libraries/Other

%description -n lib%{libname}%{soname}
This package contains the shared libraries (.so) which certain
languages and applications need to dynamically load and use %{pretty_name}.

%package -n lib%{libname}_r%{soname}
Summary:        Shared Libraries for %{pretty_name}
Group:          Development/Libraries/Other
Requires:       lib%{libname}%{soname}

%description -n lib%{libname}_r%{soname}
This package contains the shared libraries (.so) which certain
languages and applications need to dynamically load and use %{pretty_name}.

%package client
Summary:        Client for %{pretty_name}
Group:          Productivity/Databases/Clients
Requires:       %{name}-errormessages = %{version}
# Explicit requires to pull in charsets for errormessages
Requires:       lib%{libname}%{soname}
Requires(pre):  pwdutils
Conflicts:      otherproviders(mysql-client)
Provides:       %{extra_provides}-client = %{version}
Provides:       mysql-client = %{version}
Obsoletes:      %{extra_provides}-client < %{version}
%if 0%{?preferred} > 0
Obsoletes:      mysql-client < %{version}
%endif

%description client
This package contains the standard clients for %{pretty_name}.

%package errormessages
Summary:        MySQL Community Server development header files and libraries
Group:          Development/Libraries/C and C++

%description errormessages
This package provides the translated error messages for the standalone
server daemon as well as the embedded server

%package bench
Summary:        Benchmarks for %{pretty_name}
Group:          Productivity/Databases/Tools
Requires:       %{name}-client
Requires:       perl-DBD-mysql
Conflicts:      otherproviders(mysql-bench)
Provides:       %{extra_provides}-bench = %{version}
Provides:       mysql-bench = %{version}
Obsoletes:      %{extra_provides}-bench < %{version}
%if 0%{?preferred} > 0
Obsoletes:      mysql-bench < %{version}
%endif

%description bench
This package contains benchmark scripts and data for %{pretty_name}.

To run these database benchmarks, start the script "run-all-tests" in
the directory %{_datadir}/sql-bench after starting %{pretty_name}.

%package test
Summary:        Testsuite for %{pretty_name}
Group:          Productivity/Databases/Servers
Requires:       %{name} = %{version}
Requires:       %{name}-bench = %{version}
Requires:       %{name}-client = %{version}
Requires:       %{name}-tools = %{version}
# Tests requires time and ps and some perl modules
Requires:       perl-DBD-mysql
Requires:       procps
Requires:       time
Requires:       perl(Data::Dumper)
Requires:       perl(Env)
Requires:       perl(Exporter)
Requires:       perl(Fcntl)
Requires:       perl(File::Temp)
Requires:       perl(Getopt::Long)
Requires:       perl(IPC::Open3)
Requires:       perl(Socket)
Requires:       perl(Sys::Hostname)
Requires:       perl(Test::More)
Requires:       perl(Time::HiRes)
Conflicts:      otherproviders(mysql-test)
Provides:       %{extra_provides}-test = %{version}
Provides:       mysql-test = %{version}
Obsoletes:      %{extra_provides}-test < %{version}
%if 0%{?preferred} > 0
Obsoletes:      mysql-test < %{version}
%endif

%description test
This package contains the test scripts and data for %{pretty_name}.

To run the testsuite, run %{_datadir}/mysql-test/suse-test-run.

%package tools
Summary:        %{pretty_name} tools
Group:          Productivity/Databases/Servers
Requires:       perl-DBD-mysql
Conflicts:      otherproviders(mysql-tools)
# make sure this package is installed when updating from 10.2 and older
Provides:       %{extra_provides}-tools = %{version}
Provides:       mysql-client:%{_bindir}/perror
Provides:       mysql-tools = %{version}
Provides:       mysql:%{_bindir}/mysqlhotcopy
Obsoletes:      %{extra_provides}-tools < %{version}
%if 0%{?preferred} > 0
Obsoletes:      mysql-tools < %{version}
%endif

%description tools
A set of scripts for administering a %{pretty_name} or developing
applications with %{pretty_name}.

%prep
%setup -q -n mariadb-%{version} -D -a 9
cp %{_sourcedir}/README.SUSE .
cp %{_sourcedir}/suse-test-run .
# apply patches from series
mysql-patches/tools/quilt-setup.sh  "%{SOURCE12}"
mysql-patches/tools/apply-series.sh "%{SOURCE12}"
# remove unneeded manpages ('make install' basically installs everything under
# man/*)
rm -f man/mysqlman.1        # dummy fallback manpage
[ \! -f man/CMakeLists.txt ] || sed -i 's|mysqlman.1||'     man/CMakeLists.txt
rm -f man/mysql.server.1    # init script, not installed in our rpm
[ \! -f man/CMakeLists.txt ] || sed -i 's|mysql.server.1||' man/CMakeLists.txt
rm -f man/make_win_*.1      # windows build scripts
rm -f man/comp_err.1        # built-time utility
# 5.1 Carrier Grade Edition only / still under development as of 5.1.22
rm -f man/ndbd_redo_log_reader.1
# breaks VPATH builds when in sourcedir, is generated in the builddirs
rm -f sql/sql_builtin.cc
sed -i 's|@localstatedir@|%{_localstatedir}/log|' support-files/mysql-log-rotate.sh
%if 0%{preferred} < 1
for i in `grep -Rl mysqlclient .`; do
	sed -i 's|mysqlclient|%{libname}|g' $i
	sed -i 's|-lib%{libname}-symbols.patch|-libmysqlclient-symbols.patch|g' $i
done
%endif
# Broken test that needs sources
rm -f mysql-test/t/file_contents.test mysql-test/r/file_contents.result
# Specify perl path on shebangs
for i in `grep -Rl '^#!@PERL@$' .`; do
	sed -i 's|@PERL@|%{_bindir}/perl|' $i
done

%build
EXTRA_FLAGS="-Wno-unused-but-set-variable -fno-strict-aliasing -Wno-unused-parameter"
# Mariadb devs seems to fall in love with -Werror option
EXTRA_FLAGS="${EXTRA_FLAGS} -Wno-error"
export CFLAGS="%{optflags} -DOPENSSL_LOAD_CONF -DPIC -fPIC -DFORCE_INIT_OF_VARS $EXTRA_FLAGS"
export CXXFLAGS="$CFLAGS -felide-constructors"
%cmake -DWITH_SSL=system                                             \
        -DWITH_ASAN=OFF                                              \
        -DWITH_LIBWRAP=ON                                            \
        -DENABLED_PROFILING=ON                                       \
        -DENABLE_DEBUG_SYNC=OFF                                      \
        -DWITH_PIC=ON                                                \
        -DWITH_ZLIB=system                                           \
        -DWITH_LIBEVENT=system                                       \
        -DWITH_JEMALLOC=auto                                         \
        -DWITH_READLINE=1                                            \
        -DWITH_LIBEDIT=0                                             \
        -DINSTALL_LAYOUT=RPM                                         \
        -DMYSQL_UNIX_ADDR="%{_localstatedir}/run/mysql/mysql.sock"   \
        -DINSTALL_UNIX_ADDRDIR="%{_localstatedir}/run/mysql/mysql.sock" \
        -DINSTALL_MYSQLSHAREDIR=share/%{name}                        \
        -DWITH_COMMENT="SLE 12 SP1 MySQL rpm"                        \
        -DWITH_EXTRA_CHARSET=all                                     \
        -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  \
        -DWITH_INNOBASE_STORAGE_ENGINE=1                             \
        -DWITH_PERFSCHEMA_STORAGE_ENGINE=1                           \
%if 0%{with_oqgraph} > 0
        -DWITH_OQGRAPH_STORAGE_ENGINE=1                              \
%endif
%if 0%{with_cassandra} > 0
        -DWITH_CASSANDRA_STORAGE_ENGINE=1                            \
%endif
        -DWITH_XTRADB_STORAGE_ENGINE=1                               \
        -DWITH_CSV_STORAGE_ENGINE=1                                  \
        -DWITH_HANDLERSOCKET_STORAGE_ENGINE=1                        \
        -DWITH_EMBEDDED_SERVER=true                                  \
        -DWITH_WSREP=ON                                              \
        -DWITH_INNODB_DISALLOW_WRITES=1                              \
        -DCOMPILATION_COMMENT="SLE 12 SP1 package"                   \
        -DDENABLE_DOWNLOADS=false                                    \
        -DINSTALL_PLUGINDIR_RPM="%{_lib}/mysql/plugin"               \
        -DINSTALL_LIBDIR_RPM="%{_lib}"                               \
        -DINSTALL_SYSCONF2DIR="%{_sysconfdir}/my.cnf.d"              \
        -DCMAKE_C_FLAGS_RELWITHDEBINFO="$CFLAGS"                     \
        -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$CXXFLAGS"                 \
        -DCMAKE_BUILD_TYPE=RelWithDebInfo                            \
        -DINSTALL_SQLBENCHDIR=share                                  \
        -DCMAKE_C_FLAGS="$CFLAGS"                                    \
        -DCMAKE_CXX_FLAGS="$CXXFLAGS"                                \
        -DCMAKE_EXE_LINKER_FLAGS="-Wl,--as-needed -pie -Wl,-z,relro,-z,now" \
        -DCMAKE_MODULE_LINKER_FLAGS="-Wl,--as-needed -pie -Wl,-z,relro,-z,now" \
        -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed -pie -Wl,-z,relro,-z,now" \
        -Wno-dev "$@" ..
make %{?_smp_mflags}
nm --numeric-sort sql/mysqld > sql/mysqld.sym

%install
# Helper function to generate filelist for binaries and their manpages
filelist()
{
	echo '%%defattr(-, root, root)'
	pushd %{buildroot} >/dev/null
	for i; do
		if test -e usr/sbin/"$i"; then
			echo %{_sbindir}/"$i"
		fi
		if test -e usr/bin/"$i"; then
			echo %{_bindir}/"$i"
		fi
		if test -d usr/share/*/"$i"; then
			echo "/`echo usr/share/*/"$i"`"
		fi
		if test -n "`ls -1 %{buildroot}$i 2> /dev/null`"; then
			echo "$i"
		fi
		if ls usr/share/man/*/"$i".[1-9]* >/dev/null 2>&1; then
			echo "%{_mandir}/*/$i.[1-9]*"
		fi
	done
	popd >/dev/null
}

# Install the package itself
%cmake_install benchdir_root=%{_datadir}/

# Logrotate file should be named as the package
if [ ! -e %{buildroot}%{_sysconfdir}/logrotate.d/mysql ]; then
    # some versions do not install it automatically
    install -D -m 644 build/support-files/mysql-log-rotate %{buildroot}%{_sysconfdir}/logrotate.d/mysql
fi
mv %{buildroot}%{_sysconfdir}/logrotate.d/mysql %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

# Create log directory with the expected perms of mysql
install -d -m 700 %{buildroot}%{_localstatedir}/log/mysql/

# Symbols from build to go into libdir
install -m 644 build/sql/mysqld.sym %{buildroot}%{_libdir}/mysql/mysqld.sym
# INFO_BIN and INFO_SRC binaries
install -p -m 644 build/Docs/INFO_SRC %{buildroot}%{_libdir}/mysql/
install -p -m 644 build/Docs/INFO_BIN %{buildroot}%{_libdir}/mysql/

# Remove TokuDB plugin and binaries (as TokuDB storage engine requires the jemalloc library that isn't present in SLE-12-SP1)
rm -f %{buildroot}%{_libdir}/mysql/plugin/ha_tokudb.so
rm -f %{buildroot}%{_bindir}/tokuft_logprint
rm -f %{buildroot}%{_bindir}/tokuftdump

# Remove handler socket client
rm -f %{buildroot}%{_libdir}/mysql/plugin/handlersocket.so

# Remove debug management for keys Mariadb 101+
rm -f %{buildroot}%{_libdir}/mysql/plugin/debug_key_management.so

# Remove most static libs (FIXME: don't build them at all...)
[ \! -f "%{buildroot}%{_libdir}/"libmysqld.a ] || mv "%{buildroot}%{_libdir}/"libmysqld.a "%{buildroot}%{_libdir}/"libmysqld.static
rm -f %{buildroot}%{_libdir}/*.a
[ \! -f "%{buildroot}%{_libdir}/"libmysqld.static ] || mv "%{buildroot}%{_libdir}/"libmysqld.static "%{buildroot}%{_libdir}/"libmysqld.a

# Rename mytop to have name prefixed with the implementation
[ \! -f "%{buildroot}%{_bindir}/mytop" ] || mv %{buildroot}%{_bindir}/mytop %{buildroot}%{_bindir}/%{name}_mytop

# Remove few configure/examples
rm -f %{buildroot}%{_datadir}/mysql/{binary-configure,errmsg-utf8.txt,magic,mysql-log-rotate,mysql*.server}
rm -f %{buildroot}%{_libdir}/mysql/plugin/daemon_example.ini

mv %{buildroot}%{_datadir}/mysql-test/lib/My/SafeProcess/my_safe_process %{buildroot}%{_bindir}

# Generate various filelists
filelist innochecksum my_print_defaults myisam_ftdump myisamchk myisamlog myisampack mysql_fix_extensions mysql_fix_privilege_tables mysql_ssl_rsa_setup mysql_install_db mysql_secure_installation mysql_upgrade mysqlbug mysqld mysqld_multi mysqld_safe mysqlbinlog mysqldumpslow mysqlmanager mroonga resolve_stack_dump resolveip {m,}aria_chk {m,}aria_dump_log {m,}aria_ftdump {m,}aria_pack {m,}aria_read_log xtstat >mysql.files

filelist mysql mysqladmin mysqlcheck mysqldump mysqlimport mysqlshow mysql_config_editor mysqld_safe_helper >mysql-client.files
# The dialog stuff is mariadb only
if [ "`ls '%{buildroot}'%{_libdir}/mysql/plugin/dialog*.so 2> /dev/null`" ]; then
    echo '%%dir %%_libdir/mysql'               >> mysql-client.files
    echo '%%dir %%_libdir/mysql/plugin'        >> mysql-client.files
    echo '%%_libdir/mysql/plugin/dialog*.so'   >> mysql-client.files
fi
# Mysql has configuration file in _bindir
if [ -f scripts/mysqlaccess.conf ] ; then
    install -m 640 scripts/mysqlaccess.conf %{buildroot}%{_sysconfdir}/mysqlaccess.conf
    rm -f %{buildroot}%{_bindir}/mysqlaccess.conf
    echo '%config(noreplace) %attr(0640, root, mysql) %{_sysconfdir}/mysqlaccess.conf' >> mysql-client.files
fi

filelist mysql_config %{_datadir}/pkgconfig/mariadb.pc >libmysqlclient-devel.files

filelist mysqlslap >mysql-bench.files

filelist mysql_client_test mysql_client_test_embedded mysql_waitpid mysqltest mysqltest_embedded >mysql-test.files

filelist msql2mysql mysql_plugin mysql_convert_table_format mysql_find_rows mysql_setpermission mysql_tzinfo_to_sql mysql_zap mysqlaccess mysqlhotcopy perror replace mysql_embedded %{name}_mytop hsclient %{_bindir}/wsrep* %{_datadir}/mysql/wsrep_notify >mysql-tools.files

filelist ndbd ndbmtd ndbd_redo_log_reader >mysql-ndb-storage.files

filelist ndb_mgmd >mysql-ndb-management.files

filelist ndb_{config,desc,error_reporter,mgm,print_backup_file,print_schema_file,print_sys_file,restore,select_all,select_count,show_tables,size.pl,test_platform,waiter} >mysql-ndb-tools.files

filelist ndb_{cpcd,delete_all,drop_index,index_stat,print_file,redo_log_reader,drop_table} ndbinfo_select_all memcached >mysql-ndb-extra.files

# All configuration files
echo '%{_datadir}/mysql/*.cnf' >> mysql.files
# Mysql-community server has dictionary file in datadir
if [ -f "%{buildroot}%{_datadir}/%{name}"/dictionary.txt ]; then
    echo "%{_datadir}/%{name}/dictionary.txt" >> mysql.files
fi

# Special errormessages approach
echo '%%defattr(-, root, root)' > %{_builddir}/errormessages.files
pushd %{buildroot} >/dev/null
for f in usr/share/%{name}/*; do
    if test -e $f/errmsg.sys; then
        echo "%%dir /$f" >> %{_builddir}/errormessages.files
    fi
done
echo %{_datadir}/%{name}/errmsg-utf8.txt >> %{_builddir}/errormessages.files
popd >/dev/null
mv %{_builddir}/errormessages.files errormessages.files

### files not installed by make install
# Some of the documentation we need to have installed
DOCS=(COPYING README EXCEPTIONS-CLIENT %{_sourcedir}/README.debug %{_sourcedir}/README.SUSE plugin/daemon_example/daemon_example.ini)
DOCDIR=%{buildroot}%{_defaultdocdir}/%{name}
install -d -m 755 ${DOCDIR}
for i in "${DOCS[@]}"; do
	install -m 644 "${i}" "${DOCDIR}" || true
done
# Default configuration file
install -m 660 %{SOURCE14} %{buildroot}%{_sysconfdir}/my.cnf

# Systemd/initscript
install -D -m 755 %{_sourcedir}/mysql-systemd-helper '%{buildroot}'%{_libexecdir}/mysql/mysql-systemd-helper
sed -i 's|@MYSQLVER@|%{version}|' '%{buildroot}'%{_libexecdir}/mysql/mysql-systemd-helper
ln -sf service '%{buildroot}'%{_sbindir}/rcmysql
install -D -m 644 %{_sourcedir}/mysql.service '%{buildroot}'%{_libexecdir}/systemd/system/mysql.service
install -D -m 644 %{_sourcedir}/mysql@.service '%{buildroot}'%{_libexecdir}/systemd/system/mysql@.service
install -D -m 644 %{_sourcedir}/mysql.target '%{buildroot}'%{_libexecdir}/systemd/system/mysql.target
rm -rf '%{buildroot}'%{_sysconfdir}/init.d

# Tmpfiles file to exclude mysql tempfiles that are auto-cleaned up
# bnc#852451
mkdir -p %{buildroot}%{_tmpfilesdir}
cat > %{buildroot}%{_tmpfilesdir}/mysql.conf <<EOF
x %{_localstatedir}/tmp/mysql.*
EOF

# SuSEfirewall service description
install -D -m 644 %{_sourcedir}/mysql.SuSEfirewall2 %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/mysql

# testsuite
install -d -m 755 '%{buildroot}'%{_datadir}/mysql-test/
install -m 755 suse-test-run '%{buildroot}'%{_datadir}/mysql-test/
mkdir '%{buildroot}'%{_datadir}/mysql-test/var

# Final fixes
find '%{buildroot}'%{_datadir}/mysql-test -name '*.orig' -delete
%fdupes -s '%{buildroot}'%{_datadir}/mysql-test
fdupes -q -n -r '%{buildroot}'%{_datadir}/mysql-test
for i in `grep -Rl '\r' '%{buildroot}'%{_datadir}/sql-bench`; do
	dos2unix "$i"
done

# Fix libmysqlclient_r.so.18 symlinking to be done against plain .so file
# and thus broken later on. Fixes bnc#906147
pushd "%{buildroot}%{_libdir}"
rm -f lib%{libname}_r.so*
ln -sf lib%{libname}.so.%{soname}.0.0 lib%{libname}_r.so
ln -sf lib%{libname}.so.%{soname}.0.0 lib%{libname}_r.so.%{soname}
ln -sf lib%{libname}.so.%{soname}.0.0 lib%{libname}_r.so.%{soname}.0.0
popd

# If not preffered simply reduce main develpackage to NULL
%if ! 0%{preferred} > 0
cat libmysqlclient-devel.files | sed 's|%%doc\ ||' | while read tmp; do
	cd '%{buildroot}'
	rm -f ."$tmp"
done
rm -rf '%{buildroot}'/%{_libdir}/libmysqld.*
rm -rf '%{buildroot}'/%{_libdir}/{*.so,*.a}
rm -rf '%{buildroot}'/%{_mandir}/*/mysql_config.1*
rm -rf '%{buildroot}'/%{_includedir}
rm -rf '%{buildroot}'/%{_datadir}/aclocal
%endif

# Compat with old scripts
ln -s mysqlcheck '%{buildroot}'%{_bindir}/mysqlrepair
ln -s mysqlcheck '%{buildroot}'%{_bindir}/mysqlanalyze
ln -s mysqlcheck '%{buildroot}'%{_bindir}/mysqloptimize

# Use our configuration stuff instead of upstream one
rm -rf '%{buildroot}'%{_sysconfdir}/my.cnf.d
install -d -m 755 '%{buildroot}'%{_sysconfdir}/my.cnf.d
bzip2 -cd '%{_sourcedir}'/configuration-tweaks.tar.bz2 | tar -C '%{buildroot}'%{_sysconfdir}/my.cnf.d -xvf -

# Documentation that was copied to wrong folder
rm -f  '%{buildroot}'%{_datadir}/doc/* 2> /dev/null || true

# Unwanted packaged stuff
rm -rf '%{buildroot}'%{_datadir}/mysql/{solaris,SELinux}

# Create the directory specified in 'secure-file-priv' option
mkdir -p '%{buildroot}'/var/lib/mysql-files

%check
cd build

# First run simple ctest unittests
LD_LIBRARY_PATH=$(pwd)/unittest/mytap make test %{?_smp_mflags}

# And then run discustingly HUGE testsuite that might fail here and there
# Basically we run it to have overview to check how it goes
cd mysql-test
./mysql-test-run.pl \
    --parallel=%{?jobs:%{jobs}} \
    --force \
    --retry=0 \
    --ssl \
    --suite-timeout=720 \
    --testcase-timeout=30 \
    --mysqld=--binlog-format=mixed \
    --force-restart \
    --shutdown-timeout=60 \
    --max-test-fail=0 || :

# client does not require server and needs the user too

%pre client
getent group mysql >/dev/null || groupadd -r mysql
getent passwd mysql >/dev/null || useradd -r -o -g mysql -u 60 -c "MySQL database admin" \
                  -s /bin/false -d %{_localstatedir}/lib/mysql mysql
usermod -g mysql -s /bin/false mysql
exit 0

%pre
getent group mysql >/dev/null || groupadd -r mysql
getent passwd mysql >/dev/null || useradd -r -o -g mysql -u 60 -c "MySQL database admin" \
                  -s /bin/false -d %{_localstatedir}/lib/mysql mysql
usermod -g mysql -s /bin/false mysql

%service_add_pre mysql.service

%post
%service_add_post mysql.service
# Use %%tmpfiles_create when 13.2 is oldest in support scope
%{_bindir}/systemd-tmpfiles --create %{_tmpfilesdir}/mysql.conf || :

# SLE11 Migration support
for i in protected tmp; do
    rmdir "$datadir"/.$i 2>/dev/null || :
done
# Remove any messages that could've been in place about the upgrade
rm -f %{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release}

# During package rename (migration maria->mysql-community-server),
# there might be config file move and we get rpmsave that we should keep
if [ -f %{_sysconfdir}/my.cnf.rpmsave ]; then
    mv %{_sysconfdir}/my.cnf{,.rpmnew}
    mv %{_sysconfdir}/my.cnf{.rpmsave,}
    cat >> %{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release} << EOF

WARNING: %{_sysconfdir}/my.cnf.rpmsave file detected!

This probably means that you are migrating from different variant of MySQL.
Your configuration was left intact and you can see the new configuration in
%{_sysconfdir}/my.cnf.rpmnew

EOF
fi

# warn on first run
datadir="`%{_bindir}/my_print_defaults mysqld mysql_server | sed -n 's|--datadir=||p'`"
[ -n "$datadir" ] || datadir="%{_localstatedir}/lib/mysql"
if [ -d "$datadir/mysql" ]; then
    touch "$datadir/.run-mysql_upgrade"
fi
if [ \! -f "$datadir/mysql_upgrade_info" ]; then
    if [ $1 -eq 1 ]; then
        cat >> %{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release} << EOF

%(cat %{_sourcedir}/README.install)

EOF
    fi
else
    MYSQLVER="`echo %{version} | sed 's|\.[0-9]\+$||'`"
    if [ -f "$datadir/mysql_upgrade_info" ] && \
        [ -z "`grep "^$MYSQLVER" "$datadir/mysql_upgrade_info" 2> /dev/null`" ]; then
    cat >> %{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release} << EOF

WARNING: You are upgrading from different stable version of MySQL!

Your database will be migrated automatically during next restart of MySQL.
Before you do that make sure you have up to date backup of your data. It
should be mainly in $datadir directory.

EOF
    fi
fi
exit 0

%preun
%service_del_preun mysql.service

%postun
%service_del_postun mysql.service
# Remove the /var/adm updatemsg that was hand-created and thus not on filelist
rm -f %{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release}

%post -n lib%{libname}%{soname} -p /sbin/ldconfig

%postun -n lib%{libname}%{soname} -p /sbin/ldconfig

%post -n lib%{libname}_r%{soname} -p /sbin/ldconfig

%postun -n lib%{libname}_r%{soname} -p /sbin/ldconfig

%if 0%{preferred} > 0
%post -n libmysqld%{soname} -p /sbin/ldconfig

%postun -n libmysqld%{soname} -p /sbin/ldconfig
%endif

%files -f mysql.files
%defattr(-, root, root)
%config(noreplace) %attr(0640, root, mysql) %{_sysconfdir}/my.cnf
%dir %attr(0750, root, mysql) %{_sysconfdir}/my.cnf.d
%config(noreplace) %attr(0640, root, mysql) %{_sysconfdir}/my.cnf.d/*
%config %{_sysconfdir}/logrotate.d/%{name}
%doc %{_defaultdocdir}/%{name}
%dir %{_libexecdir}/mysql
%dir %attr(0700, mysql, mysql) %{_localstatedir}/log/mysql
%{_libexecdir}/mysql/mysql-systemd-helper
%{_libexecdir}/systemd/system/mysql.service
%{_libexecdir}/systemd/system/mysql@.service
%{_libexecdir}/systemd/system/mysql.target
%{_tmpfilesdir}/mysql.conf
%{_sbindir}/rcmysql
%dir %{_datadir}/%{name}
%dir %{_datadir}/mysql
%{_datadir}/%{name}/charsets/
%{_datadir}/%{name}/*.sql
%dir %{_libdir}/mysql
%{_libdir}/mysql/mysqld.sym
%{_libdir}/mysql/INFO_BIN
%{_libdir}/mysql/INFO_SRC
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/mysql
%dir %{_libdir}/mysql/plugin
%{_libdir}/mysql/plugin/[!d]*.so
%ghost %{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release}
%dir %attr(0750, mysql, mysql) /var/lib/mysql-files

%files errormessages -f errormessages.files
%defattr(-, root, root)
%{_datadir}/%{name}/*/errmsg.sys

%files client -f mysql-client.files
%defattr(-, root, root)

%if 0%{preferred} > 0
%files -n libmysqlclient-devel -f libmysqlclient-devel.files
%defattr(-, root, root)
%{_includedir}/mysql
%{_libdir}/libmysqlclient.so
%dir %{_datadir}/aclocal
%{_datadir}/aclocal/mysql.m4

%files -n libmysqld-devel
%defattr(-,root,root)
%{_libdir}/libmysqld.a
%{_libdir}/libmysqld.so

%files -n libmysqld%{soname}
%defattr(-,root,root)
%{_libdir}/libmysqld.so.*
%endif

%files -n lib%{libname}%{soname}
%defattr(-, root, root)
%{_libdir}/lib%{libname}.so.*

%files -n lib%{libname}_r%{soname}
%defattr(-, root, root)
# We need .so file here as few apps still rely on it to be present.
# Currently known are Mysql workbench and Libreoffice
%{_libdir}/lib%{libname}_r.so*

%files bench -f mysql-bench.files
%defattr(-, root, root)
%{_datadir}/sql-bench

%files test -f mysql-test.files
%defattr(-, root, root)
%{_bindir}/my_safe_process
%{_mandir}/man1/mysql-test-run.pl.1*
%{_mandir}/man1/mysql-stress-test.pl.1*
%{_datadir}/mysql-test/valgrind.supp
%dir %attr(755, root, root)%{_datadir}/mysql-test
%{_datadir}/mysql-test/[^v]*
%dir %attr(755, mysql, mysql) %{_datadir}/mysql-test/var

%files tools -f mysql-tools.files
%defattr(-, root, root)
%{_bindir}/mysqlrepair
%{_bindir}/mysqlanalyze
%{_bindir}/mysqloptimize

%changelog