Skip to content

Instantly share code, notes, and snippets.

@sevu
Last active July 30, 2020 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sevu/1e6cd29cb0f1792114a82ab87d5a2639 to your computer and use it in GitHub Desktop.
Save sevu/1e6cd29cb0f1792114a82ab87d5a2639 to your computer and use it in GitHub Desktop.
MariaDB optimized build script for Archlinux
--- sql/sql_plugin.cc.orig 2019-01-04 16:28:49.000000000 +0100
+++ sql/sql_plugin.cc 2019-01-07 22:31:53.202843948 +0100
@@ -4127,11 +4127,11 @@
/*
If the plugin is disabled it should not be initialized.
*/
if (disable_plugin)
{
- if (global_system_variables.log_warnings)
+ if (global_system_variables.log_warnings && tmp->name.str != "FEEDBACK")
sql_print_information("Plugin '%s' is disabled.",
tmp->name.str);
goto err;
}
#!/bin/sh
post_install(){
echo ":: You need to initialize the MariaDB data directory prior to starting"
echo " the service. This can be done with mysql_install_db command, e.g.:"
echo " mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql"
}
post_upgrade(){
# Not shown for mere pkgrel bumps
NEW=`echo $1 |cut -f1 -d"-"`
OLD=`echo $2 |cut -f1 -d"-"`
if [ $NEW != $OLD ]; then
echo ""
echo "You updated the database-management-system. To update the databases, run:"
echo "systemctl restart mariadb && mysql_upgrade -u root -p"
echo ""
fi
}
# Maintainer: Michael Herzberg
# Maintainer: Severin Glöckner <severin.gloeckner@stud.htwk-leipzig.de>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Christian Hesse <mail@eworm.de>
pkgbase=mariadb-10.3
pkgname=('mariadb-libs-10.3' 'mariadb-clients-10.3' 'mytop-10.3' 'mariadb-10.3')
pkgver=10.3.12
pkgrel=2
arch=('x86_64')
license=('GPL')
url='https://mariadb.org'
makedepends=('boost' 'bzip2' 'cmake' 'jemalloc' 'libaio' 'libxml2' 'lz4' 'lzo'
'openssl' 'systemd' 'zlib' 'readline' 'clang' 'numactl' 'snappy'
'krb5' 'judy' 'asio' 'curl' 'ncurses' 'unixodbc' 'cracklib' 'zstd')
# msgpack-c/libmpack, cassandra
validpgpkeys=('199369E5404BD5FC7D2FE43BCBCB082A1BB943DB') # MariaDB Package Signing Key <package-signing-key@mariadb.org>
source=("https://mirrors.ukfast.co.uk/sites/mariadb/mariadb-$pkgver/source/mariadb-$pkgver.tar.gz"{,.asc}
fix_libmariadb_ignored_host.patch
hide_feedback_plugin_message.patch)
sha256sums=('f7449a34c25e0455928d7983dae83fd2069fe1f16c4c5f4aeed9ed9d3f081ff6'
'SKIP'
'fd186c795c393b6898f28d731390bb14ea8444230c8340a5f4cfbccb16ea10e9'
'b90487ea65f50e06fb9e1e849bdc25963e6de3a785df0da578bf84b8448b675b')
prepare() {
cd ${pkgbase%-10.3}-$pkgver/
# Changes to the upstream unit files:
# * remove the alias from unit files, we install symlinks in package function
# * enable PrivateTmp for a little bit more security
sed -i -e '/^Alias/d' \
-e '/^PrivateTmp/c PrivateTmp=true' \
support-files/mariadb{,@}.service.in
# let's create the datadir from tmpfiles
echo 'd @MYSQL_DATADIR@ 0700 @MYSQLD_USER@ @MYSQLD_USER@ -' >> support-files/tmpfiles.conf.in
# Fix that libmariadb ignores the host from .my.cnf files
# More info: https://jira.mariadb.org/browse/CONC-359
patch -p0 < ../fix_libmariadb_ignored_host.patch
# Hide the message shown at each startup
patch -p0 < ../hide_feedback_plugin_message.patch
}
build() {
mkdir -p build
cd build
# cmake uses this variable to find JNI & AWT
export JAVA_HOME=/usr/lib/jvm/default
# don't look for it
unset ORACLE_HOME
cmake ../${pkgbase%-10.3}-$pkgver \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DBUILD_CONFIG=mysql_release \
-DMYSQL_MAINTAINER_MODE=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DMYSQL_DATADIR=/var/lib/mysql \
-DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock \
-DINSTALL_UNIX_ADDRDIR=/run/mysqld/mysqld.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \
-DINSTALL_DOCDIR=share/doc/mariadb \
-DINSTALL_DOCREADMEDIR=share/doc/mariadb \
-DINSTALL_MANDIR=share/man \
-DINSTALL_PLUGINDIR=lib/mysql/plugin \
-DINSTALL_SCRIPTDIR=bin \
-DINSTALL_INCLUDEDIR=include/mysql \
-DINSTALL_SUPPORTFILESDIR=share/mysql \
-DINSTALL_SHAREDIR=share \
-DINSTALL_MYSQLSHAREDIR=share/mysql \
-DINSTALL_MYSQLTESTDIR=share/mysql-test \
-DINSTALL_SYSCONF2DIR=/etc/mysql \
-DINSTALL_SYSTEMD_SYSUSERSDIR=/usr/lib/sysusers.d/ \
-DINSTALL_SYSTEMD_TMPFILESDIR=/usr/lib/tmpfiles.d/ \
-DINSTALL_SYSTEMD_UNITDIR=/usr/lib/systemd/system/ \
-DWITH_SYSTEMD=yes \
-DWITH_READLINE=OFF \
-DWITH_ZLIB=system \
-DWITH_SSL=system \
-DWITH_PCRE=bundled \
-DWITH_JEMALLOC=yes \
-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc' \
-DCMAKE_C_FLAGS="-fPIC $CFLAGS -fno-strict-aliasing -DBIG_JOINS=1 -fomit-frame-pointer -fno-delete-null-pointer-checks" \
-DCMAKE_CXX_FLAGS="-fPIC $CXXFLAGS -fno-strict-aliasing -DBIG_JOINS=1 -felide-constructors -fno-rtti -fno-delete-null-pointer-checks" \
-DWITH_MYSQLD_LDFLAGS="-pie ${LDFLAGS},-z,now,--no-undefined" \
-DMANUFACTURER="Archlinux AUR" \
-DWITH_UNIT_TESTS=OFF \
-DCONC_WITH_UNIT_TESTS=OFF \
-DPCRE_BUILD_TESTS=OFF \
-DENABLED_PROFILING=OFF \
-DPROFILING=OFF \
-DAWS_SDK_EXTERNAL_PROJECT=NO \
-DPLUGIN_DEBUG_KEY_MANAGEMENT=NO \
-DPLUGIN_TEST_SQL_DISCOVERY=NO \
-DPLUGIN_TEST_VERSIONING=NO \
-DPLUGIN_AUTH_TEST_PLUGIN=NO \
-DPLUGIN_EXAMPLE_KEY_MANAGEMENT=NO \
-DPLUGIN_DIALOG_EXAMPLES=NO \
-DPLUGIN_FTEXAMPLE=NO \
-DPLUGIN_FEDERATED=NO \
-DPLUGIN_FEEDBACK=NO \
-DPLUGIN_CASSANDRA=NO \
-DCONNECT_WITH_MONGO=NO \
-DCONC_WITH_SSL=ON \
-DCONC_WITH_CURL=ON \
-Wno-dev
# Things which don't work & workarounds:
# - compiling with gcc, cmake detection fails
# - compiling mongodb connector, won't find bson.h (despite being installed)
# - compiling cassandra plugin (is unmaintained and needs additional dependencies)
# - bundled pcre is used to work around this bug: https://bugs.exim.org/show_bug.cgi?id=2173
# - INSTALL_UNIX_ADDRDIR is set specifically for mariadb.pc
# - not setting SYSCONFDIR has the advantage that MariaDB looks for both /etc/my.cnf and /etc/mysql/my.cnf
#
# Most Plugins are compiled dynamically. See here how to load them:
# https://mariadb.com/kb/en/library/plugin-sql-statements/
#
# Alternatively they can be compiled statically
# Statically in this context doesn't mean creating static libraries,
# but compiling them into the server executable
#
# ! Plugins which miss dependencies at build time are silently ignored !
make
}
# Might be renamed, as the library is not anymore called libmysqlclient
# Contains the client library 'libmariadb' (a.k.a Connector/C)
# as well as 'libmariadbd', the library of the embedded server
package_mariadb-libs-10.3() {
# this package should be found when searching for the c connector
pkgdesc='MariaDB connection libraries for C & C++'
depends=('bzip2' 'libaio' 'lzo' 'zlib' 'numactl' 'jemalloc' 'krb5' 'libsystemd')
conflicts=('libmysqlclient' 'libmariadbclient' "mariadb-connector-c")
provides=("libmariadbclient=$pkgver" "mariadb-connector-c")
replaces=("libmariadbclient-10.3")
cd build
for dir in libmariadb libmysqld libservices include; do
make -C $dir DESTDIR="$pkgdir" install
done
install -D -m0755 scripts/mysql_config "$pkgdir"/usr/bin/mysql_config
install -D -m0644 "$srcdir"/${pkgbase%-10.3}-$pkgver/man/mysql_config.1 "$pkgdir"/usr/share/man/man1/mysql_config.1
install -D -m0644 support-files/mariadb.pc "$pkgdir"/usr/lib/pkgconfig/mariadb.pc
install -D -m0644 "$srcdir"/${pkgbase%-10.3}-$pkgver/support-files/mysql.m4 "$pkgdir"/usr/share/aclocal/mysql.m4
# for compatibility with connector c version 2 and other programs (e.g. teamspeak-server)
ln -s libmariadb.so.3 "$pkgdir"/usr/lib/libmariadb.so.2
ln -s libmariadb.so.3 "$pkgdir"/usr/lib/libmysqlclient.so.18
# remove static libraries, they have a *.so counterpart
rm "$pkgdir"/usr/lib/*.a
}
package_mariadb-clients-10.3() {
pkgdesc='MariaDB client tools'
depends=('openssl' 'jemalloc' 'zlib')
conflicts=('mysql-clients' 'mariadb-clients')
provides=("mysql-clients=$pkgver" "mariadb-clients=$pkgver")
cd build
make -C client DESTDIR="$pkgdir" install
# install man pages
for man in mysql mysql_plugin mysql_upgrade mysqladmin mysqlbinlog mysqlcheck mysqldump mysqlimport mysqlshow mysqlslap mysqltest
do
install -D -m0644 "$srcdir"/${pkgbase%-10.3}-$pkgver/man/$man.1 "$pkgdir"/usr/share/man/man1/$man.1
done
}
package_mytop-10.3() {
pkgdesc='Top clone for MariaDB'
arch=('any')
depends=('perl-dbd-mysql' 'perl-term-readkey')
conflicts=('mytop')
provides=("mytop=$pkgver")
cd build
install -Dm0755 scripts/mytop "$pkgdir"/usr/bin/mytop
}
package_mariadb-10.3() {
pkgdesc='Fast SQL database server, drop-in replacement for MySQL'
backup=('etc/mysql/my.cnf'
'etc/mysql/client.cnf'
'etc/mysql/mysql-clients.cnf'
'etc/mysql/server.cnf')
install=mariadb.install
depends=('libsystemd' 'libxml2' 'snappy' 'unixodbc' 'libaio' 'lzo' 'jemalloc' 'numactl'
'inetutils' 'gawk' 'lsof' 'rsync' 'socat') # according to the Debian package provided by the MariaDB devs
optdepends=('libmariadbclient-10.3: package with additional plugins'
'galera: for MariaDB cluster with Galera WSREP'
'perl-dbd-mysql: for mysqlhotcopy, mysql_convert_table_format and mysql_setpermission'
'python: for myrocks_hotbackup'
'judy: for oqgraph plugin'
'zstd: for rocksdb plugin'
'boost-libs: for mroonga, rocksdb, cassandra and oqgraph plugins') # guessed by grepping, Debian has it only as makedep
conflicts=('mysql' 'mariadb')
provides=("mysql=$pkgver" "mariadb=$pkgver")
cd build
make DESTDIR="$pkgdir" install
cd "$pkgdir"
mv usr/lib/sysusers.d/{sysusers,mariadb}.conf
mv usr/lib/tmpfiles.d/{tmpfiles,mariadb}.conf
ln -s mariadb.service usr/lib/systemd/system/mysqld.service
ln -s mariadb@.service usr/lib/systemd/system/mysqld@.service
# move to proper licenses directories
install -d usr/share/licenses/mariadb
mv usr/share/doc/mariadb/COPYING* usr/share/licenses/mariadb/
# move it where one might look for it
mv usr/share/{groonga,doc/mariadb/}
mv usr/share/{groonga-normalizer-mysql,doc/mariadb/}
# already installed to real systemd unit directory
rm -r usr/share/mysql/systemd/
# init scripts for sysvinit and not needed things
rm usr/share/mysql/{binary-configure,mysql.server,mysqld_multi.server}
rm -r usr/lib/systemd/system/mariadb@bootstrap.service.d
# if SYSCONFDIR has been set, some more files have been installed
if [ -d "$pkgdir"/etc ] ; then
# some we don't want
rm usr/bin/rcmysql
rm -r `find etc -name init.d`
rm -r `find etc -name systemd`
rm -r `find etc -name logrotate.d`
else
# some we would like to have
mkdir -p etc/mysql
cp "$srcdir"/${pkgbase%-10.3}-$pkgver/support-files/rpm/{*.cnf,*.preset} \
etc/mysql
fi
# provided by libmariadbclient
rm usr/bin/{mysql,mariadb}_config
rm usr/lib/lib{mysql,mariadb}*
rm usr/lib/mysql/plugin/{auth_gssapi_client.so,dialog.so,mysql_clear_password.so,sha256_password.so,caching_sha2_password.so}
rm usr/share/man/man1/mysql_config.1
rm -r usr/include/
rm -r usr/share/{aclocal,pkgconfig}
rm -r usr/lib/pkgconfig
# provided by mariadb-clients
rm usr/bin/{mysql,mysql_plugin,mysql_upgrade,mysqladmin,mysqlbinlog,mysqlcheck,mysqldump,mysqlimport,mysqlshow,mysqlslap,mysqltest}
rm usr/share/man/man1/{mysql,mysql_plugin,mysql_upgrade,mysqladmin,mysqlbinlog,mysqlcheck,mysqldump,mysqlimport,mysqlshow,mysqlslap,mysqltest}.1
# provided by mytop
rm usr/bin/mytop
# not needed
rm -r usr/{data,sql-bench,share/mysql-test}
rm usr/share/man/man1/mysql-test-run.pl.1
# The comments in the .cnf files fit only for SYSCONFDIR=/etc SYSCONFDIR2=/etc/my.cnf.d
# Arch used so far /etc/mysql/ for both:
sed -e "s/include all files from the config directory/read configuration from the respective files/" \
-e/includedir/g -i etc/mysql/my.cnf
echo "!include /etc/mysql/client.cnf" >> etc/mysql/my.cnf
echo "!include /etc/mysql/mysql-clients.cnf" >> etc/mysql/my.cnf
echo "!include /etc/mysql/server.cnf" >> etc/mysql/my.cnf
# Many users want to run the Database server only for the local machine
# Let's improve security a bit by letting it only be reachable locally
# (This is also the default in Ubuntu / Debian)
sed '/\[mysqld\]/a bind_address = 127.0.0.1' -i etc/mysql/server.cnf
sed '/\[mysqld\]/a # Allow only connections from this computer' -i etc/mysql/server.cnf
# Fix a comment
sed "s;# /etc/systemd/system/mariadb.service;# /usr/lib/systemd/system/mariadb.service;" \
-i usr/lib/systemd/system/mariadb.service
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment