Commit 4e946b0f authored by Otto Kekäläinen's avatar Otto Kekäläinen Committed by Vicențiu-Marian Ciorbaru
parent 9ed7e967
#!/bin/bash -e #!/bin/bash
set -e
. /usr/share/debconf/confmodule . /usr/share/debconf/confmodule
...@@ -12,6 +13,7 @@ export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin ...@@ -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. # 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" 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 # This will make an error in a logged command immediately apparent by aborting
# the install, rather than failing silently and leaving a broken install. # the install, rather than failing silently and leaving a broken install.
set -o pipefail set -o pipefail
...@@ -31,7 +33,6 @@ case "$1" in ...@@ -31,7 +33,6 @@ case "$1" in
mysql_statedir=/usr/share/mysql mysql_statedir=/usr/share/mysql
mysql_datadir=/var/lib/mysql mysql_datadir=/var/lib/mysql
mysql_logdir=/var/log/mysql mysql_logdir=/var/log/mysql
mysql_rundir=/var/run/mysqld
mysql_cfgdir=/etc/mysql mysql_cfgdir=/etc/mysql
mysql_upgradedir=/var/lib/mysql-upgrade mysql_upgradedir=/var/lib/mysql-upgrade
...@@ -56,7 +57,7 @@ case "$1" in ...@@ -56,7 +57,7 @@ case "$1" in
mv "$savelink" "$targetdir" mv "$savelink" "$targetdir"
else else
# this should never even happen, but just in case... # 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 echo "this is very strange! see $mysql_tmp/README..." >&2
mv "$targetdir" "$mysql_tmp" mv "$targetdir" "$mysql_tmp"
cat << EOF > "$mysql_tmp/README" cat << EOF > "$mysql_tmp/README"
...@@ -79,17 +80,17 @@ EOF ...@@ -79,17 +80,17 @@ EOF
done done
# Ensure the existence and right permissions for the database and # Ensure the existence and right permissions for the database and
# log files. # log files. Use mkdir option 'Z' to create with correct SELinux context.
if [ ! -d "$mysql_statedir" -a ! -L "$mysql_statedir" ]; then mkdir "$mysql_statedir"; fi if [ ! -d "$mysql_statedir" ] && [ ! -L "$mysql_statedir" ]; then mkdir -Z "$mysql_statedir"; fi
if [ ! -d "$mysql_datadir" -a ! -L "$mysql_datadir" ]; then mkdir "$mysql_datadir" ; fi if [ ! -d "$mysql_datadir" ] && [ ! -L "$mysql_datadir" ]; then mkdir -Z "$mysql_datadir" ; fi
if [ ! -d "$mysql_logdir" -a ! -L "$mysql_logdir" ]; then mkdir "$mysql_logdir" ; 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. # 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. # /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 # The mysql_statedir must not be writable by the mysql user under any
# circumstances as it contains scripts that are executed by root. # circumstances as it contains scripts that are executed by root.
set +e set +e
chown -R 0:0 $mysql_statedir 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 chown -R mysql:adm $mysql_logdir
chmod 2750 $mysql_logdir chmod 2750 $mysql_logdir
set -e set -e
...@@ -105,7 +106,7 @@ EOF ...@@ -105,7 +106,7 @@ EOF
# Clean up old flags before setting new one # Clean up old flags before setting new one
rm -f $mysql_datadir/debian-*.flag rm -f $mysql_datadir/debian-*.flag
# Flag data dir to avoid downgrades # 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 :-( # initiate databases. Output is not allowed by debconf :-(
# This will fail if we are upgrading an existing database; in this case # This will fail if we are upgrading an existing database; in this case
...@@ -115,12 +116,12 @@ EOF ...@@ -115,12 +116,12 @@ EOF
# Debian: can safely run on upgrades with existing databases # Debian: can safely run on upgrades with existing databases
set +e set +e
bash /usr/bin/mysql_install_db --rpm --cross-bootstrap --user=mysql \ 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 $ERR_LOGGER
set -e set -e
# To avoid downgrades. # 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. # On new installations root user can connect via unix_socket.
# But on upgrades, scripts rely on debian-sys-maint user and # But on upgrades, scripts rely on debian-sys-maint user and
...@@ -130,6 +131,9 @@ EOF ...@@ -130,6 +131,9 @@ EOF
# --defaults-file option for tools (for the sake of upgrades) # --defaults-file option for tools (for the sake of upgrades)
# and thus need /etc/mysql/debian.cnf to exist, even if it's empty. # and thus need /etc/mysql/debian.cnf to exist, even if it's empty.
dc=$mysql_cfgdir/debian.cnf; 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 if [ ! -e "$dc" ]; then
cat /dev/null > $dc cat /dev/null > $dc
echo "# Automatically generated for Debian scripts. DO NOT TOUCH!" >>$dc echo "# Automatically generated for Debian scripts. DO NOT TOUCH!" >>$dc
...@@ -146,11 +150,11 @@ EOF ...@@ -146,11 +150,11 @@ EOF
# any profile installed and maintained by users themselves. # any profile installed and maintained by users themselves.
profile="/etc/apparmor.d/usr.sbin.mysqld" profile="/etc/apparmor.d/usr.sbin.mysqld"
if [ -f "$profile" ] && aa-status --enabled 2>/dev/null; then if [ -f "$profile" ] && aa-status --enabled 2>/dev/null; then
if grep -q /usr/sbin/mysqld "$profile" 2>/dev/null ; then if grep -q /usr/sbin/mysqld "$profile" 2>/dev/null ; then
apparmor_parser -r "$profile" || true apparmor_parser -r "$profile" || true
else else
echo "/usr/sbin/mysqld { }" | apparmor_parser --remove 2>/dev/null || true echo "/usr/sbin/mysqld { }" | apparmor_parser --remove 2>/dev/null || true
fi fi
fi fi
# copy out any mysqld_safe settings # copy out any mysqld_safe settings
...@@ -189,5 +193,3 @@ if [ -x "$(command -v deb-systemd-helper)" ]; then ...@@ -189,5 +193,3 @@ if [ -x "$(command -v deb-systemd-helper)" ]; then
fi fi
#DEBHELPER# #DEBHELPER#
exit 0
#!/bin/bash -e #!/bin/bash
set -e
. /usr/share/debconf/confmodule . /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 if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 } ${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
...@@ -37,17 +41,18 @@ case "$1" in ...@@ -37,17 +41,18 @@ case "$1" in
esac 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. # - 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 # we remove the mysql user only after all his owned files are purged
rm -f /var/log/mysql.{log,err}{,.0,.[1234567].gz} rm -f /var/log/mysql.{log,err}{,.0,.[1234567].gz}
rm -rf /var/log/mysql 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_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 if [ "$RET" = "true" ]; then
# never remove the debian.cnf when the databases are still existing # never remove the debian.cnf when the databases are still existing
# else we ran into big trouble on the next install! # 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 ...@@ -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 # directory with file system data. See #829491 for details and
# #608938 for potential mysql-server leftovers which erroneously # #608938 for potential mysql-server leftovers which erroneously
# had been renamed. # had been renamed.
find /var/lib/mysql -mindepth 1 \ # Attempt removal only if the directory hasn't already been removed
-not -path '*/lost+found/*' -not -name 'lost+found' \ # by dpkg to avoid failing on "No such file or directory" errors.
-not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \ if [ -d /var/lib/mysql ]
-delete then
# "|| true" still needed as rmdir still exits with non-zero if find /var/lib/mysql -mindepth 1 \
# /var/lib/mysql is a mount point -not -path '*/lost+found/*' -not -name 'lost+found' \
rmdir --ignore-fail-on-non-empty /var/lib/mysql || true -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 rm -rf /var/run/mysqld # this directory is created by the init script, don't leave behind
userdel mysql || true userdel mysql || true
fi fi
...@@ -70,5 +81,3 @@ if [ "$1" = "purge" -a ! \( -x /usr/sbin/mysqld -o -L /usr/sbin/mysqld \) ]; the ...@@ -70,5 +81,3 @@ if [ "$1" = "purge" -a ! \( -x /usr/sbin/mysqld -o -L /usr/sbin/mysqld \) ]; the
fi fi
#DEBHELPER# #DEBHELPER#
exit 0
...@@ -9,6 +9,14 @@ ...@@ -9,6 +9,14 @@
. /usr/share/debconf/confmodule . /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 if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 } ${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
...@@ -41,7 +49,7 @@ stop_server() { ...@@ -41,7 +49,7 @@ stop_server() {
################################ main() ########################## ################################ main() ##########################
this_version=10.5 this_version=$MAJOR_VER
max_upgradeable_version=5.7 max_upgradeable_version=5.7
# Check if a flag file is found that indicates a previous MariaDB or MySQL # Check if a flag file is found that indicates a previous MariaDB or MySQL
...@@ -53,12 +61,12 @@ do ...@@ -53,12 +61,12 @@ do
# The for loop leaves $flag as the query string if there are no results, # 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 # so the check below is needed to stop further processing when there are
# no real results. # no real results.
if [ $flag = "$mysql_datadir/debian-*.flag" ] if [ "$flag" = "$mysql_datadir/debian-*.flag" ]
then then
break break
fi 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 # Initialize value if empty
if [ -z "$found_version" ] if [ -z "$found_version" ]
...@@ -85,6 +93,15 @@ done ...@@ -85,6 +93,15 @@ done
if [ ! -z "$found_version" ] if [ ! -z "$found_version" ]
then 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" echo "$mysql_datadir: found previous version $found_version"
if dpkg --compare-versions "$found_version" '>>' "$this_version" if dpkg --compare-versions "$found_version" '>>' "$this_version"
...@@ -105,17 +122,17 @@ fi ...@@ -105,17 +122,17 @@ fi
# Instead simply move the old datadir and create a new for this_version. # Instead simply move the old datadir and create a new for this_version.
if [ ! -z "$downgrade_detected" ] if [ ! -z "$downgrade_detected" ]
then 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 db_go
echo "The file $mysql_datadir/debian-$found_version.flag indicates a" 1>&2 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 "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 "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 "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 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 # Also move away the old debian.cnf file that included credentials that are
# no longer valid # 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 fi
# to be sure # to be sure
...@@ -124,7 +141,7 @@ stop_server ...@@ -124,7 +141,7 @@ stop_server
# If we use NIS then errors should be tolerated. It's up to the # If we use NIS then errors should be tolerated. It's up to the
# user to ensure that the mysql user is correctly setup. # user to ensure that the mysql user is correctly setup.
# Beware that there are two ypwhich one of them needs the 2>/dev/null! # 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 set +e
fi fi
...@@ -164,16 +181,18 @@ set -e ...@@ -164,16 +181,18 @@ set -e
# if there's a symlink, let's store where it's pointing, because otherwise # if there's a symlink, let's store where it's pointing, because otherwise
# it's going to be lost in some situations # it's going to be lost in some situations
for dir in DATADIR LOGDIR; do for dir in DATADIR LOGDIR; do
checkdir=`eval echo "$"$dir` checkdir=$(eval echo "$"$dir)
if [ -L "$checkdir" ]; then if [ -L "$checkdir" ]; then
mkdir -p "$mysql_upgradedir" # Use mkdir option 'Z' to create with correct SELinux context.
cp -dT "$checkdir" "$mysql_upgradedir/$dir.link" mkdir -pZ "$mysql_upgradedir"
fi cp -dT "$checkdir" "$mysql_upgradedir/$dir.link"
fi
done done
# creating mysql home directory # creating mysql home directory
if [ ! -d $mysql_datadir -a ! -L $mysql_datadir ]; then if [ ! -d $mysql_datadir ] && [ ! -L $mysql_datadir ]; then
mkdir $mysql_datadir # Use mkdir option 'Z' to create with correct SELinux context.
mkdir -Z $mysql_datadir
fi fi
# checking disc space # checking disc space
...@@ -191,7 +210,7 @@ fi ...@@ -191,7 +210,7 @@ fi
# The "set +e" is necessary as e.g. a ".journal" of a ext3 partition is # The "set +e" is necessary as e.g. a ".journal" of a ext3 partition is
# not chgrp'able (#318435). # not chgrp'able (#318435).
set +e 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 \ find $mysql_datadir -follow -not -group mysql -print0 2>/dev/null \
| xargs -0 --no-run-if-empty chgrp mysql | xargs -0 --no-run-if-empty chgrp mysql
set -e set -e
...@@ -200,5 +219,3 @@ set -e ...@@ -200,5 +219,3 @@ set -e
db_stop db_stop
#DEBHELPER# #DEBHELPER#
exit 0
#!/bin/bash #!/bin/sh
set -e 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# #DEBHELPER#
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment