Commit 8febdfa3 authored by Tuukka Pasanen's avatar Tuukka Pasanen Committed by Daniel Black

MDEV-30952: Fix shellcheck problems on Debian scripts

Commit fixes several ShellCheck found problems in Debian
Pre- and Postscripts.

Debian script mariadb-server-10.6.postrm contains shellcheck
Fixed problems are:
  https://www.shellcheck.net/wiki/SC2166 -- Prefer [ p ] && [ q ] as [ p -a q...
  https://www.shellcheck.net/wiki/SC2006 -- Use $(...) notation instead of le...
  https://www.shellcheck.net/wiki/SC1091 -- Not following: /usr/share/debconf...

Debian script mariadb-server-10.6.postinst contains shellcheck
Fixed problems are:
  https://www.shellcheck.net/wiki/SC2129 -- Consider using { cmd1; cmd2; } >>...
  https://www.shellcheck.net/wiki/SC1091 -- Not following: /usr/share/debconf...
  https://www.shellcheck.net/wiki/SC1072 -- Expected test to end here (don't ...
  https://www.shellcheck.net/wiki/SC1073 -- Couldn't parse this test expressi...
  https://www.shellcheck.net/wiki/SC1009 -- The mentioned syntax error was in...

Debian script mariadb-server-10.6.preinst contains shellcheck
Fixed problems are:
  https://www.shellcheck.net/wiki/SC2231 -- Quote expansions in this for loop...
  https://www.shellcheck.net/wiki/SC2166 -- Prefer [ p ] && [ q ] as [ p -a q...
  https://www.shellcheck.net/wiki/SC2001 -- See if you can use ${variable//se...
  https://www.shellcheck.net/wiki/SC1091 -- Not following: /usr/share/debconf...
  https://www.shellcheck.net/wiki/SC1007 -- Remove space after = if trying to...
parent 7cbb45d1
#!/bin/bash #!/bin/bash
set -e set -e
# shellcheck source=/dev/null
. /usr/share/debconf/confmodule . /usr/share/debconf/confmodule
# Automatically set version to ease maintenance of this file # Automatically set version to ease maintenance of this file
...@@ -112,8 +113,10 @@ EOF ...@@ -112,8 +113,10 @@ EOF
# This direct update is needed to enable an authentication mechanism to # This direct update is needed to enable an authentication mechanism to
# perform mariadb-upgrade, (MDEV-22678). To keep the impact minimal, we # 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. # skip innodb and set key-buffer-size to 0 as it isn't reused.
if [ -f "$mysql_datadir"/auto.cnf ] && [ -f "$mysql_datadir"/mysql/user.MYD ] && lsof -nt "$mysql_datadir"/mysql/user.MYD > /dev/null
[ ! lsof -nt "$mysql_datadir"/mysql/user.MYD > /dev/null ] && [ ! -f "$mysql_datadir"/undo_001 ]; then lsof_rtn_code=$?
if [ -f "$mysql_datadir/auto.cnf" ] && [ -f "$mysql_datadir/mysql/user.MYD" ] &&
[ ! ${lsof_rtn_code} ] && [ ! -f "$mysql_datadir/undo_001" ]; then
echo "UPDATE mysql.user SET plugin='unix_socket' WHERE plugin='auth_socket';" | 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 mariadbd --skip-innodb --key_buffer_size=0 --default-storage-engine=MyISAM --bootstrap 2> /dev/null
fi fi
...@@ -189,20 +192,22 @@ EOF ...@@ -189,20 +192,22 @@ EOF
fi fi
if [ ! -e "$dc" ]; then if [ ! -e "$dc" ]; then
cat /dev/null > $dc cat /dev/null > $dc
echo "# THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE." >>$dc {
echo "# This file exists only for backwards compatibility for" >>$dc echo "# THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE.";
echo "# tools that run '--defaults-file=/etc/mysql/debian.cnf'" >>$dc echo "# This file exists only for backwards compatibility for";
echo "# and have root level access to the local filesystem." >>$dc echo "# tools that run '--defaults-file=/etc/mysql/debian.cnf'";
echo "# With those permissions one can run 'mariadb' directly" >>$dc echo "# and have root level access to the local filesystem.";
echo "# anyway thanks to unix socket authentication and hence" >>$dc echo "# With those permissions one can run 'mariadb' directly";
echo "# this file is useless. See package README for more info." >>$dc echo "# anyway thanks to unix socket authentication and hence";
echo "[client]" >>$dc echo "# this file is useless. See package README for more info.";
echo "host = localhost" >>$dc echo "[client]";
echo "user = root" >>$dc echo "host = localhost";
echo "[mysql_upgrade]" >>$dc echo "user = root";
echo "host = localhost" >>$dc echo "[mysql_upgrade]";
echo "user = root" >>$dc echo "host = localhost";
echo "# THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE." >>$dc echo "user = root";
echo "# THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE.";
} >> $dc
fi fi
# Keep it only root-readable, as it always was # Keep it only root-readable, as it always was
chown 0:0 $dc chown 0:0 $dc
......
#!/bin/bash #!/bin/bash
set -e set -e
# shellcheck source=/dev/null
. /usr/share/debconf/confmodule . /usr/share/debconf/confmodule
# Automatically set version to ease maintenance of this file # Automatically set version to ease maintenance of this file
...@@ -26,7 +27,7 @@ stop_server() { ...@@ -26,7 +27,7 @@ stop_server() {
set -e set -e
# systemctl could emit exit code 100=no init script (fresh install) # systemctl could emit exit code 100=no init script (fresh install)
if [ "$errno" != 0 -a "$errno" != 100 ]; then if [ "$errno" != 0 ] && [ "$errno" != 100 ]; then
echo "Attempt to stop MariaDB/MySQL server returned exitcode $errno" 1>&2 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 "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 echo "Stop it yourself and try again!" 1>&2
...@@ -38,7 +39,7 @@ stop_server() { ...@@ -38,7 +39,7 @@ stop_server() {
case "$1" in case "$1" in
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
if [ -n "`$MYADMIN ping 2>/dev/null`" ]; then if [ -n "$($MYADMIN ping 2>/dev/null)" ]; then
stop_server stop_server
sleep 2 sleep 2
fi fi
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
# * <old-preinst> abort-upgrade <new-version> # * <old-preinst> abort-upgrade <new-version>
# #
# shellcheck source=/dev/null
. /usr/share/debconf/confmodule . /usr/share/debconf/confmodule
# Automatically set version to ease maintenance of this file # Automatically set version to ease maintenance of this file
...@@ -40,7 +41,7 @@ stop_server() { ...@@ -40,7 +41,7 @@ stop_server() {
set -e set -e
# systemctl could emit exit code 100=no init script (fresh install) # systemctl could emit exit code 100=no init script (fresh install)
if [ "$errno" != 0 -a "$errno" != 100 ]; then if [ "$errno" != 0 ] && [ "$errno" != 100 ]; then
echo "Attempt to stop MariaDB/MySQL server returned exitcode $errno" 1>&2 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 "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 echo "Stop it yourself and try again!" 1>&2
...@@ -57,7 +58,7 @@ max_upgradeable_version=5.7 ...@@ -57,7 +58,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
# version was installed. If multiple flags are found, check which one was # version was installed. If multiple flags are found, check which one was
# the biggest version number. # the biggest version number.
for flag in $mysql_datadir/debian-*.flag for flag in "$mysql_datadir"/debian-*.flag
do 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,
...@@ -92,7 +93,7 @@ done ...@@ -92,7 +93,7 @@ done
# Downgrade is detected if the flag version is bigger than $this_version # 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 # (e.g. 10.1 > 10.0) or the flag version is smaller than 10.0 but bigger
# than $max_upgradeable_version. # than $max_upgradeable_version.
if [ ! -z "$found_version" ] if [ -n "$found_version" ]
then then
# MySQL 8.0 in Ubuntu has a bug in packaging and the file is name wrongly # MySQL 8.0 in Ubuntu has a bug in packaging and the file is name wrongly
...@@ -134,7 +135,7 @@ fi ...@@ -134,7 +135,7 @@ fi
# Don't abort dpkg if downgrade is detected (as was done previously). # 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. # Instead simply move the old datadir and create a new for this_version.
if [ ! -z "$downgrade_detected" ] if [ -n "$downgrade_detected" ]
then then
db_input critical "mariadb-server-$MAJOR_VER/old_data_directory_saved" || true db_input critical "mariadb-server-$MAJOR_VER/old_data_directory_saved" || true
db_go db_go
......
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