Skip to content

Commit 5c64d33

Browse files
committed
Add macOS packaging scripts
1 parent 97de865 commit 5c64d33

File tree

19 files changed

+5970
-0
lines changed

19 files changed

+5970
-0
lines changed

macOSpkg/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
These files support the creation of a native macOS .pkg installer for MariaDB Server.
2+
3+
This installer is intended to install a specially-built MariaDB distribution that runs independent of other things installed on the OS. See https://mariadb.com/kb/en/mariadb/installing-mariadb-server-pkg-packages-on-macos/ for more information about the behavior of the .pkg installer and the MariaDB distribution it installs.
4+
5+
Build Instructions:
6+
7+
The recommended build configuration is achieved by invoking cmake with these options:
8+
9+
cmake . -DBUILD_CONFIG=mysql_release -DWITH_SSL=system -DOPENSSL_SSL_LIBRARY="/usr/local/opt/openssl/lib/libssl.a" -DOPENSSL_CRYPTO_LIBRARY="/usr/local/opt/openssl/lib/libcrypto.a" -DOPENSSL_INCLUDE_DIR="/usr/local/opt/openssl/include" -DTOKUDB_OK=0 -DWITH_JEMALLOC=no -DMYSQL_UNIX_ADDR=/usr/local/mariadb/data/mariadb.sock -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb/server -DINSTALL_MYSQLDATADIR=/usr/local/mariadb/data -DDEFAULT_SYSCONFDIR=/usr/local/mariadb/etc -DWITH_EMBEDDED_SERVER=OFF -DPLUGIN_AWS_KEY_MANAGEMENT=NO -DWITH_UNIT_TESTS=OFF -DWITH_WSREP=OFF
10+
11+
Build the TGZ package using cmake && make package, and then point mkpkg to that archive.

macOSpkg/distribution.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<installer-gui-script minSpecVersion="1">
3+
<title>MariaDB Server</title>
4+
<background file="MariaDB_background.png" mime-type="image/png" />
5+
<allowed-os-versions>
6+
<os-version min="10.11.0"/>
7+
</allowed-os-versions>
8+
<domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/>
9+
<installation-check script="InstallationCheck()"/>
10+
<script>
11+
function InstallationCheck(prefix) {
12+
if (system.compareVersions(system.version.ProductVersion, '10.11.0') &lt; 0) {
13+
my.result.message = 'Sorry, macOS Sierra (10.11) or higher is required to install this MariaDB Server package. Consider installing from Homebrew instead on earlier versions of OS X.';
14+
my.result.type = 'Fatal';
15+
return false;
16+
}
17+
var existing = system.run('check_for_existing_installation');
18+
if (existing > 0) {
19+
// _err_existing_process=2
20+
// _err_existing_tcp=4
21+
// _err_existing_socket=8
22+
// _err_existing_install=16
23+
my.result.message = "Installation of MariaDB Server may interfere with, or be affected by, your existing installation. Proceed with caution.";
24+
my.result.type = 'Warning';
25+
if (existing &amp; 16) { my.result.message += "\n\n• There is an existing install of MariaDB Server running from /usr/local/mariadb/server. This instance will be stopped before installation proceeds." }
26+
if (existing &amp; 2) { my.result.message += "\n\n• There is a mariadbd or mysqld process already running on this computer." }
27+
if (existing &amp; 4) { my.result.message += "\n\n• There is a server already listening on TCP port 3306. This MariaDB Server installation will be started with networking disabled unless an existing MariaDB Server installation, stopped during the install process, is bound to that port." }
28+
if (existing &amp; 8) { my.result.message += "\n\n• There is an existing socket file at /tmp/mysql.sock." }
29+
return false
30+
}
31+
return true;
32+
}
33+
</script>
34+
<welcome file="welcome.html" mime-type="text/html" />
35+
<license file="license.html" mime-type="text/html" />
36+
<conclusion file="conclusion.html" mime-type="text/html"/>
37+
<options customize="allow" require-scripts="false" allow-external-scripts="yes"/>
38+
<choices-outline>
39+
<line choice="com.mariadb.mariadb-server-files"/>
40+
<line choice="com.mariadb.mariadb-server-launchd"/>
41+
</choices-outline>
42+
<choice id="default"/>
43+
<choice id="com.mariadb.mariadb-server-files" visible="true" enabled="true" title="MariaDB Server" description="MariaDB Server and standard tools.">
44+
<pkg-ref id="com.mariadb.mariadb-server-files"/>
45+
</choice>
46+
<choice id="com.mariadb.mariadb-server-launchd" visible="true" enabled="true" title="launchd support" description="Automatically start MariaDB Server using launchd.">
47+
<pkg-ref id="com.mariadb.mariadb-server-launchd"/>
48+
</choice>
49+
<pkg-ref id="com.mariadb.mariadb-server-files" onConclusion="none">#mariadb-server-files.pkg</pkg-ref>
50+
<pkg-ref id="com.mariadb.mariadb-server-launchd" onConclusion="none">#mariadb-server-launchd.pkg</pkg-ref>
51+
</installer-gui-script>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2016 MariaDB Corporation
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; version 2 of the License.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
17+
18+
set -e
19+
set -x
20+
exec >>/var/log/mariadb_installer.log 2>&1
21+
22+
basedir=/usr/local/mariadb/server
23+
datadir=/usr/local/mariadb/data
24+
option_file=/usr/local/mariadb/etc/my.cnf
25+
26+
# If the datadir does NOT exist, create it and bootstrap with some special sauce to remove
27+
# superfluous users and put some unix socket auth users in their place.
28+
if ! [[ -e $datadir ]]
29+
then
30+
cd "$basedir"
31+
mkdir -p "$datadir"
32+
./scripts/mysql_install_db --skip-networking --datadir="$datadir"
33+
# ./bin/mysqld --skip-networking --bootstrap --datadir="$datadir" --basedir=. <<EoSQL
34+
# delete from mysql.user;
35+
# delete from mysql.db;
36+
# flush privileges;
37+
# create user '$USER'@'localhost' identified with unix_socket;
38+
# -- grant all privileges on test.* to '$USER'@'localhost';
39+
#EoSQL
40+
rm -f ./data/*.err
41+
fi
42+
43+
chown -R _mysql "$datadir"
44+
45+
46+
# Is anything listening on port 3306 ?
47+
# If so, start MariaDB Server without networking.
48+
if nc localhost -G 2 3306 < /dev/null &>/dev/null
49+
then
50+
#
51+
if ! [[ -e $option_file ]] ||
52+
! "$basedir"/bin/my_print_defaults --defaults-file="$option_file" --mysqld 2>/dev/null |
53+
grep -q skip.networking
54+
then
55+
printf '%s\n' '[server]' 'skip-networking' >> "$option_file"
56+
fi
57+
fi
58+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2016 MariaDB Corporation
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; version 2 of the License.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
17+
18+
# Unload existing .plist, and stop running MariaDB Server
19+
launchctl unload /Library/LaunchDaemons/com.mariadb.server.plist
20+
21+
mkdir -p /usr/local/mariadb
22+
23+
symlinks=( /usr/local/mariadb/server )
24+
25+
# Go through the symlinks in the array and, for each one, move it to use an unused suffixed
26+
for dest in "${symlinks[@]}"
27+
do
28+
if [[ -L $dest ]]
29+
then
30+
rm "$dest"
31+
elif [[ -e $dest ]]
32+
then
33+
# look for an unused suffix to rename $dest
34+
suffix=0
35+
while [[ -e $dest.$((++suffix)) ]]; do :; done
36+
37+
mv "$dest" "$dest.$suffix"
38+
fi
39+
done
40+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# Create a log file of the script's activities.
3+
exec >>/var/log/mariadb_installer.log 2>&1
4+
5+
# Load the .plist file into launchctl, which will also start MariaDB Server
6+
launchctl load /Library/LaunchDaemons/com.mariadb.server.plist
7+
8+
# Wait 30 seconds for MariaDB Server to start
9+
i=0; while ((i++ < 30)); do pgrep mariadbd && [[ -e /usr/local/mariadb/data/mariadb.sock ]] && break; sleep 1; done
10+
11+
/usr/local/mariadb/server/bin/mysql_upgrade
12+
13+
# ln -sf /usr/local/mariadb/server/bin/* /usr/local/bin/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Label</key> <string>com.mariadb.server</string>
6+
7+
<key>KeepAlive</key>
8+
<dict>
9+
<key>SuccessfulExit</key> <false/>
10+
</dict>
11+
12+
<key>ExitTimeOut</key> <integer>600</integer>
13+
<key>UserName</key> <string>_mysql</string>
14+
<key>GroupName</key> <string>_mysql</string>
15+
16+
<key>WorkingDirectory</key> <string>/usr/local/mariadb/data</string>
17+
<key>Program</key> <string>/usr/local/mariadb/server/bin/mariadbd</string>
18+
<key>ProgramArguments</key>
19+
<array>
20+
<string>/usr/local/mariadb/server/bin/mariadbd</string>
21+
<string>--user=_mysql</string>
22+
<string>--basedir=/usr/local/mariadb/server</string>
23+
<string>--datadir=/usr/local/mariadb/data</string>
24+
<string>--log-basename=mariadb</string>
25+
<string>--plugin-dir=/usr/local/mariadb/server/lib/plugin</string>
26+
</array>
27+
<key>EnvironmentVariables</key>
28+
<dict>
29+
<key>MYSQL_HOME</key> <string>/usr/local/mariadb</string>
30+
</dict>
31+
</dict>
32+
</plist>

macOSpkg/mkpkg

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
3+
# This script takes an existing .tar.gz package of MariaDB Server and morphs it into
4+
# a macOS .pkg installer. The server should be built using some specific CMake options
5+
# outlined in the README file in this source tree for the package to work correctly!
6+
7+
# This script builds two packages: mariadb-server-files and mariadb-server-launchd,
8+
# and then it combines them together into a single, installable .pkg file.
9+
# The script was originally developed by Kolbe Kegel (https://github.com/kolbe).
10+
11+
set -ex
12+
13+
if ! (($# == 1))
14+
then
15+
echo "Must provide path to MariaDB Server .tar.gz package. Aborting." >&2
16+
exit 1
17+
fi
18+
19+
file=$1
20+
dir="${file%*.tar.gz}"
21+
dir="${dir##*/}"
22+
23+
re='mariadb-([0-9]+\.[0-9]+\.[0-9]+)-'
24+
[[ $dir =~ $re ]]
25+
ver=${BASH_REMATCH[1]}
26+
27+
mkdir -p mariadb-server-files tmp
28+
rm -rf mariadb-server-files/* tmp/*
29+
30+
tar -xf "$file" -C mariadb-server-files/
31+
32+
pushd "mariadb-server-files"
33+
pushd "$dir"
34+
35+
pushd bin
36+
37+
# Create these symlinks, so that MariaDB Server is started using "mariadbd" instead
38+
# of "mysqld" and the client program is "mariadb" instead of "mysql".
39+
#ln -s mysql mariadb
40+
#ln -s mysqld mariadbd
41+
42+
popd
43+
popd
44+
45+
ln -s "$dir" server
46+
47+
# Create the etc dir so that it's "installed" by the installer.
48+
mkdir etc
49+
50+
popd
51+
52+
pkgbuild --root ./mariadb-server-files --identifier com.mariadb.mariadb-server-files --scripts ./mariadb-server-files-scripts --version "${ver//./}0" --install-location /usr/local/mariadb mariadb-server-files.pkg
53+
54+
pkgbuild --root ./mariadb-server-launchd --identifier com.mariadb.mariadb-server-launchd --scripts ./mariadb-server-launchd-scripts --install-location /Library/LaunchDaemons mariadb-server-launchd.pkg
55+
56+
productbuild --distribution distribution.xml --resources ./resources --scripts ./resources/scripts "$dir.pkg"
57+
58+
mv mariadb-server-files.pkg mariadb-server-launchd.pkg tmp/

0 commit comments

Comments
 (0)