1
1
#! /bin/bash
2
2
set -e
3
3
4
+ # shellcheck source=/dev/null
4
5
. /usr/share/debconf/confmodule
5
6
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
+
7
13
${DEBIAN_SCRIPT_TRACE: + echo " #42#DEBUG# RUNNING $0 $* " 1>&2 }
8
14
9
15
export PATH=$PATH :/sbin:/usr/sbin:/bin:/usr/bin
@@ -21,7 +27,9 @@ case "$1" in
21
27
# and because changed configuration options should take effect immediately.
22
28
# In case the server wasn't running at all it should be ok if the stop
23
29
# 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
25
33
26
34
# An existing /etc/init.d/mysql might be on the system if there was a
27
35
# previous MySQL or MariaDB installation, since /etc/init.d files are
@@ -61,21 +69,26 @@ case "$1" in
61
69
# If the following symlink exists, it is a preserved copy the old data dir
62
70
# created by the preinst script during a upgrade that would have otherwise
63
71
# 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
65
74
66
- if [ " $dir " = " DATADIR" ]; then
75
+ if [ " $dir " = " DATADIR" ]
76
+ then
67
77
targetdir=$mysql_datadir
68
78
else
69
79
targetdir=$mysql_logdir
70
80
fi
71
81
72
82
savelink=" $mysql_upgradedir /$dir .link"
73
- if [ -L " $savelink " ]; then
83
+ if [ -L " $savelink " ]
84
+ then
74
85
# If the targetdir was a symlink before we upgraded it is supposed
75
86
# to be either still be present or not existing anymore now.
76
- if [ -L " $targetdir " ]; then
87
+ if [ -L " $targetdir " ]
88
+ then
77
89
rm " $savelink "
78
- elif [ ! -d " $targetdir " ]; then
90
+ elif [ ! -d " $targetdir " ]
91
+ then
79
92
mv " $savelink " " $targetdir "
80
93
else
81
94
# this should never even happen, but just in case...
@@ -97,7 +110,7 @@ this all away.
97
110
EOF
98
111
fi
99
112
fi
100
- rmdir $mysql_upgradedir 2> /dev/null || true
113
+ rmdir $mysql_upgradedir 2> /dev/null || true
101
114
102
115
done
103
116
@@ -109,17 +122,29 @@ EOF
109
122
# This direct update is needed to enable an authentication mechanism to
110
123
# perform mariadb-upgrade, (MDEV-22678). To keep the impact minimal, we
111
124
# 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
116
132
fi
117
133
118
134
# Ensure the existence and right permissions for the database and
119
135
# 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
123
148
# When creating an ext3 jounal on an already mounted filesystem like e.g.
124
149
# /var/lib/mysql, you get a .journal file that is not modifiable by chown.
125
150
# The mysql_statedir must not be writable by the mysql user under any
168
193
# Debian: can safely run on upgrades with existing databases
169
194
set +e
170
195
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
173
198
set -e
174
199
175
200
# On new installations root user can connect via unix_socket.
@@ -180,26 +205,30 @@ EOF
180
205
# --defaults-file option for tools (for the sake of upgrades)
181
206
# and thus need /etc/mysql/debian.cnf to exist, even if it's empty.
182
207
# 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
185
211
install -o 0 -g 0 -m 0755 -d $mysql_cfgdir
186
212
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
203
232
fi
204
233
# Keep it only root-readable, as it always was
205
234
chown 0:0 $dc
212
241
# on by default) to work both to disable a default profile, and to keep
213
242
# any profile installed and maintained by users themselves.
214
243
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
217
248
apparmor_parser -r " $profile " || true
218
249
else
219
250
echo " /usr/sbin/mariadbd { }" | apparmor_parser --remove 2> /dev/null || true
@@ -225,24 +256,24 @@ EOF
225
256
# Note that file cannot be empty, otherwise systemd version in Ubuntu Bionic
226
257
# will think the service is masked
227
258
echo " # empty placeholder" > /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
228
-
229
- ;;
259
+ ;;
230
260
231
261
abort-upgrade|abort-remove|abort-configure)
232
- ;;
262
+ ;;
233
263
234
264
triggered)
235
- if [ -d /run/systemd/system ]; then
265
+ if [ -d /run/systemd/system ]
266
+ then
236
267
systemctl --system daemon-reload
237
268
else
238
269
invoke-rc.d mariadb restart
239
270
fi
240
- ;;
271
+ ;;
241
272
242
273
* )
243
274
echo " postinst called with unknown argument '$1 '" 1>&2
244
275
exit 1
245
- ;;
276
+ ;;
246
277
esac
247
278
248
279
db_stop # in case invoke fails
@@ -252,19 +283,23 @@ db_stop # in case invoke fails
252
283
# systemctl. If we upgrade from MySQL mysql.service may be masked, which also
253
284
# means init.d script is disabled. Unmask mysql service explicitly.
254
285
# 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
256
288
deb-systemd-helper unmask mysql.service > /dev/null
257
289
fi
258
290
259
291
# DEBHELPER#
260
292
261
293
# 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
270
305
fi
0 commit comments