~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to debian/mysql-server-5.6.postinst

  • Committer: Package Import Robot
  • Author(s): James Page, Akhil Mohan, Bjoern Boschman
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-0vst0nnto99pc2su
Tags: 5.6.15-0ubuntu1
[ Akhil Mohan ]
* added libmysqlclient.so link to libmysqlclient18.1-dev package
* revisited patches in d/patches/series; removed extra patches not needed
* some patches were modified to handle 5.6 issues
* mysql-server-5.6 and mysql-client-5.6 now depend on mysql-common (>= 5.5)
* mysql-server-5.6 now provides only virtual-mysql-server
* mysql-client-5.6 now provides only virtual-mysql-client
* MySQL 5.6 now contains mysql-common-5.6 which is only suggested
* moved mysql-common/etc/mysql/my.cnf to
    mysql-common-5.6/usr/share/mysql/my.cnf
* MySQL 5.6 now gives libmysqlclient18.1, libmysqlclient18.1-dev,
    libmysqld-5.6-dev and libmysqld-5.6-pic
* libmysqlclient18.1-dev, libmysqld-5.6-dev and libmysqld-5.6-pic packages
    conflict with their respective counterparts from MySQL 5.5
* link traversal for libmysqlclient is
    libmysqlclient.so (contained in libmysqclient18.1-dev)  ->
    libmysqlclient.so.18 (contained in libmysqclient18.1)   ->
    libmysqlclient.so.18.1 (contained in libmysqclient18.1) ->
    libmysqlclient.so.18.1.0 (contained in libmysqclient18.1)
* Placeholder packages mysql-server, mysql-client, mysql-testsuite 
  have been discontinued
* d/rules, d/control removed gcc-4.4 dependency and disable X86 assembly in
  taocrypt.
  - Cherry-pick from Debian svn r2231 with thanks to Clint Byrum.
* changed mirror to download source tar
* replaced mysql_install_db script with small shell script to create
  root accounts. This avoids creating anonymous users which were
  security concern.
* Docs/mysql.info has been removed in the mysql 5.6.15 source
* removed debian/repack.* and 'DFSG and repacking' section in
  debian/README.source because repack not needed
* dropped '+dfsg' from version in changelog since there is no repack
* simplified debian/watch since there is no repack
* removed redundant *_r* links to mysql client library in libmysqlclient18
  and libmysqlclient-dev packages
* updated debian/control to allow mysql-*-5.6 packages upgrade/ replace
  an existing installation of mysql-*-5.5 packages
* modified debian/rules to use system zlib library, install additional
  man pages and remove execute bit on few test and result files
* added patches to fix link path in man page mysql_client_test_embedded.1
  and mysqltest_embedded.1
* added man page for mysql_config_pic at debian/additions/mysql_config_pic.1
* added man page for mysql_embedded at debian/additions/mysql_embedded.1
* moved libmysqlcient.so link from libmysqlclient18 to libmysqlclient-dev
  based on lintian warning non-dev-pkg-with-shlib-symlink
* moved mysql_client_test_embedded binary from mysql-testsuite-5.6 
  package to mysql-client-5.6 package
* moved mysql_config_editor.1 man page to mysql-client-5.6 package
* moved mysql_embedded from mysql-testsuite-5.6 package to mysql-client-5.6
  package
* moved mysqltest_embedded binary from mysql-testsuite-5.6
  package to mysql-server-5.6 package
* removed absolute path for mysql_install_db script in mysql-server-5.6
  postinst script based on lintian warning

[ Bjoern Boschman ]
* Initial release of mysql-5.6 package.
* mysql_install_db is now a perl script. Do not run it with bash.
* added innodb_data_file_path to my.cnf for mysql-5.1 => mysql-5.6 upgrade
  path.
* added multiarch support 
* do not include .a files within libmysqlclient18

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
set -e
 
4
 
 
5
. /usr/share/debconf/confmodule
 
6
 
 
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 }
 
9
 
 
10
export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
 
11
 
 
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"
 
14
 
 
15
invoke() {
 
16
  if [ -x /usr/sbin/invoke-rc.d ]; then
 
17
    invoke-rc.d mysql $1
 
18
  else
 
19
    /etc/init.d/mysql $1
 
20
  fi
 
21
}
 
22
 
 
23
MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables"
 
24
 
 
25
test_mysql_access() {
 
26
       mysql --no-defaults -u root -h localhost </dev/null >/dev/null 2>&1
 
27
}
 
28
 
 
29
# call with $1 = "online" to connect to the server, otherwise it bootstraps
 
30
set_mysql_rootpw() {
 
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 ""
 
34
 
 
35
       tfile=`mktemp`
 
36
       if [ ! -f "$tfile" ]; then
 
37
               return 1
 
38
       fi
 
39
 
 
40
       # this avoids us having to call "test" or "[" on $rootpw
 
41
       cat << EOF > $tfile
 
42
USE mysql;
 
43
UPDATE user SET password=PASSWORD("$rootpw") WHERE user='root';
 
44
FLUSH PRIVILEGES;
 
45
EOF
 
46
       if grep -q 'PASSWORD("")' $tfile; then
 
47
               retval=0
 
48
       elif [ "$1" = "online" ]; then
 
49
               mysql --no-defaults -u root -h localhost <$tfile >/dev/null
 
50
               retval=$?
 
51
       else
 
52
               $MYSQL_BOOTSTRAP <$tfile
 
53
               retval=$?
 
54
       fi
 
55
       rm -f $tfile
 
56
       return $retval
 
57
}
 
58
 
 
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
 
64
    
 
65
case "$1" in
 
66
  configure)
 
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
 
73
 
 
74
    # Ensure the existence and right permissions for the database and
 
75
    # log files.
 
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.
 
83
    set +e
 
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
 
93
    set -e
 
94
 
 
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
 
99
 
 
100
    # To avoid downgrades.
 
101
    touch $mysql_statedir/debian-5.6.flag
 
102
 
 
103
    # initiate databases. Output is not allowed by debconf :-(
 
104
    # Debian: can safely run on upgrades with existing databases 
 
105
 
 
106
    set +e
 
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
 
112
    rm $tfile_select_db
 
113
    set -e
 
114
 
 
115
    ## On every reconfiguration the maintenance user is recreated.
 
116
    #
 
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.
 
131
 
 
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`"
 
136
    else
 
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
 
139
        umask 066
 
140
        cat /dev/null > $dc
 
141
        umask 022
 
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
 
154
    fi
 
155
    # If this dir chmod go+w then the admin did it. But this file should not.
 
156
    chown 0:0 $dc
 
157
    chmod 0600 $dc
 
158
 
 
159
    replace_query=`echo -e \
 
160
        "USE mysql;\n" \
 
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 \
 
175
        "USE mysql;\n" \
 
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');" `
 
183
 
 
184
    db_get mysql-server/root_password && rootpw="$RET"
 
185
    if ! set_mysql_rootpw; then
 
186
        password_error="yes"
 
187
    fi
 
188
 
 
189
    echo "$replace_query"                                    | $MYSQL_BOOTSTRAP 2>&1 | $ERR_LOGGER
 
190
    set +e
 
191
    echo "$install_plugins"                                  | $MYSQL_BOOTSTRAP 2>&1 | $ERR_LOGGER
 
192
    set -e
 
193
  ;;
 
194
 
 
195
  abort-upgrade|abort-remove|abort-configure)
 
196
  ;;
 
197
 
 
198
  *)
 
199
    echo "postinst called with unknown argument '$1'" 1>&2
 
200
    exit 1
 
201
  ;;
 
202
esac
 
203
 
 
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
 
211
               db_go
 
212
               db_get mysql-server/root_password && rootpw="$RET"
 
213
 
 
214
               if ! set_mysql_rootpw "online"; then
 
215
                       password_error="yes"
 
216
               fi
 
217
       fi
 
218
 
 
219
       if [ "$password_error" = "yes" ]; then
 
220
               db_input high mysql-server/error_setting_password || true
 
221
               db_go
 
222
       fi
 
223
 
 
224
fi
 
225
 
 
226
db_stop # in case invoke failes
 
227
 
 
228
#DEBHELPER#
 
229
 
 
230
exit 0