summaryrefslogtreecommitdiff
path: root/debian/mariadb-server.preinst
diff options
context:
space:
mode:
Diffstat (limited to 'debian/mariadb-server.preinst')
-rw-r--r--debian/mariadb-server.preinst107
1 files changed, 61 insertions, 46 deletions
diff --git a/debian/mariadb-server.preinst b/debian/mariadb-server.preinst
index 2204d230bdd..e92f97a618c 100644
--- a/debian/mariadb-server.preinst
+++ b/debian/mariadb-server.preinst
@@ -7,14 +7,20 @@
# * <old-preinst> abort-upgrade <new-version>
#
+# shellcheck source=/dev/null
. /usr/share/debconf/confmodule
# 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/"
+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 }
export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
@@ -25,25 +31,29 @@ mysql_upgradedir=/var/lib/mysql-upgrade
# do it himself. No database directories should be removed while the server
# is running! Another mariadbd in e.g. a different chroot is fine for us.
stop_server() {
- # Return immediately if there are no mysqld processes running on a host
- # (leave containerized processes with the same name in other namespaces)
- # as there is no point in trying to shutdown in that case.
- if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null; then return; fi
-
- set +e
- invoke-rc.d mariadb stop
- invoke-rc.d mysql stop # Backwards compatibility
- errno=$?
- set -e
-
- # systemctl could emit exit code 100=no init script (fresh install)
- if [ "$errno" != 0 -a "$errno" != 100 ]; then
- echo "Attempt to stop MariaDB/MySQL server returned exitcode $errno" 1>&2
- echo "There is a MariaDB/MySQL server running, but we failed in our attempts to stop it." 1>&2
- echo "Stop it yourself and try again!" 1>&2
- db_stop
- exit 1
- fi
+ # Return immediately if there are no mysqld processes running on a host
+ # (leave containerized processes with the same name in other namespaces)
+ # as there is no point in trying to shutdown in that case.
+ if ! pgrep -x --nslist pid --ns $$ "mysqld|mariadbd" > /dev/null
+ then
+ return
+ fi
+
+ set +e
+ invoke-rc.d mariadb stop
+ invoke-rc.d mysql stop # Backwards compatibility
+ errno=$?
+ set -e
+
+ # systemctl could emit exit code 100=no init script (fresh install)
+ if [ "$errno" != 0 ] && [ "$errno" != 100 ]
+ then
+ echo "Attempt to stop MariaDB/MySQL server returned exitcode $errno" 1>&2
+ echo "There is a MariaDB/MySQL server running, but we failed in our attempts to stop it." 1>&2
+ echo "Stop it yourself and try again!" 1>&2
+ db_stop
+ exit 1
+ fi
}
################################ main() ##########################
@@ -56,7 +66,7 @@ max_upgradeable_version=5.7
# Check if a flag file is found that indicates a previous MariaDB or MySQL
# version was installed. If multiple flags are found, check which one was
# the biggest version number.
-for flag in $mysql_datadir/debian-*.flag
+for flag in "$mysql_datadir"/debian-*.flag
do
# The for loop leaves $flag as the query string if there are no results,
@@ -91,7 +101,7 @@ done
# Downgrade is detected if the flag version is bigger than $this_version
# (e.g. 10.1 > 10.0) or the flag version is smaller than 10.0 but bigger
# than $max_upgradeable_version.
-if [ ! -z "$found_version" ]
+if [ -n "$found_version" ]
then
# MySQL 8.0 in Ubuntu has a bug in packaging and the file is name wrongly
@@ -111,7 +121,7 @@ then
fi
if dpkg --compare-versions "$found_version" '>>' "$max_upgradeable_version" \
- && dpkg --compare-versions "$found_version" '<<' "10.0"
+ && dpkg --compare-versions "$found_version" '<<' "10.0"
then
downgrade_detected=true
fi
@@ -133,7 +143,7 @@ fi
# Don't abort dpkg if downgrade is detected (as was done previously).
# Instead simply move the old datadir and create a new for this_version.
-if [ ! -z "$downgrade_detected" ]
+if [ -n "$downgrade_detected" ]
then
db_input critical "mariadb-server/old_data_directory_saved" || true
db_go
@@ -154,7 +164,8 @@ 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
@@ -169,23 +180,25 @@ fi
#
# creating mysql group if he isn't already there
-if ! getent group mysql >/dev/null; then
- # Adding system group: mysql.
- addgroup --system mysql >/dev/null
+if ! getent group mysql >/dev/null
+then
+ # Adding system group: mysql.
+ addgroup --system mysql >/dev/null
fi
# creating mysql user if he isn't already there
-if ! getent passwd mysql >/dev/null; then
- # Adding system user: mysql.
- adduser \
- --system \
- --disabled-login \
- --ingroup mysql \
- --no-create-home \
- --home /nonexistent \
- --gecos "MySQL Server" \
- --shell /bin/false \
- mysql >/dev/null
+if ! getent passwd mysql >/dev/null
+then
+ # Adding system user: mysql.
+ adduser \
+ --system \
+ --disabled-login \
+ --ingroup mysql \
+ --no-create-home \
+ --home /nonexistent \
+ --gecos "MySQL Server" \
+ --shell /bin/false \
+ mysql >/dev/null
fi
# end of NIS tolerance zone
@@ -193,7 +206,8 @@ 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
+for dir in DATADIR LOGDIR
+do
checkdir=$(eval echo "$"$dir)
if [ -L "$checkdir" ]; then
# Use mkdir option 'Z' to create with correct SELinux context.
@@ -203,15 +217,17 @@ for dir in DATADIR LOGDIR; do
done
# creating mysql home directory
-if [ ! -d $mysql_datadir ] && [ ! -L $mysql_datadir ]; then
- # Use mkdir option 'Z' to create with correct SELinux context.
+if [ ! -d $mysql_datadir ] && [ ! -L $mysql_datadir ]
+then
+ # Use mkdir option 'Z' to create with correct SELinux context.
mkdir -Z $mysql_datadir
fi
# As preset blocksize of GNU df is 1024 then available bytes is $df_available_blocks * 1024
# 4096 blocks is then lower than 4 MB
df_available_blocks=`LC_ALL=C BLOCKSIZE= df --output=avail "$datadir" | tail -n 1`
-if [ "$df_available_blocks" -lt "4096" ]; then
+if [ "$df_available_blocks" -lt "4096" ]
+then
echo "ERROR: There's not enough space in $mysql_datadir/" 1>&2
db_stop
exit 1
@@ -230,7 +246,6 @@ find $mysql_datadir -follow -not -group mysql -print0 2>/dev/null \
| xargs -0 --no-run-if-empty chgrp mysql
set -e
-
db_stop
#DEBHELPER#