3
# summary of how this script can be called:
4
# * <new-preinst> install
5
# * <new-preinst> install <old-version>
6
# * <new-preinst> upgrade <old-version>
7
# * <old-preinst> abort-upgrade <new-version>
10
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
11
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
13
export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
15
# Try to stop the server in a sane way. If it does not success let the admin
16
# do it himself. No database directories should be removed while the server
17
# is running! Another mysqld in e.g. a different chroot is fine for us.
19
if [ ! -x /etc/init.d/mysql ]; then return; fi
22
if [ -x /usr/sbin/invoke-rc.d ]; then
23
cmd="invoke-rc.d mysql stop"
25
cmd="/etc/init.d/mysql stop"
31
# 0=ok, 100=no init script (fresh install)
32
if [ "$errno" != 0 -a "$errno" != 100 ]; then
33
echo "${cmd/ */} returned $errno" 1>&2
34
echo "There is a MySQL server running, but we failed in our attempts to stop it." 1>&2
35
echo "Stop it yourself and try again!" 1>&2
41
if [ ! -x /etc/init.d/mysql ]; then return; fi
44
if [ -x /usr/sbin/invoke-rc.d ]; then
45
cmd="invoke-rc.d mysql start"
47
cmd="/etc/init.d/mysql start"
53
##### here's a bunch of helper functions for converting database formats ######
56
/usr/sbin/mysqld --print-defaults \
64
mytmp=`mktemp -d -t mysql-ISAM-convert.XXXXXX`
65
cvt_log="$mytmp/conversion.log"
66
if [ ! -d "$mytmp" ]; then
67
echo "can't create temporary directory, oh well." >&2
73
cvt_socket=${mytmp}/mysql.sock
75
cvt_mysqld="mysqld --skip-grant-tables --skip-networking --socket $cvt_socket"
76
cvt_mysql="mysql --socket $cvt_socket"
77
cvt_mysqladmin="mysqladmin --socket $cvt_socket"
81
echo fetching database list ... >&2
82
$cvt_mysql -e 'show databases' | sed -n -e '2,$p'
86
echo querying tables in $1 ... >&2
87
$cvt_mysql $1 -e 'show table status' | sed -n -e '2,$p' | \
88
cut -f 1,2 | grep -w 'ISAM$' | cut -f 1
92
echo converting $1.$2 ... >&2
93
$cvt_mysql $1 -e "alter table $2 type=MyISAM"
96
cvt_wait_for_server(){
98
echo -n waiting for server startup.. >&2
99
while ! $cvt_mysql </dev/null >/dev/null 2>&1; do
103
if [ -f $mytmp/mysql.done ]; then
104
echo "sorry... looks like the server crashed :(" >&2
106
elif [ "$count" = "...................." ]; then
107
echo "sorry... looks like the server didn't start :(" >&2
116
echo -n waiting for server shutdown.. >&2
117
while [ ! -f $mytmp/mysql.done ]; do
121
if [ "$count" = "...................." ]; then
122
echo "hrm... guess it never started?" >&2
132
# kill any mysqld child processes left over. there *shouldn't* be any,
133
# but let's not take chances with that
134
mysql_kids=`ps o 'pid command' --ppid $$ | grep -E '^[[:digit:]]+ mysqld ' | cut -d' ' -f1`
135
if [ "$mysql_kids" ]; then
136
echo "strange, some mysql processes left around. killing them now." >&2
139
mysql_kids=`ps o 'pid command' --ppid $$ | grep -E '^[[:digit:]]+ mysqld ' | cut -d' ' -f1`
140
if [ "$mysql_kids" ]; then
141
echo "okay, they're really not getting the hint..." >&2
147
################################ main() ##########################
149
# test if upgrading from non conffile state
150
if [ "$1" = "upgrade" ] && [ -x /usr/sbin/mysqld ]; then
151
cvt_datadir=`cvt_get_param datadir`
152
# test for ISAM tables, which we must convert NOW
153
if [ -n "`find $cvt_datadir -name '*.ISM' 2>/dev/null`" ]; then
154
pidfile=`cvt_get_param pid-file`
155
if [ "$pidfile" ] && [ -f "$pidfile" ]; then
156
server_pid=`cat $pidfile`
157
if [ "$server_pid" ] && ps $server_pid >/dev/null 2>&1; then
166
----------------------------------------
167
WARNING WARNING WARNING
168
----------------------------------------
170
It has been detected that are are using ISAM format on some of your
171
mysql database tables. This format has been deprecated and no longer
172
supported. to prevent these databases from essentially disappearing,
173
an attempt at format conversion will now be made. please check after
174
your upgrade that all tables are present and accounted for.
176
apologies for the noise, but we thought you'd appreciate it :)
178
----------------------------------------
179
WARNING WARNING WARNING
180
----------------------------------------
183
($cvt_mysqld >$cvt_log 2>&1; touch $mytmp/mysql.done ) &
185
if cvt_wait_for_server; then
186
dbs=`cvt_get_databases`
188
tables=`cvt_get_tables $db`
189
for tbl in $tables; do
190
cvt_convert_table $db $tbl
197
echo shutting down server... >&2
198
$cvt_mysqladmin shutdown
201
if [ ! "$cvt_error" = "yes" ]; then
204
echo "you might want to look in $mytmp..." >&2
207
if [ "$server_running" ]; then