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
40
##### here's a bunch of helper functions for converting database formats ######
43
/usr/sbin/mysqld --print-defaults \
51
mytmp=`mktemp -d -t mysql-ISAM-convert.XXXXXX`
52
cvt_log="$mytmp/conversion.log"
53
if [ ! -d "$mytmp" ]; then
54
echo "can't create temporary directory, oh well." >&2
60
cvt_socket=${mytmp}/mysql.sock
62
cvt_mysqld="mysqld --skip-grant-tables --skip-networking --socket $cvt_socket"
63
cvt_mysql="mysql --socket $cvt_socket"
64
cvt_mysqladmin="mysqladmin --socket $cvt_socket"
68
echo fetching database list ... >&2
69
$cvt_mysql -e 'show databases' | sed -n -e '2,$p'
73
echo querying tables in $1 ... >&2
74
$cvt_mysql $1 -e 'show table status' | sed -n -e '2,$p' | \
75
cut -f 1,2 | grep -w 'ISAM$' | cut -f 1
79
echo converting $1.$2 ... >&2
80
$cvt_mysql $1 -e "alter table $2 type=MyISAM"
83
cvt_wait_for_server(){
85
echo -n waiting for server startup.. >&2
86
while ! $cvt_mysql </dev/null >/dev/null 2>&1; do
90
if [ -f $mytmp/mysql.done ]; then
91
echo "sorry... looks like the server crashed :(" >&2
93
elif [ "$count" = "...................." ]; then
94
echo "sorry... looks like the server didn't start :(" >&2
103
echo -n waiting for server shutdown.. >&2
104
while [ ! -f $mytmp/mysql.done ]; do
108
if [ "$count" = "...................." ]; then
109
echo "hrm... guess it never started?" >&2
119
# kill any mysqld child processes left over. there *shouldn't* be any,
120
# but let's not take chances with that
121
mysql_kids=`ps o 'pid command' --ppid $$ | grep -E '^[[:digit:]]+ mysqld ' | cut -d' ' -f1`
122
if [ "$mysql_kids" ]; then
123
echo "strange, some mysql processes left around. killing them now." >&2
126
mysql_kids=`ps o 'pid command' --ppid $$ | grep -E '^[[:digit:]]+ mysqld ' | cut -d' ' -f1`
127
if [ "$mysql_kids" ]; then
128
echo "okay, they're really not getting the hint..." >&2
134
################################ main() ##########################
139
# test if upgrading from non conffile state
140
if [ "$1" = "upgrade" ] && [ -x /usr/sbin/mysqld ]; then
141
cvt_datadir=`cvt_get_param datadir`
142
# test for ISAM tables, which we must convert NOW
143
if [ -n "`find $cvt_datadir -name '*.ISM' 2>/dev/null`" ]; then
146
----------------------------------------
147
WARNING WARNING WARNING
148
----------------------------------------
150
It has been detected that are are using ISAM format on some of your
151
mysql database tables. This format has been deprecated and no longer
152
supported. to prevent these databases from essentially disappearing,
153
an attempt at format conversion will now be made. please check after
154
your upgrade that all tables are present and accounted for.
156
apologies for the noise, but we thought you'd appreciate it :)
158
----------------------------------------
159
WARNING WARNING WARNING
160
----------------------------------------
163
($cvt_mysqld >$cvt_log 2>&1; touch $mytmp/mysql.done ) &
165
if cvt_wait_for_server; then
166
dbs=`cvt_get_databases`
168
tables=`cvt_get_tables $db`
169
for tbl in $tables; do
170
cvt_convert_table $db $tbl
177
echo shutting down server... >&2
178
$cvt_mysqladmin shutdown
181
if [ ! "$cvt_error" = "yes" ]; then
184
echo "you might want to look in $mytmp..." >&2