LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File mariadb.spec of Package mariadb (Project home:jayvdb:toggl)

# spec file for package mariadb
# Copyright (c) 2016 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/

### WARNING!!!! ##############################################################
# This package is developed on http://github.com/openSUSE/mysql-packaging/
# Do not change anything here in OBS.
%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_101
%define with_mandatory_lz4 0
%define build_readline 1
%define build_extras 1
# _tmpfilesdir is not defined in systemd macros up to openSUSE 13.2
%{!?_tmpfilesdir: %global _tmpfilesdir %{_libexecdir}/tmpfiles.d }
%if 0%{build_extras} > 0
%define with_jemalloc 1
#temporarily disable OQGraph (see MDEV-9479)
#%define with_oqgraph 1
%define with_oqgraph 0
%define with_cassandra 0
%define with_jemalloc 0
%define with_oqgraph 0
%define with_cassandra 0
Name:           mariadb
Version:        10.1.25
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.xz
Source12:       series
Source13:       configuration-tweaks.tar.xz
Source14:       my.ini
Source15:       mysql.service
Source16:       mysql.target
Source17:       mysql-systemd-helper
Source18:       mysql@.service
%if 0%{?opensuse}
BuildRequires:  libaudit1
BuildRequires:  bison
BuildRequires:  cmake
BuildRequires:  dos2unix
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  libaio-devel
%if 0%{?fedora} || 0%{?mageia} || 0%{?scientificlinux}
BuildRequires:  bzip2-devel
BuildRequires:  libbz2-devel
BuildRequires:  libevent-devel
BuildRequires:  libtool
BuildRequires:  libxml2-devel
BuildRequires:  lzo-devel
BuildRequires:  ncurses-devel
# Temporarily require OpenSSL 1.0.x until we update to 10.2 which builds fine with OpenSSL 1.1
BuildRequires:  openssl-devel
BuildRequires:  pam-devel
BuildRequires:  pcre-devel
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)
BuildRequires:  pkgconfig
# Tests requires time and ps and some perl modules
# Keep in sync with Requires of mysql-testsuite
BuildRequires:  procps
%if 0%{?fedora} || 0%{?opensuse}
BuildRequires:  shadow
BuildRequires:  shadow-utils
%if ! 0%{?mageia}
BuildRequires:  sqlite
BuildRequires:  tcpd-devel
BuildRequires:  time
BuildRequires:  zlib-devel
# Do not ever switch away from pkgconfig(libsystemd) BuildRequires; systemd/systemd-devel causes build cycles
# BuildRequires:  pkgconfig(libsystemd)
# required by rcmysql
Requires:       %{name}-client
Requires:       %{name}-errormessages = %{version}
Requires:       perl-base
%if 0%{?fedora} || 0%{?opensuse}
BuildRequires:  shadow
BuildRequires:  shadow-utils
Conflicts:      otherproviders(mariadb-server)
Conflicts:      otherproviders(mysql)
Conflicts:      otherproviders(mysql-debug)
Conflicts:      otherproviders(mysql-server)
# Compatibility with Fedora/CentOS
Provides:       mysql-server = %{version}
Provides:       mariadb-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:       mysql = %{version}
Provides:       mysql-debug = %{version}
Provides:       %{extra_provides} = %{version}
Obsoletes:      %{extra_provides} < %{version}
Provides:       %{extra_provides}-debug-version = %{version}
Obsoletes:      %{extra_provides}-debug-version < %{version}
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{with_mandatory_lz4} > 0
# Dependency introduced in 5.7 mysql
BuildRequires:  liblz4-devel
# On mariadb we want readline5 (except for SLE12) and on mysql we use libedit from system
%if 0%{build_readline} > 0 && ! (( 0%{?suse_version} == 1315 ) && ( ! 0%{?is_opensuse} ))
BuildRequires:  readline5-devel
BuildRequires:  libedit-devel
%if 0%{with_oqgraph} > 0 || 0%{with_cassandra} > 0
BuildRequires:  boost-devel
# Build with jemalloc even for mariadb-100 to enable TokuDB there (bnc#970287)
%if 0%{with_jemalloc} > 0 || "%{extra_provides}" == "mariadb_100"
BuildRequires:  jemalloc-devel
%if 0%{with_oqgraph} > 0
BuildRequires:  judy-devel
%if 0%{with_cassandra} > 0
BuildRequires:  libthrift-devel
%if 0%{?preferred} > 0
Obsoletes:      mysql < %{version}
Obsoletes:      mysql-debug < %{version}

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:       libaio-devel
Requires:       libmysqlclient%{soname} = %{version}
Requires:       libmysqlclient_r%{soname} = %{version}
Requires:       lzo-devel
Requires:       pkgconfig(libssl)
Requires:       zlib-devel
# 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
Group:          Development/Libraries/C and C++
# the headers files are the shared
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}.

%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:  shadow
Conflicts:      otherproviders(mysql-client)
Provides:       mysql-client = %{version}
Provides:       %{extra_provides}-client = %{version}
Obsoletes:      %{extra_provides}-client < %{version}
%if 0%{?preferred} > 0
Obsoletes:      mysql-client < %{version}

%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:       mysql-bench = %{version}
Provides:       %{extra_provides}-bench = %{version}
Obsoletes:      %{extra_provides}-bench < %{version}
%if 0%{?preferred} > 0
Obsoletes:      mysql-bench < %{version}

%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(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)
Requires:       perl-DBD-mysql
Requires:       procps
Requires:       time
Conflicts:      otherproviders(mysql-test)
Provides:       mysql-test = %{version}
Provides:       %{extra_provides}-test = %{version}
Obsoletes:      %{extra_provides}-test < %{version}
%if 0%{?preferred} > 0
Obsoletes:      mysql-test < %{version}

%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:       mysql-client:%{_bindir}/perror
Provides:       mysql:%{_bindir}/mysqlhotcopy
Provides:       mysql-tools = %{version}
Provides:       %{extra_provides}-tools = %{version}
Obsoletes:      %{extra_provides}-tools < %{version}
%if 0%{?preferred} > 0
Obsoletes:      mysql-tools < %{version}

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

%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
mv scripts/mysqlclient.pc.in scripts/%{libname}.pc.in || continue
# 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

EXTRA_FLAGS="-Wno-unused-but-set-variable -fno-strict-aliasing -Wno-unused-parameter"
# Mariadb devs seems to fall in love with -Werror option
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=0                                            \
        -DWITH_LIBEDIT=0                                             \
        -DWITH_EDITLINE=system                                       \
        -DINSTALL_LAYOUT=RPM                                         \
        -DWITH_SYSTEMD=ON                                            \
        -DWITH_LZ4=system                                            \
        -DMYSQL_UNIX_ADDR="%{_localstatedir}/run/mysql/mysql.sock"   \
        -DINSTALL_UNIX_ADDRDIR="%{_localstatedir}/run/mysql/mysql.sock" \
        -DINSTALL_MYSQLSHAREDIR=share/%{name}                        \
        -DWITH_COMMENT="openSUSE mariadb 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                              \
%if 0%{with_cassandra} > 0
        -DWITH_CASSANDRA_STORAGE_ENGINE=1                            \
        -DWITH_XTRADB_STORAGE_ENGINE=1                               \
        -DWITH_CSV_STORAGE_ENGINE=1                                  \
        -DWITH_HANDLERSOCKET_STORAGE_ENGINE=1                        \
        -DWITH_INNODB_MEMCACHED=ON                                   \
        -DWITH_EMBEDDED_SERVER=true                                  \
        -DWITH_WSREP=ON                                              \
        -DWITH_INNODB_DISALLOW_WRITES=1                              \
        -DWITH_BOOST=../boost/                                       \
        -DCOMPILATION_COMMENT="openSUSE 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_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

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

# Remove unused services for mariadb_101
%if "%{extra_provides}" == "mariadb_101"
rm -f %{buildroot}'%{_unitdir}/mariadb.service'
rm -f %{buildroot}'%{_unitdir}/mariadb@.service'
rm -f %{buildroot}'%{_unitdir}/mariadb@bootstrap.service.d/use_galera_new_cluster.conf'

# Generate various filelists
filelist galera_new_cluster galera_recovery innochecksum mariadb-service-convert 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 tokuft_logprint tokuft_logdump tokuftdump >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
# 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

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 wsrep_sst_common wsrep_sst_mariabackup wsrep_sst_mysqldump wsrep_sst_rsync wsrep_sst_xtrabackup-v2 wsrep_sst_xtrabackup %{_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

# 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
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)
install -d -m 755 ${DOCDIR}
for i in "${DOCS[@]}"; do
	install -m 644 "${i}" "${DOCDIR}" || true
# Default configuration file
install -m 664 %{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}'%{_unitdir}/mysql.service
install -D -m 644 %{_sourcedir}/mysql@.service '%{buildroot}'%{_unitdir}/mysql@.service
install -D -m 644 %{_sourcedir}/mysql.target '%{buildroot}'%{_unitdir}/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.*

# 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"

# 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

# 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"
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

# 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
tar -C '%{buildroot}'%{_sysconfdir}/my.cnf.d -xvf %{SOURCE13}

# 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

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
# if mysql user is not in mysql group or if mysql user doesn't have '/bin/false' shell set, do so
id -Gn mysql | grep '\bmysql\b' &>/dev/null || usermod -g mysql mysql
getent passwd mysql | cut -d: -f7 | grep '\b/bin/false\b' &>/dev/null || usermod -s /bin/false mysql
exit 0

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
# if mysql user is not in mysql group or if mysql user doesn't have '/bin/false' shell set, do so
id -Gn mysql | grep '\bmysql\b' &>/dev/null || usermod -g mysql mysql
getent passwd mysql | cut -d: -f7 | grep '\b/bin/false\b' &>/dev/null || usermod -s /bin/false mysql

%service_add_pre mysql.service

%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 || :
# 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


# 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"
if [ \! -f "$datadir/mysql_upgrade_info" ]; then
    if [ $1 -eq 1 ]; then
        cat >> %{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release} << EOF

    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.

exit 0

%service_del_preun mysql.service

%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

%files -f mysql.files
%defattr(-, root, root)
%config(noreplace) %attr(0644, root, mysql) %{_sysconfdir}/my.cnf
%dir %attr(0755, root, mysql) %{_sysconfdir}/my.cnf.d
%config(noreplace) %attr(0644, 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
%dir %{_datadir}/%{name}
%dir %{_datadir}/mysql
%dir %{_libdir}/mysql
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/mysql
%dir %{_libdir}/mysql/plugin
%ghost %{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release}
%dir %attr(0750, mysql, mysql) /var/lib/mysql-files
# Pack files for mariadb_101
%if "%{extra_provides}" == "mariadb_101"
%dir %{_datadir}/mysql/policy
%dir %{_datadir}/mysql/policy/apparmor
%dir %{_datadir}/mysql/policy/selinux
%dir %{_datadir}/mysql/systemd

%files errormessages -f errormessages.files
%defattr(-, root, root)

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

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

%files -n libmysqld-devel

%files -n libmysqld%{soname}

%files -n lib%{libname}%{soname}
%defattr(-, root, root)

%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

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

%files test -f mysql-test.files
%defattr(-, root, root)
%if "%{extra_provides}" == "mariadb_101"
%dir %attr(755, root, root)%{_datadir}/mysql-test
%dir %attr(755, mysql, mysql) %{_datadir}/mysql-test/var

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