2020-04-07 11:10:03 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2012-01-23 12:20:16 +01:00
|
|
|
|
2023-03-29 11:42:12 +02:00
|
|
|
# shellcheck source=/dev/null
|
2012-01-23 12:20:16 +01:00
|
|
|
. /usr/share/debconf/confmodule
|
|
|
|
|
2023-03-30 12:58:54 +02:00
|
|
|
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]
|
|
|
|
then
|
|
|
|
set -v -x
|
|
|
|
DEBIAN_SCRIPT_TRACE=1
|
|
|
|
fi
|
|
|
|
|
2023-10-08 04:42:31 +02:00
|
|
|
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2}
|
2016-10-09 22:39:01 +02:00
|
|
|
|
2012-01-23 12:20:16 +01:00
|
|
|
export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
|
|
|
|
|
|
|
|
# This command can be used as pipe to syslog. With "-s" it also logs to stderr.
|
2022-05-01 08:27:39 +02:00
|
|
|
ERR_LOGGER="logger -p daemon.err -t mariadb-server.postinst -i"
|
2020-04-07 11:10:03 +02:00
|
|
|
# Specify syslog tag name so it is clear the entry came from this postinst script.
|
2012-01-23 12:20:16 +01:00
|
|
|
# This will make an error in a logged command immediately apparent by aborting
|
|
|
|
# the install, rather than failing silently and leaving a broken install.
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
configure)
|
2022-12-14 09:13:17 +01:00
|
|
|
# This is needed because mariadb-install-db removes the pid file in /run
|
2018-06-23 15:37:09 +02:00
|
|
|
# and because changed configuration options should take effect immediately.
|
|
|
|
# In case the server wasn't running at all it should be ok if the stop
|
2020-04-26 09:41:21 +02:00
|
|
|
# script fails. I can't tell at this point because of the cleaned /run.
|
2023-03-30 12:58:54 +02:00
|
|
|
set +e
|
|
|
|
invoke-rc.d mariadb stop
|
|
|
|
set -e
|
2020-04-26 09:41:21 +02:00
|
|
|
|
|
|
|
# An existing /etc/init.d/mysql might be on the system if there was a
|
|
|
|
# previous MySQL or MariaDB installation, since /etc/init.d files are
|
|
|
|
# considered config files and stay around even after the package is removed.
|
|
|
|
#
|
|
|
|
# The install step of this package adds a new /etc/init.d/mariadb file. As
|
|
|
|
# we also want to ensure that there are no old (and potentially outdated)
|
|
|
|
# versions of /etc/init.d/mysql we simply replace it using a copy of the
|
|
|
|
# latest 'mariadb' file. This has also the added benefit that anything that
|
|
|
|
# invokes traditional sysv init with either 'mysql' or 'mariadb' will end up
|
|
|
|
# controlling this newly installed MariaDB, and thus we maintain better
|
2021-05-06 21:08:38 +02:00
|
|
|
# backwards compatibility.
|
2020-04-26 09:41:21 +02:00
|
|
|
#
|
|
|
|
# Note that the 'Provides' line is also updated to avoid 'insserv' exiting
|
|
|
|
# on failure (when it is run by update-rc.d) because of duplicate service
|
|
|
|
# names.
|
|
|
|
if [ -f "/etc/init.d/mysql" ] && [ -f "/etc/init.d/mariadb" ]
|
|
|
|
then
|
|
|
|
# Copy init file and rename the service name and filename on the fly
|
|
|
|
sed 's/Provides: mariadb/Provides: mysql/g' /etc/init.d/mariadb > /etc/init.d/mysql
|
|
|
|
# NOTE: Number of spaces/tabs is important here!
|
|
|
|
# Confirm if the sed worked
|
|
|
|
if ! grep --quiet "Provides: mysql" /etc/init.d/mysql
|
|
|
|
then
|
|
|
|
# If not, then delete the file to avoid failures later on
|
|
|
|
rm -f /etc/init.d/mysql
|
|
|
|
echo "Warning! Failed creating a mysql named copy of mariadb init.d file"
|
|
|
|
fi
|
|
|
|
fi
|
2018-06-23 15:37:09 +02:00
|
|
|
|
2024-05-27 08:04:34 +02:00
|
|
|
mariadb_statedir=/usr/share/mariadb
|
|
|
|
mariadb_datadir=/var/lib/mysql
|
|
|
|
mariadb_logdir=/var/log/mysql
|
|
|
|
mariadb_cfgdir=/etc/mysql
|
|
|
|
mariadb_upgradedir=/var/lib/mysql-upgrade
|
2012-01-23 12:20:16 +01:00
|
|
|
|
2016-10-09 22:39:01 +02:00
|
|
|
# If the following symlink exists, it is a preserved copy the old data dir
|
|
|
|
# created by the preinst script during a upgrade that would have otherwise
|
|
|
|
# been replaced by an empty mysql dir. This should restore it.
|
2023-03-30 12:58:54 +02:00
|
|
|
for dir in DATADIR LOGDIR
|
|
|
|
do
|
2016-10-09 22:39:01 +02:00
|
|
|
|
2023-03-30 12:58:54 +02:00
|
|
|
if [ "$dir" = "DATADIR" ]
|
|
|
|
then
|
2024-05-27 08:04:34 +02:00
|
|
|
targetdir=$mariadb_datadir
|
2016-10-09 22:39:01 +02:00
|
|
|
else
|
2024-05-27 08:04:34 +02:00
|
|
|
targetdir=$mariadb_logdir
|
2016-10-09 22:39:01 +02:00
|
|
|
fi
|
|
|
|
|
2024-05-27 08:04:34 +02:00
|
|
|
savelink="$mariadb_upgradedir/$dir.link"
|
2023-03-30 12:58:54 +02:00
|
|
|
if [ -L "$savelink" ]
|
|
|
|
then
|
2016-10-09 22:39:01 +02:00
|
|
|
# If the targetdir was a symlink before we upgraded it is supposed
|
|
|
|
# to be either still be present or not existing anymore now.
|
2023-03-30 12:58:54 +02:00
|
|
|
if [ -L "$targetdir" ]
|
|
|
|
then
|
2016-10-09 22:39:01 +02:00
|
|
|
rm "$savelink"
|
2023-03-30 12:58:54 +02:00
|
|
|
elif [ ! -d "$targetdir" ]
|
|
|
|
then
|
2016-10-09 22:39:01 +02:00
|
|
|
mv "$savelink" "$targetdir"
|
|
|
|
else
|
|
|
|
# this should never even happen, but just in case...
|
2024-05-27 08:04:34 +02:00
|
|
|
mariadb_tmp=$(mktemp -d -t mariadb-symlink-restore-XXXXXX)
|
|
|
|
echo "this is very strange! see $mariadb_tmp/README..." >&2
|
|
|
|
mv "$targetdir" "$mariadb_tmp"
|
|
|
|
cat << EOF > "$mariadb_tmp/README"
|
2016-10-09 22:39:01 +02:00
|
|
|
|
2018-04-11 08:14:58 +02:00
|
|
|
If you're reading this, it's most likely because you had replaced /var/lib/mysql
|
2012-01-23 12:20:16 +01:00
|
|
|
with a symlink, then upgraded to a new version of mysql, and then dpkg
|
2016-10-09 22:39:01 +02:00
|
|
|
removed your symlink (see #182747 and others). The mysql packages noticed
|
|
|
|
that this happened, and as a workaround have restored it. However, because
|
2012-01-23 12:20:16 +01:00
|
|
|
/var/lib/mysql seems to have been re-created in the meantime, and because
|
2016-10-09 22:39:01 +02:00
|
|
|
we don't want to rm -rf something we don't know as much about, we are going
|
|
|
|
to leave this unexpected directory here. If your database looks normal,
|
2012-01-23 12:20:16 +01:00
|
|
|
and this is not a symlink to your database, you should be able to blow
|
|
|
|
this all away.
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
2016-10-09 22:39:01 +02:00
|
|
|
fi
|
2024-05-27 08:04:34 +02:00
|
|
|
rmdir $mariadb_upgradedir 2>/dev/null || true
|
2016-10-09 22:39:01 +02:00
|
|
|
|
2023-10-08 04:42:31 +02:00
|
|
|
done # end 'for dir' loop
|
2020-12-20 22:29:29 +01:00
|
|
|
|
2020-09-17 02:36:25 +02:00
|
|
|
# Upgrading from mysql.com needs might have the root user as auth_socket.
|
|
|
|
# auto.cnf is a sign of a mysql install, that doesn't exist in mariadb.
|
|
|
|
# We use lsof to protect against concurrent access by mysqld (mariadb has
|
|
|
|
# its own projection). We make sure we're not doing this on a MySQL-8.0
|
|
|
|
# directory.
|
|
|
|
# This direct update is needed to enable an authentication mechanism to
|
|
|
|
# perform mariadb-upgrade, (MDEV-22678). To keep the impact minimal, we
|
|
|
|
# skip innodb and set key-buffer-size to 0 as it isn't reused.
|
2024-05-27 08:04:34 +02:00
|
|
|
if [ -f "$mariadb_datadir/auto.cnf" ] &&
|
2024-08-06 14:45:24 +02:00
|
|
|
[ -f "$mariadb_datadir/mysql/user.MYD" ] &&
|
|
|
|
! lsof -nt "$mariadb_datadir"/mysql/user.MYD > /dev/null &&
|
|
|
|
[ ! -f "$mariadb_datadir/undo_001" ]
|
2023-03-30 12:58:54 +02:00
|
|
|
then
|
2023-10-08 04:42:31 +02:00
|
|
|
echo "UPDATE mysql.user SET plugin='unix_socket' WHERE plugin='auth_socket';" | \
|
|
|
|
mariadbd --skip-innodb --key_buffer_size=0 --default-storage-engine=MyISAM --bootstrap 2> /dev/null
|
2020-09-17 02:36:25 +02:00
|
|
|
fi
|
2016-10-09 22:39:01 +02:00
|
|
|
|
2012-01-23 12:20:16 +01:00
|
|
|
# Ensure the existence and right permissions for the database and
|
2020-04-07 11:10:03 +02:00
|
|
|
# log files. Use mkdir option 'Z' to create with correct SELinux context.
|
2024-05-27 08:04:34 +02:00
|
|
|
if [ ! -d "$mariadb_statedir" ] && [ ! -L "$mariadb_statedir" ]
|
2023-03-30 12:58:54 +02:00
|
|
|
then
|
2024-05-27 08:04:34 +02:00
|
|
|
mkdir -Z "$mariadb_statedir"
|
2023-03-30 12:58:54 +02:00
|
|
|
fi
|
2024-05-27 08:04:34 +02:00
|
|
|
if [ ! -d "$mariadb_datadir" ] && [ ! -L "$mariadb_datadir" ]
|
2023-03-30 12:58:54 +02:00
|
|
|
then
|
2024-05-27 08:04:34 +02:00
|
|
|
mkdir -Z "$mariadb_datadir"
|
2023-03-30 12:58:54 +02:00
|
|
|
fi
|
2024-05-27 08:04:34 +02:00
|
|
|
if [ ! -d "$mariadb_logdir" ] && [ ! -L "$mariadb_logdir" ]
|
2023-03-30 12:58:54 +02:00
|
|
|
then
|
2024-05-27 08:04:34 +02:00
|
|
|
mkdir -Z "$mariadb_logdir"
|
2023-03-30 12:58:54 +02:00
|
|
|
fi
|
2012-01-23 12:20:16 +01:00
|
|
|
# When creating an ext3 jounal on an already mounted filesystem like e.g.
|
2021-08-23 10:10:59 +02:00
|
|
|
# /var/lib/mysql, you get a .journal file that is not modifiable by chown.
|
2024-05-27 08:04:34 +02:00
|
|
|
# The mariadb_statedir must not be writable by the mysql user under any
|
2012-01-23 12:20:16 +01:00
|
|
|
# circumstances as it contains scripts that are executed by root.
|
|
|
|
set +e
|
2024-08-06 14:45:24 +02:00
|
|
|
find $mariadb_statedir ! -uid 0 -print0 -or ! -gid 0 -print0 | xargs -0 -r sudo chown 0:0
|
2024-05-27 08:04:34 +02:00
|
|
|
find $mariadb_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql
|
2024-08-06 14:45:24 +02:00
|
|
|
chown mysql:adm $mariadb_logdir
|
|
|
|
find "$mariadb_logdir" -print0 | xargs -0 -r chown mysql:adm
|
2024-05-27 08:04:34 +02:00
|
|
|
chmod 2750 $mariadb_logdir
|
2012-01-23 12:20:16 +01:00
|
|
|
set -e
|
|
|
|
|
2020-04-08 19:18:37 +02:00
|
|
|
## Set the correct filesystem ownership for the PAM v2 plugin
|
|
|
|
# eg. /usr/lib/x86_64-linux-gnu/mysql/plugin/auth_pam_tool_dir/
|
|
|
|
# NOTE! This is security sensitive, don't allow for a race condition.
|
|
|
|
#
|
|
|
|
# 1. Drop privileges of directory
|
|
|
|
# -> At this point only root can see and execute auth_pam_tool
|
|
|
|
chmod 0700 /usr/lib/mysql/plugin/auth_pam_tool_dir
|
|
|
|
#
|
|
|
|
# 2. Make binary setuid
|
|
|
|
# -> At this point only root can run the setuid binary so no escalation here yet
|
|
|
|
chmod 04755 /usr/lib/mysql/plugin/auth_pam_tool_dir/auth_pam_tool
|
|
|
|
#
|
|
|
|
# 3. Allow user 'mysql' to see and execute auth_pam_tool
|
|
|
|
# -> Now user mysql owns the directory and can see and execute the binary inside
|
|
|
|
# -> Since the binary is setuid, user mysql gets limited root powers here to
|
|
|
|
# run the PAM authetications, which need root (e.g. to validate passwords
|
|
|
|
# against /etc/shadow)
|
2020-01-15 18:08:02 +01:00
|
|
|
chown mysql /usr/lib/mysql/plugin/auth_pam_tool_dir
|
|
|
|
|
2012-01-23 12:20:16 +01:00
|
|
|
# This is important to avoid dataloss when there is a removed
|
2024-05-27 08:04:34 +02:00
|
|
|
# mariadb-server version from Woody lying around which used the same
|
2022-12-17 00:47:45 +01:00
|
|
|
# data directory and then somehow gets purged by the admin.
|
2016-10-09 22:39:01 +02:00
|
|
|
db_set mariadb-server/postrm_remove_database false || true
|
|
|
|
|
|
|
|
# Clean up old flags before setting new one
|
2024-05-27 08:04:34 +02:00
|
|
|
rm -f $mariadb_datadir/debian-*.flag
|
2016-10-09 22:39:01 +02:00
|
|
|
# Flag data dir to avoid downgrades
|
2023-10-08 04:42:31 +02:00
|
|
|
# @TODO: Rewrite this to use the new upstream /var/lib/mysql_upgrade_info file
|
|
|
|
# instead of the legacy /var/lib/debian-XX.X.flag file
|
2024-05-27 08:04:34 +02:00
|
|
|
touch "$mariadb_datadir/debian-__MARIADB_MAJOR_VER__.flag"
|
2016-10-09 22:39:01 +02:00
|
|
|
|
|
|
|
# initiate databases. Output is not allowed by debconf :-(
|
|
|
|
# This will fail if we are upgrading an existing database; in this case
|
2022-12-14 09:13:17 +01:00
|
|
|
# mariadb-upgrade, called from the /etc/mysql/debian-start script, will
|
2016-10-09 22:39:01 +02:00
|
|
|
# handle things.
|
|
|
|
# Debian: beware of the bashisms...
|
|
|
|
# Debian: can safely run on upgrades with existing databases
|
2023-10-08 04:42:31 +02:00
|
|
|
# Workaround for Debian Bug #1022994: failure to create database when
|
|
|
|
# working with libpam-tmpdir (by setting TMPDIR to empty value).
|
2016-10-09 22:39:01 +02:00
|
|
|
set +e
|
2023-10-08 04:42:31 +02:00
|
|
|
TMPDIR='' bash /usr/bin/mariadb-install-db \
|
|
|
|
--rpm --cross-bootstrap \
|
|
|
|
--user=mysql --disable-log-bin \
|
|
|
|
--skip-test-db 2>&1 | \
|
2023-03-29 11:28:51 +02:00
|
|
|
$ERR_LOGGER
|
2016-10-09 22:39:01 +02:00
|
|
|
set -e
|
2012-01-23 12:20:16 +01:00
|
|
|
|
2019-02-20 16:39:48 +01:00
|
|
|
# On new installations root user can connect via unix_socket.
|
|
|
|
# But on upgrades, scripts rely on debian-sys-maint user and
|
|
|
|
# credentials in /etc/mysql/debian.cnf
|
|
|
|
# All tools use --defaults-file=/etc/mysql/debian.cnf
|
|
|
|
# And while it's not needed for new installations, we keep using
|
|
|
|
# --defaults-file option for tools (for the sake of upgrades)
|
|
|
|
# and thus need /etc/mysql/debian.cnf to exist, even if it's empty.
|
2020-10-04 11:57:48 +02:00
|
|
|
# In the long run the goal is to obsolete this file.
|
2024-05-27 08:04:34 +02:00
|
|
|
dc="$mariadb_cfgdir/debian.cnf"
|
|
|
|
if [ ! -d "$mariadb_cfgdir" ]
|
2023-03-30 12:58:54 +02:00
|
|
|
then
|
2024-05-27 08:04:34 +02:00
|
|
|
install -o 0 -g 0 -m 0755 -d $mariadb_cfgdir
|
2020-04-07 11:10:03 +02:00
|
|
|
fi
|
2023-10-08 04:42:31 +02:00
|
|
|
|
2023-03-30 12:58:54 +02:00
|
|
|
if [ ! -e "$dc" ]
|
|
|
|
then
|
2023-03-29 11:28:51 +02:00
|
|
|
cat /dev/null > $dc
|
2023-03-29 11:42:12 +02:00
|
|
|
{
|
|
|
|
echo "# THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE.";
|
|
|
|
echo "# This file exists only for backwards compatibility for";
|
|
|
|
echo "# tools that run '--defaults-file=/etc/mysql/debian.cnf'";
|
|
|
|
echo "# and have root level access to the local filesystem.";
|
|
|
|
echo "# With those permissions one can run 'mariadb' directly";
|
|
|
|
echo "# anyway thanks to unix socket authentication and hence";
|
|
|
|
echo "# this file is useless. See package README for more info.";
|
|
|
|
echo "[client]";
|
|
|
|
echo "host = localhost";
|
|
|
|
echo "user = root";
|
2024-05-27 08:04:34 +02:00
|
|
|
echo "[mariadb_upgrade]";
|
2023-03-29 11:42:12 +02:00
|
|
|
echo "host = localhost";
|
|
|
|
echo "user = root";
|
|
|
|
echo "# THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE.";
|
|
|
|
} >> $dc
|
2012-01-23 12:20:16 +01:00
|
|
|
fi
|
2019-02-20 16:39:48 +01:00
|
|
|
# Keep it only root-readable, as it always was
|
2012-01-23 12:20:16 +01:00
|
|
|
chown 0:0 $dc
|
|
|
|
chmod 0600 $dc
|
|
|
|
|
|
|
|
# If there is a real AppArmor profile, we reload it.
|
|
|
|
# If the default empty profile is installed, then we remove any old
|
|
|
|
# profile that may be loaded.
|
|
|
|
# This allows upgrade from old versions (that have an apparmor profile
|
|
|
|
# on by default) to work both to disable a default profile, and to keep
|
|
|
|
# any profile installed and maintained by users themselves.
|
2020-06-11 00:39:11 +02:00
|
|
|
profile="/etc/apparmor.d/usr.sbin.mariadbd"
|
2023-10-08 04:42:31 +02:00
|
|
|
if [ -f "$profile" ] && aa-status --enabled 2> /dev/null
|
2023-03-30 12:58:54 +02:00
|
|
|
then
|
2023-10-08 04:42:31 +02:00
|
|
|
if grep -q /usr/sbin/mariadbd "$profile" 2> /dev/null
|
2023-03-30 12:58:54 +02:00
|
|
|
then
|
2020-04-07 11:10:03 +02:00
|
|
|
apparmor_parser -r "$profile" || true
|
|
|
|
else
|
2023-10-08 04:42:31 +02:00
|
|
|
echo "/usr/sbin/mariadbd { }" | apparmor_parser --remove 2> /dev/null || true
|
2020-04-07 11:10:03 +02:00
|
|
|
fi
|
2012-01-23 12:20:16 +01:00
|
|
|
fi
|
2015-11-04 17:13:15 +01:00
|
|
|
|
2022-05-05 06:42:38 +02:00
|
|
|
# The introduction of /etc/logrotate.d/mariadb has made the old config
|
|
|
|
# obsolete and it needs to be disabled to prevent logrotate running twice.
|
|
|
|
if [ -f /etc/logrotate.d/mysql-server ]
|
|
|
|
then
|
|
|
|
mv -vf /etc/logrotate.d/mysql-server /etc/logrotate.d/mysql-server.dpkg-bak
|
|
|
|
fi
|
|
|
|
|
2020-05-04 19:45:18 +02:00
|
|
|
# @TODO: Remove once buildbot.askmonty.org has been updated not to expect this file
|
|
|
|
mkdir -p /etc/systemd/system/mariadb.service.d/
|
|
|
|
# Note that file cannot be empty, otherwise systemd version in Ubuntu Bionic
|
|
|
|
# will think the service is masked
|
|
|
|
echo "# empty placeholder" > /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
|
2023-03-29 11:28:51 +02:00
|
|
|
;;
|
2012-01-23 12:20:16 +01:00
|
|
|
|
|
|
|
abort-upgrade|abort-remove|abort-configure)
|
2023-03-29 11:28:51 +02:00
|
|
|
;;
|
2012-01-23 12:20:16 +01:00
|
|
|
|
2018-06-23 15:37:09 +02:00
|
|
|
triggered)
|
2023-03-30 12:58:54 +02:00
|
|
|
if [ -d /run/systemd/system ]
|
|
|
|
then
|
2021-04-14 10:35:39 +02:00
|
|
|
systemctl --system daemon-reload
|
2023-10-08 04:42:31 +02:00
|
|
|
elif [ -x /etc/init.d/mariadb ]
|
|
|
|
then
|
2020-04-26 09:41:21 +02:00
|
|
|
invoke-rc.d mariadb restart
|
2018-06-23 15:37:09 +02:00
|
|
|
fi
|
2023-03-29 11:28:51 +02:00
|
|
|
;;
|
2018-06-23 15:37:09 +02:00
|
|
|
|
2012-01-23 12:20:16 +01:00
|
|
|
*)
|
|
|
|
echo "postinst called with unknown argument '$1'" 1>&2
|
|
|
|
exit 1
|
2023-03-29 11:28:51 +02:00
|
|
|
;;
|
2012-01-23 12:20:16 +01:00
|
|
|
esac
|
|
|
|
|
2021-08-23 10:10:59 +02:00
|
|
|
db_stop # in case invoke fails
|
2012-01-23 12:20:16 +01:00
|
|
|
|
|
|
|
#DEBHELPER#
|
2020-04-21 23:48:14 +02:00
|
|
|
|