5
. /usr/share/debconf/confmodule
7
if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
8
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
10
export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
12
# This command can be used as pipe to syslog. With "-s" it also logs to stderr.
13
ERR_LOGGER="logger -p daemon.err -t mysqld_safe -i"
16
if [ -x /usr/sbin/invoke-rc.d ]; then
23
MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables"
26
mysql --no-defaults -u root -h localhost </dev/null >/dev/null 2>&1
29
# call with $1 = "online" to connect to the server, otherwise it bootstraps
31
# forget we ever saw the password. don't use reset to keep the seen status
32
db_set mysql-server/root_password ""
33
db_set mysql-server/root_password_again ""
36
if [ ! -f "$tfile" ]; then
40
# this avoids us having to call "test" or "[" on $rootpw
43
UPDATE user SET password=PASSWORD("$rootpw") WHERE user='root';
46
if grep -q 'PASSWORD("")' $tfile; then
48
elif [ "$1" = "online" ]; then
49
mysql --no-defaults -u root -h localhost <$tfile >/dev/null
52
$MYSQL_BOOTSTRAP <$tfile
59
# This is necessary because mysql_install_db removes the pid file in /var/run
60
# and because changed configuration options should take effect immediately.
61
# In case the server wasn't running at all it should be ok if the stop
62
# script fails. I can't tell at this point because of the cleaned /var/run.
63
set +e; invoke stop; set -e
67
mysql_datadir=/usr/share/mysql
68
mysql_statedir=/var/lib/mysql
69
mysql_rundir=/var/run/mysqld
70
mysql_logdir=/var/log/mysql
71
mysql_cfgdir=/etc/mysql
72
mysql_upgradedir=/var/lib/mysql-upgrade
74
# Ensure the existence and right permissions for the database and
76
if [ ! -d "$mysql_statedir" -a ! -L "$mysql_statedir" ]; then mkdir "$mysql_statedir"; fi
77
if [ ! -d "$mysql_statedir/mysql" -a ! -L "$mysql_statedir/mysql" ]; then mkdir "$mysql_statedir/mysql"; fi
78
if [ ! -d "$mysql_logdir" -a ! -L "$mysql_logdir" ]; then mkdir "$mysql_logdir"; fi
79
# When creating an ext3 jounal on an already mounted filesystem like e.g.
80
# /var/lib/mysql, you get a .journal file that is not modifyable by chown.
81
# The mysql_datadir must not be writable by the mysql user under any
82
# circumstances as it contains scripts that are executed by root.
84
chown -R 0:0 $mysql_datadir
85
chown -R mysql $mysql_statedir
86
chmod 700 $mysql_statedir $mysql_statedir/mysql
87
if [ ! -d "$mysql_rundir" ]; then mkdir "$mysql_rundir"; fi
88
chown -R mysql $mysql_rundir
89
touch $mysql_logdir/error.log
90
chown -R mysql:adm $mysql_logdir
91
chmod 0750 $mysql_logdir
92
chmod 0640 $mysql_logdir/error.log
95
# This is important to avoid dataloss when there is a removed
96
# mysql-server version from Woody lying around which used the same
97
# data directory and then somewhen gets purged by the admin.
98
db_set mysql-server/postrm_remove_database false || true
100
# To avoid downgrades.
101
touch $mysql_statedir/debian-5.6.flag
103
# initiate databases. Output is not allowed by debconf :-(
104
# Debian: can safely run on upgrades with existing databases
107
tfile_select_db=`mktemp`
108
echo "USE mysql;" > $tfile_select_db
109
MYSQL_EXTRA_OPTS=" --default-storage-engine=myisam --lc-messages-dir=/usr/share/mysql/english/.."
110
MYSQL_CMDLINE=$MYSQL_BOOTSTRAP$MYSQL_EXTRA_OPTS
111
cat $tfile_select_db $mysql_datadir/mysql_system_tables.sql $mysql_datadir/debian_create_root_user.sql $mysql_datadir/fill_help_tables.sql | $MYSQL_CMDLINE 2>&1 | $ERR_LOGGER
115
## On every reconfiguration the maintenance user is recreated.
117
# - It is easier to regenerate the password every time but as people
118
# use fancy rsync scripts and file alteration monitors, the existing
119
# password is used and existing files not touched.
120
# - The mysqld statement is like that in mysql_install_db because the
121
# server is not already running. This has some implications:
122
# - The amount of newlines and semicolons in the query is important!
123
# - GRANT is not possible with --skip-grant-tables and "INSERT
124
# (user,host..) VALUES" is not --ansi compliant
125
# - The echo is just for readability. ash's buildin has no "-e" so use /bin/echo.
126
# - The Super_priv, Show_db_priv, Create_tmp_table_priv and Lock_tables_priv
127
# may not be present as old Woody 3.23 databases did not have it and the
128
# admin might not already have run mysql_upgrade which adds them.
129
# As the binlog cron scripts to need at least the Super_priv, I do first
130
# the old query which always succeeds and then the new which may or may not.
132
# recreate the credentials file if not present or without mysql_upgrade stanza
133
dc=$mysql_cfgdir/debian.cnf;
134
if [ -e "$dc" -a -n "`fgrep mysql_upgrade $dc 2>/dev/null`" ]; then
135
pass="`sed -n 's/^[ ]*password *= *// p' $dc | head -n 1`"
137
pass=`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)'`;
138
if [ ! -d "$mysql_cfgdir" ]; then install -o 0 -g 0 -m 0755 -d $mysql_cfgdir; fi
142
echo "# Automatically generated for Debian scripts. DO NOT TOUCH!" >>$dc
143
echo "[client]" >>$dc
144
echo "host = localhost" >>$dc
145
echo "user = debian-sys-maint" >>$dc
146
echo "password = $pass" >>$dc
147
echo "socket = $mysql_rundir/mysqld.sock" >>$dc
148
echo "[mysql_upgrade]" >>$dc
149
echo "host = localhost" >>$dc
150
echo "user = debian-sys-maint" >>$dc
151
echo "password = $pass" >>$dc
152
echo "socket = $mysql_rundir/mysqld.sock" >>$dc
153
echo "basedir = /usr" >>$dc
155
# If this dir chmod go+w then the admin did it. But this file should not.
159
replace_query=`echo -e \
161
"REPLACE INTO user SET " \
162
" host='localhost', user='debian-sys-maint', password=password('$pass'), " \
163
" Select_priv='Y', Insert_priv='Y', Update_priv='Y', Delete_priv='Y', " \
164
" Create_priv='Y', Drop_priv='Y', Reload_priv='Y', Shutdown_priv='Y', " \
165
" Process_priv='Y', File_priv='Y', Grant_priv='Y', References_priv='Y', " \
166
" Index_priv='Y', Alter_priv='Y', Super_priv='Y', Show_db_priv='Y', "\
167
" Create_tmp_table_priv='Y', Lock_tables_priv='Y', Execute_priv='Y', "\
168
" Repl_slave_priv='Y', Repl_client_priv='Y', Create_view_priv='Y', "\
169
" Show_view_priv='Y', Create_routine_priv='Y', Alter_routine_priv='Y', "\
170
" Create_user_priv='Y', Event_priv='Y', Trigger_priv='Y'; "`;
171
# Engines supported by etch should be installed per default. The query sequence is supposed
172
# to be aborted if the CREATE TABLE fails due to an already existent table in which case the
173
# admin might already have chosen to remove one or more plugins. Newlines are necessary.
174
install_plugins=`echo -e \
176
"CREATE TABLE IF NOT EXISTS plugin (name char(64) COLLATE utf8_bin NOT NULL DEFAULT '', " \
177
" dl char(128) COLLATE utf8_bin NOT NULL DEFAULT '', " \
178
" PRIMARY KEY (name)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='MySQL plugins';\n" \
179
"INSERT INTO plugin VALUES ('innodb', 'ha_innodb.so');\n" \
180
"INSERT INTO plugin VALUES ('federated', 'ha_federated.so');\n" \
181
"INSERT INTO plugin VALUES ('blackhole', 'ha_blackhole.so');\n" \
182
"INSERT INTO plugin VALUES ('archive', 'ha_archive.so');" `
184
db_get mysql-server/root_password && rootpw="$RET"
185
if ! set_mysql_rootpw; then
189
echo "$replace_query" | $MYSQL_BOOTSTRAP 2>&1 | $ERR_LOGGER
191
echo "$install_plugins" | $MYSQL_BOOTSTRAP 2>&1 | $ERR_LOGGER
195
abort-upgrade|abort-remove|abort-configure)
199
echo "postinst called with unknown argument '$1'" 1>&2
204
# here we check to see if we can connect as root without a password
205
# this should catch upgrades from previous versions where the root
206
# password wasn't set. if there is a password, or if the connection
207
# fails for any other reason, nothing happens.
208
if [ "$1" = "configure" ]; then
209
if test_mysql_access; then
210
db_input medium mysql-server/root_password || true
212
db_get mysql-server/root_password && rootpw="$RET"
214
if ! set_mysql_rootpw "online"; then
219
if [ "$password_error" = "yes" ]; then
220
db_input high mysql-server/error_setting_password || true
226
db_stop # in case invoke failes