11#! /bin/bash
22set -e
33
4+ # shellcheck source=/dev/null
45. /usr/share/debconf/confmodule
56
6- if [ -n " $DEBIAN_SCRIPT_DEBUG " ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
7+ if [ -n " $DEBIAN_SCRIPT_DEBUG " ]
8+ then
9+ set -v -x
10+ DEBIAN_SCRIPT_TRACE=1
11+ fi
12+
713${DEBIAN_SCRIPT_TRACE: + echo " #42#DEBUG# RUNNING $0 $* " 1>&2 }
814
915export PATH=$PATH :/sbin:/usr/sbin:/bin:/usr/bin
@@ -21,7 +27,9 @@ case "$1" in
2127 # and because changed configuration options should take effect immediately.
2228 # In case the server wasn't running at all it should be ok if the stop
2329 # script fails. I can't tell at this point because of the cleaned /run.
24- set +e; invoke-rc.d mariadb stop; set -e
30+ set +e
31+ invoke-rc.d mariadb stop
32+ set -e
2533
2634 # An existing /etc/init.d/mysql might be on the system if there was a
2735 # previous MySQL or MariaDB installation, since /etc/init.d files are
@@ -61,21 +69,26 @@ case "$1" in
6169 # If the following symlink exists, it is a preserved copy the old data dir
6270 # created by the preinst script during a upgrade that would have otherwise
6371 # been replaced by an empty mysql dir. This should restore it.
64- for dir in DATADIR LOGDIR; do
72+ for dir in DATADIR LOGDIR
73+ do
6574
66- if [ " $dir " = " DATADIR" ]; then
75+ if [ " $dir " = " DATADIR" ]
76+ then
6777 targetdir=$mysql_datadir
6878 else
6979 targetdir=$mysql_logdir
7080 fi
7181
7282 savelink=" $mysql_upgradedir /$dir .link"
73- if [ -L " $savelink " ]; then
83+ if [ -L " $savelink " ]
84+ then
7485 # If the targetdir was a symlink before we upgraded it is supposed
7586 # to be either still be present or not existing anymore now.
76- if [ -L " $targetdir " ]; then
87+ if [ -L " $targetdir " ]
88+ then
7789 rm " $savelink "
78- elif [ ! -d " $targetdir " ]; then
90+ elif [ ! -d " $targetdir " ]
91+ then
7992 mv " $savelink " " $targetdir "
8093 else
8194 # this should never even happen, but just in case...
@@ -97,7 +110,7 @@ this all away.
97110EOF
98111 fi
99112 fi
100- rmdir $mysql_upgradedir 2> /dev/null || true
113+ rmdir $mysql_upgradedir 2> /dev/null || true
101114
102115 done
103116
@@ -109,17 +122,29 @@ EOF
109122 # This direct update is needed to enable an authentication mechanism to
110123 # perform mariadb-upgrade, (MDEV-22678). To keep the impact minimal, we
111124 # skip innodb and set key-buffer-size to 0 as it isn't reused.
112- if [ -f " $mysql_datadir " /auto.cnf ] && [ -f " $mysql_datadir " /mysql/user.MYD ] &&
113- [ ! lsof -nt " $mysql_datadir " /mysql/user.MYD > /dev/null ] && [ ! -f " $mysql_datadir " /undo_001 ]; then
114- echo " UPDATE mysql.user SET plugin='unix_socket' WHERE plugin='auth_socket';" |
115- mariadbd --skip-innodb --key_buffer_size=0 --default-storage-engine=MyISAM --bootstrap 2> /dev/null
125+ if [ -f " $mysql_datadir /auto.cnf" ] &&
126+ [ -f " $mysql_datadir /mysql/user.MYD" ] &&
127+ ! lsof -nt " $mysql_datadir " /mysql/user.MYD > /dev/null &&
128+ [ ! -f " $mysql_datadir /undo_001" ]
129+ then
130+ echo " UPDATE mysql.user SET plugin='unix_socket' WHERE plugin='auth_socket';" |
131+ mariadbd --skip-innodb --key_buffer_size=0 --default-storage-engine=MyISAM --bootstrap 2> /dev/null
116132 fi
117133
118134 # Ensure the existence and right permissions for the database and
119135 # log files. Use mkdir option 'Z' to create with correct SELinux context.
120- if [ ! -d " $mysql_statedir " ] && [ ! -L " $mysql_statedir " ]; then mkdir -Z " $mysql_statedir " ; fi
121- if [ ! -d " $mysql_datadir " ] && [ ! -L " $mysql_datadir " ]; then mkdir -Z " $mysql_datadir " ; fi
122- if [ ! -d " $mysql_logdir " ] && [ ! -L " $mysql_logdir " ]; then mkdir -Z " $mysql_logdir " ; fi
136+ if [ ! -d " $mysql_statedir " ] && [ ! -L " $mysql_statedir " ]
137+ then
138+ mkdir -Z " $mysql_statedir "
139+ fi
140+ if [ ! -d " $mysql_datadir " ] && [ ! -L " $mysql_datadir " ]
141+ then
142+ mkdir -Z " $mysql_datadir "
143+ fi
144+ if [ ! -d " $mysql_logdir " ] && [ ! -L " $mysql_logdir " ]
145+ then
146+ mkdir -Z " $mysql_logdir "
147+ fi
123148 # When creating an ext3 jounal on an already mounted filesystem like e.g.
124149 # /var/lib/mysql, you get a .journal file that is not modifiable by chown.
125150 # The mysql_statedir must not be writable by the mysql user under any
168193 # Debian: can safely run on upgrades with existing databases
169194 set +e
170195 bash /usr/bin/mariadb-install-db --rpm --cross-bootstrap --user=mysql \
171- --disable-log-bin --skip-test-db 2>&1 | \
172- $ERR_LOGGER
196+ --disable-log-bin --skip-test-db 2>&1 | \
197+ $ERR_LOGGER
173198 set -e
174199
175200 # On new installations root user can connect via unix_socket.
@@ -180,26 +205,30 @@ EOF
180205 # --defaults-file option for tools (for the sake of upgrades)
181206 # and thus need /etc/mysql/debian.cnf to exist, even if it's empty.
182207 # In the long run the goal is to obsolete this file.
183- dc=$mysql_cfgdir /debian.cnf;
184- if [ ! -d " $mysql_cfgdir " ]; then
208+ dc=" $mysql_cfgdir /debian.cnf"
209+ if [ ! -d " $mysql_cfgdir " ]
210+ then
185211 install -o 0 -g 0 -m 0755 -d $mysql_cfgdir
186212 fi
187- if [ ! -e " $dc " ]; then
188- cat /dev/null > $dc
189- echo " # THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE." >> $dc
190- echo " # This file exists only for backwards compatibility for" >> $dc
191- echo " # tools that run '--defaults-file=/etc/mysql/debian.cnf'" >> $dc
192- echo " # and have root level access to the local filesystem." >> $dc
193- echo " # With those permissions one can run 'mariadb' directly" >> $dc
194- echo " # anyway thanks to unix socket authentication and hence" >> $dc
195- echo " # this file is useless. See package README for more info." >> $dc
196- echo " [client]" >> $dc
197- echo " host = localhost" >> $dc
198- echo " user = root" >> $dc
199- echo " [mysql_upgrade]" >> $dc
200- echo " host = localhost" >> $dc
201- echo " user = root" >> $dc
202- echo " # THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE." >> $dc
213+ if [ ! -e " $dc " ]
214+ then
215+ cat /dev/null > $dc
216+ {
217+ echo " # THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE." ;
218+ echo " # This file exists only for backwards compatibility for" ;
219+ echo " # tools that run '--defaults-file=/etc/mysql/debian.cnf'" ;
220+ echo " # and have root level access to the local filesystem." ;
221+ echo " # With those permissions one can run 'mariadb' directly" ;
222+ echo " # anyway thanks to unix socket authentication and hence" ;
223+ echo " # this file is useless. See package README for more info." ;
224+ echo " [client]" ;
225+ echo " host = localhost" ;
226+ echo " user = root" ;
227+ echo " [mysql_upgrade]" ;
228+ echo " host = localhost" ;
229+ echo " user = root" ;
230+ echo " # THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE." ;
231+ } >> $dc
203232 fi
204233 # Keep it only root-readable, as it always was
205234 chown 0:0 $dc
212241 # on by default) to work both to disable a default profile, and to keep
213242 # any profile installed and maintained by users themselves.
214243 profile=" /etc/apparmor.d/usr.sbin.mariadbd"
215- if [ -f " $profile " ] && aa-status --enabled 2> /dev/null; then
216- if grep -q /usr/sbin/mariadbd " $profile " 2> /dev/null ; then
244+ if [ -f " $profile " ] && aa-status --enabled 2> /dev/null
245+ then
246+ if grep -q /usr/sbin/mariadbd " $profile " 2> /dev/null
247+ then
217248 apparmor_parser -r " $profile " || true
218249 else
219250 echo " /usr/sbin/mariadbd { }" | apparmor_parser --remove 2> /dev/null || true
@@ -225,24 +256,24 @@ EOF
225256 # Note that file cannot be empty, otherwise systemd version in Ubuntu Bionic
226257 # will think the service is masked
227258 echo " # empty placeholder" > /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
228-
229- ;;
259+ ;;
230260
231261 abort-upgrade|abort-remove|abort-configure)
232- ;;
262+ ;;
233263
234264 triggered)
235- if [ -d /run/systemd/system ]; then
265+ if [ -d /run/systemd/system ]
266+ then
236267 systemctl --system daemon-reload
237268 else
238269 invoke-rc.d mariadb restart
239270 fi
240- ;;
271+ ;;
241272
242273 * )
243274 echo " postinst called with unknown argument '$1 '" 1>&2
244275 exit 1
245- ;;
276+ ;;
246277esac
247278
248279db_stop # in case invoke fails
@@ -252,19 +283,23 @@ db_stop # in case invoke fails
252283# systemctl. If we upgrade from MySQL mysql.service may be masked, which also
253284# means init.d script is disabled. Unmask mysql service explicitly.
254285# Check first that the command exists, to avoid emitting any warning messages.
255- if [ -x " $( command -v deb-systemd-helper) " ]; then
286+ if [ -x " $( command -v deb-systemd-helper) " ]
287+ then
256288 deb-systemd-helper unmask mysql.service > /dev/null
257289fi
258290
259291# DEBHELPER#
260292
261293# Modified dh_systemd_start snippet that's not added automatically
262- if [ -d /run/systemd/system ]; then
263- systemctl --system daemon-reload > /dev/null || true
264- deb-systemd-invoke start mariadb.service > /dev/null || true
265- # Modified dh_installinit snippet to only run with sysvinit
266- elif [ -x " /etc/init.d/mariadb" ]; then
267- if [ " $1 " = " configure" ] || [ " $1 " = " abort-upgrade" ]; then
268- invoke-rc.d mariadb start || exit $?
269- fi
294+ if [ -d /run/systemd/system ]
295+ then
296+ systemctl --system daemon-reload > /dev/null || true
297+ deb-systemd-invoke start mariadb.service > /dev/null || true
298+ # Modified dh_installinit snippet to only run with sysvinit
299+ elif [ -x " /etc/init.d/mariadb" ]
300+ then
301+ if [ " $1 " = " configure" ] || [ " $1 " = " abort-upgrade" ]
302+ then
303+ invoke-rc.d mariadb start || exit $?
304+ fi
270305fi
0 commit comments