Browse Source

MDEV-6284: Sync mariadb-server maintainer scripts as much as possible

There are still some differences in due to systemd and service triggers,
but these differences make sense and are likely to be synced the other
way later so that downstream Debian official packaging adopts them.

The synced changes include among others:
- 9f49e4b494
- 6440c0d6e7
- 6e5ee72d64
- e62e67ae4b
- df2415a53d
- 643558da74
pull/1510/head
Otto Kekäläinen 6 years ago
committed by Vicențiu-Marian Ciorbaru
parent
commit
4e946b0f0c
  1. 38
      debian/mariadb-server-10.5.postinst
  2. 37
      debian/mariadb-server-10.5.postrm
  3. 51
      debian/mariadb-server-10.5.preinst
  4. 8
      debian/mariadb-server-10.5.prerm

38
debian/mariadb-server-10.5.postinst

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/bin/bash
set -e
. /usr/share/debconf/confmodule
@ -12,6 +13,7 @@ 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.
ERR_LOGGER="logger -p daemon.err -t mariadb-server-$MAJOR_VER.postinst -i"
# Specify syslog tag name so it is clear the entry came from this postinst script.
# 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
@ -31,7 +33,6 @@ case "$1" in
mysql_statedir=/usr/share/mysql
mysql_datadir=/var/lib/mysql
mysql_logdir=/var/log/mysql
mysql_rundir=/var/run/mysqld
mysql_cfgdir=/etc/mysql
mysql_upgradedir=/var/lib/mysql-upgrade
@ -56,7 +57,7 @@ case "$1" in
mv "$savelink" "$targetdir"
else
# this should never even happen, but just in case...
mysql_tmp=`mktemp -d -t mysql-symlink-restore-XXXXXX`
mysql_tmp=$(mktemp -d -t mysql-symlink-restore-XXXXXX)
echo "this is very strange! see $mysql_tmp/README..." >&2
mv "$targetdir" "$mysql_tmp"
cat << EOF > "$mysql_tmp/README"
@ -79,17 +80,17 @@ EOF
done
# Ensure the existence and right permissions for the database and
# log files.
if [ ! -d "$mysql_statedir" -a ! -L "$mysql_statedir" ]; then mkdir "$mysql_statedir"; fi
if [ ! -d "$mysql_datadir" -a ! -L "$mysql_datadir" ]; then mkdir "$mysql_datadir" ; fi
if [ ! -d "$mysql_logdir" -a ! -L "$mysql_logdir" ]; then mkdir "$mysql_logdir" ; fi
# log files. Use mkdir option 'Z' to create with correct SELinux context.
if [ ! -d "$mysql_statedir" ] && [ ! -L "$mysql_statedir" ]; then mkdir -Z "$mysql_statedir"; fi
if [ ! -d "$mysql_datadir" ] && [ ! -L "$mysql_datadir" ]; then mkdir -Z "$mysql_datadir" ; fi
if [ ! -d "$mysql_logdir" ] && [ ! -L "$mysql_logdir" ]; then mkdir -Z "$mysql_logdir" ; fi
# When creating an ext3 jounal on an already mounted filesystem like e.g.
# /var/lib/mysql, you get a .journal file that is not modifyable by chown.
# The mysql_statedir must not be writable by the mysql user under any
# circumstances as it contains scripts that are executed by root.
set +e
chown -R 0:0 $mysql_statedir
find $mysql_datadir ! -uid $(id -u mysql) -print0 | xargs -0 -r chown mysql
find $mysql_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql
chown -R mysql:adm $mysql_logdir
chmod 2750 $mysql_logdir
set -e
@ -105,7 +106,7 @@ EOF
# Clean up old flags before setting new one
rm -f $mysql_datadir/debian-*.flag
# Flag data dir to avoid downgrades
touch $mysql_datadir/debian-10.5.flag
touch "$mysql_datadir/debian-$MAJOR_VER.flag"
# initiate databases. Output is not allowed by debconf :-(
# This will fail if we are upgrading an existing database; in this case
@ -115,12 +116,12 @@ EOF
# Debian: can safely run on upgrades with existing databases
set +e
bash /usr/bin/mysql_install_db --rpm --cross-bootstrap --user=mysql \
--disable-log-bin --skip-test-db 2>&1 | \
--disable-log-bin --skip-test-db 2>&1 | \
$ERR_LOGGER
set -e
# To avoid downgrades.
touch $mysql_statedir/debian-$MAJOR_VER.flag
touch "$mysql_statedir/debian-$MAJOR_VER.flag"
# On new installations root user can connect via unix_socket.
# But on upgrades, scripts rely on debian-sys-maint user and
@ -130,6 +131,9 @@ EOF
# --defaults-file option for tools (for the sake of upgrades)
# and thus need /etc/mysql/debian.cnf to exist, even if it's empty.
dc=$mysql_cfgdir/debian.cnf;
if [ ! -d "$mysql_cfgdir" ]; then
install -o 0 -g 0 -m 0755 -d $mysql_cfgdir
fi
if [ ! -e "$dc" ]; then
cat /dev/null > $dc
echo "# Automatically generated for Debian scripts. DO NOT TOUCH!" >>$dc
@ -146,11 +150,11 @@ EOF
# any profile installed and maintained by users themselves.
profile="/etc/apparmor.d/usr.sbin.mysqld"
if [ -f "$profile" ] && aa-status --enabled 2>/dev/null; then
if grep -q /usr/sbin/mysqld "$profile" 2>/dev/null ; then
apparmor_parser -r "$profile" || true
else
echo "/usr/sbin/mysqld { }" | apparmor_parser --remove 2>/dev/null || true
fi
if grep -q /usr/sbin/mysqld "$profile" 2>/dev/null ; then
apparmor_parser -r "$profile" || true
else
echo "/usr/sbin/mysqld { }" | apparmor_parser --remove 2>/dev/null || true
fi
fi
# copy out any mysqld_safe settings
@ -189,5 +193,3 @@ if [ -x "$(command -v deb-systemd-helper)" ]; then
fi
#DEBHELPER#
exit 0

37
debian/mariadb-server-10.5.postrm

@ -1,7 +1,11 @@
#!/bin/bash -e
#!/bin/bash
set -e
. /usr/share/debconf/confmodule
# Automatically set version to ease maintenance of this file
MAJOR_VER="${DPKG_MAINTSCRIPT_PACKAGE#mariadb-server-}"
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
@ -37,17 +41,18 @@ case "$1" in
esac
#
# - Do NOT purge logs or data if another mysql-sever* package is installed (#307473)
# - Purge logs and data only if they are ours (#307473)
# - Remove the mysql user only after all his owned files are purged.
# - Cleanup the initscripts only if this was the last provider of them
#
if [ "$1" = "purge" -a ! \( -x /usr/sbin/mysqld -o -L /usr/sbin/mysqld \) ]; then
if [ "$1" = "purge" ] && [ -f "/var/lib/mysql/debian-$MAJOR_VER.flag" ]; then
# we remove the mysql user only after all his owned files are purged
rm -f /var/log/mysql.{log,err}{,.0,.[1234567].gz}
rm -rf /var/log/mysql
db_input high mariadb-server-10.5/postrm_remove_databases || true
db_input high "mariadb-server-$MAJOR_VER/postrm_remove_databases" || true
db_go || true
db_get mariadb-server-10.5/postrm_remove_databases || true
db_get "mariadb-server-$MAJOR_VER/postrm_remove_databases" || true
if [ "$RET" = "true" ]; then
# never remove the debian.cnf when the databases are still existing
# else we ran into big trouble on the next install!
@ -56,13 +61,19 @@ if [ "$1" = "purge" -a ! \( -x /usr/sbin/mysqld -o -L /usr/sbin/mysqld \) ]; the
# directory with file system data. See #829491 for details and
# #608938 for potential mysql-server leftovers which erroneously
# had been renamed.
find /var/lib/mysql -mindepth 1 \
-not -path '*/lost+found/*' -not -name 'lost+found' \
-not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \
-delete
# "|| true" still needed as rmdir still exits with non-zero if
# /var/lib/mysql is a mount point
rmdir --ignore-fail-on-non-empty /var/lib/mysql || true
# Attempt removal only if the directory hasn't already been removed
# by dpkg to avoid failing on "No such file or directory" errors.
if [ -d /var/lib/mysql ]
then
find /var/lib/mysql -mindepth 1 \
-not -path '*/lost+found/*' -not -name 'lost+found' \
-not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \
-delete
# "|| true" still needed as rmdir still exits with non-zero if
# /var/lib/mysql is a mount point
rmdir --ignore-fail-on-non-empty /var/lib/mysql || true
fi
rm -rf /var/run/mysqld # this directory is created by the init script, don't leave behind
userdel mysql || true
fi
@ -70,5 +81,3 @@ if [ "$1" = "purge" -a ! \( -x /usr/sbin/mysqld -o -L /usr/sbin/mysqld \) ]; the
fi
#DEBHELPER#
exit 0

51
debian/mariadb-server-10.5.preinst

@ -9,6 +9,14 @@
. /usr/share/debconf/confmodule
# Automatically set version to ease maintenance of this file
MAJOR_VER="${DPKG_MAINTSCRIPT_PACKAGE#mariadb-server-}"
# Just kill the invalid insserv.conf.d directory without fallback
if [ -d "/etc/insserv.conf.d/mariadb/" ]; then
rm -rf "/etc/insserv.conf.d/mariadb/"
fi
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
@ -41,7 +49,7 @@ stop_server() {
################################ main() ##########################
this_version=10.5
this_version=$MAJOR_VER
max_upgradeable_version=5.7
# Check if a flag file is found that indicates a previous MariaDB or MySQL
@ -53,12 +61,12 @@ do
# The for loop leaves $flag as the query string if there are no results,
# so the check below is needed to stop further processing when there are
# no real results.
if [ $flag = "$mysql_datadir/debian-*.flag" ]
if [ "$flag" = "$mysql_datadir/debian-*.flag" ]
then
break
fi
flag_version=`echo $flag | sed 's/.*debian-\([0-9\.]\+\).flag/\1/'`
flag_version=$(echo "$flag" | sed 's/.*debian-\([0-9\.]\+\).flag/\1/')
# Initialize value if empty
if [ -z "$found_version" ]
@ -85,6 +93,15 @@ done
if [ ! -z "$found_version" ]
then
# MySQL 8.0 in Ubuntu has a bug in packaging and the file is name wrongly
# 'debian-5.7.flag', so in case '5.7' was encountered an extra check needs to
# be done to see is there is a file called undo_001, which is a sign of 8.0.
if [ "$found_version" == "5.7" ] && [ -f "$mysql_datadir/undo_001" ]
then
# Seems to be a 8.0, flag has wrongly 5.7 (know bug)
found_version=8.0
fi
echo "$mysql_datadir: found previous version $found_version"
if dpkg --compare-versions "$found_version" '>>' "$this_version"
@ -105,17 +122,17 @@ fi
# Instead simply move the old datadir and create a new for this_version.
if [ ! -z "$downgrade_detected" ]
then
db_input critical mariadb-server-10.5/old_data_directory_saved || true
db_input critical "mariadb-server-$MAJOR_VER/old_data_directory_saved" || true
db_go
echo "The file $mysql_datadir/debian-$found_version.flag indicates a" 1>&2
echo "version that cannot automatically be upgraded. Therefore the" 1>&2
echo "previous data directory will be renamed to $mysql_datadir-$found_version and" 1>&2
echo "a new data directory will be initialized at $mysql_datadir." 1>&2
echo "Please manually export/import your data (e.g. with mysqldump) if needed." 1>&2
mv -f $mysql_datadir $mysql_datadir-$found_version
mv -f "$mysql_datadir" "$mysql_datadir-$found_version"
# Also move away the old debian.cnf file that included credentials that are
# no longer valid
mv -f /etc/mysql/debian.cnf /etc/mysql/debian.cnf-$found_version
mv -f /etc/mysql/debian.cnf "/etc/mysql/debian.cnf-$found_version"
fi
# to be sure
@ -124,7 +141,7 @@ stop_server
# If we use NIS then errors should be tolerated. It's up to the
# user to ensure that the mysql user is correctly setup.
# Beware that there are two ypwhich one of them needs the 2>/dev/null!
if test -n "`which ypwhich 2>/dev/null`" && ypwhich >/dev/null 2>&1; then
if test -n "$(which ypwhich 2>/dev/null)" && ypwhich >/dev/null 2>&1; then
set +e
fi
@ -164,16 +181,18 @@ set -e
# if there's a symlink, let's store where it's pointing, because otherwise
# it's going to be lost in some situations
for dir in DATADIR LOGDIR; do
checkdir=`eval echo "$"$dir`
if [ -L "$checkdir" ]; then
mkdir -p "$mysql_upgradedir"
cp -dT "$checkdir" "$mysql_upgradedir/$dir.link"
fi
checkdir=$(eval echo "$"$dir)
if [ -L "$checkdir" ]; then
# Use mkdir option 'Z' to create with correct SELinux context.
mkdir -pZ "$mysql_upgradedir"
cp -dT "$checkdir" "$mysql_upgradedir/$dir.link"
fi
done
# creating mysql home directory
if [ ! -d $mysql_datadir -a ! -L $mysql_datadir ]; then
mkdir $mysql_datadir
if [ ! -d $mysql_datadir ] && [ ! -L $mysql_datadir ]; then
# Use mkdir option 'Z' to create with correct SELinux context.
mkdir -Z $mysql_datadir
fi
# checking disc space
@ -191,7 +210,7 @@ fi
# The "set +e" is necessary as e.g. a ".journal" of a ext3 partition is
# not chgrp'able (#318435).
set +e
find $mysql_datadir ! -uid $(id -u mysql) -print0 | xargs -0 -r chown mysql
find $mysql_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql
find $mysql_datadir -follow -not -group mysql -print0 2>/dev/null \
| xargs -0 --no-run-if-empty chgrp mysql
set -e
@ -200,5 +219,3 @@ set -e
db_stop
#DEBHELPER#
exit 0

8
debian/mariadb-server-10.5.prerm

@ -1,10 +1,4 @@
#!/bin/bash
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
#DEBHELPER#
Loading…
Cancel
Save