File: mysql-server.postinst

package info (click to toggle)
mysql 3.23.49-8.13
  • links: PTS
  • area: main
  • in suites: woody
  • size: 65,624 kB
  • ctags: 45,242
  • sloc: ansic: 255,722; cpp: 86,801; perl: 26,117; tcl: 19,882; sh: 18,775; asm: 4,001; yacc: 2,626; makefile: 2,494; java: 2,300; awk: 1,484; sed: 428
file content (127 lines) | stat: -rw-r--r-- 4,960 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh -e

export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin

. /usr/share/debconf/confmodule
test $DEBIAN_SCRIPT_DEBUG && set -v -x

# This is necessary because mysql_install_db removes the pid file in /var/run
# and because changed configuration options should take effect immediately.
set +e; /etc/init.d/mysql stop; set -e
    
case "$1" in
  configure)
    mysql_datadir=/usr/share/mysql
    mysql_statedir=/var/lib/mysql
    mysql_rundir=/var/run/mysqld
    mysql_logdir=/var/log
    mysql_cfgdir=/etc/mysql
    mysql_newlogdir=/var/log/mysql
    
    # ensure the existence and right permissionsa for the database and
    # log files
    if ! test -d $mysql_statedir -o -L $mysql_statedir;	then mkdir $mysql_statedir; fi
    if ! test -d $mysql_statedir/mysql -o -L $mysql_statedir/mysql;	then mkdir $mysql_statedir/mysql; fi
    if ! test -d $mysql_statedir/test -o -L $mysql_statedir/test;	then mkdir $mysql_statedir/test; fi
    if ! test -d $mysql_newlogdir -o -L $mysql_newlogdir;	then mkdir $mysql_newlogdir; fi
    # when creating an ext3 jounal on an already mounted filesystem like e.g.
    # /var/lib/mysql, you get a .journal file that is not modifyable by chown
    set +e
    chown -R mysql $mysql_datadir
    chown -R mysql $mysql_statedir
    chown -R mysql $mysql_rundir
    chown -R mysql.mysql $mysql_newlogdir;	chmod 0770 $mysql_newlogdir;
    for i in log err; do
      touch             $mysql_logdir/mysql.$i
      chown mysql.mysql $mysql_logdir/mysql.$i
      chmod 0600        $mysql_logdir/mysql.$i
    done
    set -e
    # new location; omitting mysql.log* for compatibility reasons
    oldlogs=`ls $mysql_logdir/mysql.err* 2>/dev/null`
    if [ -n "$oldlogs" ]; then mv $oldlogs $mysql_newlogdir/; fi

    # initiate databases. Output is not allowed by debconf :-(
    # Debian: beware of the bashisms... 
    # Debian: can safely run on upgrades with existing databases 
    set +e
    /bin/bash /usr/bin/mysql_install_db -IN-RPM >>$mysql_newlogdir/mysql.err 2>&1
    if [ "$?" != "0" ]; then
      echo "ATTENTION: An error is occured. More info in /var/log/mysql/mysql.err!"
    fi
    set -e
    
    # On every reconfiguration the maintenance user is recreated.
    # The mysqld statement is like that in mysql_install_db because the
    # server is not already running.
    MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables  --skip-bdb  --skip-innodb  --skip-gemini"
    pass=`perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)'`;
    # ash has a buildin echo that does not support "-e"
    /bin/echo -e \
	"USE mysql;\n" \
	"DELETE FROM user WHERE host='localhost' and user='debian-sys-maint';\n" \
        "INSERT INTO user (host,user,password,shutdown_priv,reload_priv) VALUES " \
        "  ('localhost','debian-sys-maint',password('$pass'),'Y','Y');\n" \
	|$MYSQL_BOOTSTRAP >>$mysql_newlogdir/mysql.err 2>&1
    # If this dir chmod go+w then the admin did it. But this file should not.
    dc=$mysql_cfgdir/debian.cnf; 
    if [ ! -d "$mysql_cfgdir" ]; then install -o 0 -g 0 -m 0755 -d $mysql_cfgdir; fi
    cat /dev/null > $dc
    chown 0.0 $dc
    chmod 0600 $dc
    echo "# Automatically generated for Debian scripts. DO NOT TOUCH!" >>$dc
    echo "[client]"                    >>$dc
    echo "host     = localhost"        >>$dc
    echo "user     = debian-sys-maint" >>$dc
    echo "password = $pass"            >>$dc

    # Re: DEBHELPER
    #
    # No debhelper here because it would start mysql in every case and we 
    # want the user to decide to start mysql only on demand or on boot.
    #
    # 1. Things the Debhelper script did, too, which we may not omit.
    # 2. Registering the init script to modify /etc/runlevel.conf or /etc/rcX.d
    # 3. Start the daemon if it should start on boottime or on demand and 
    #    was running.
    #
    # Automatically added by dh_installdocs
    if [ "$1" = "configure" ]; then
      if [ -d /usr/doc -a ! -e /usr/doc/mysql-server -a -d /usr/share/doc/mysql-server ]; then
        ln -sf ../share/doc/mysql-server /usr/doc/mysql-server
      fi
    fi
    # End automatically added section
    db_get mysql-server/start_on_boot
    if [ "$RET" = "true" ]; then
      update-rc.d mysql defaults >/dev/null
    else
      # FIXME: doesn't work right now because update-rc.d has a bug!
      update-rc.d -f mysql remove >/dev/null
    fi
    if [ \( "$RET" = "true" \) -o \( -f /etc/mysql/dpkg__mysql_was_running \) ]; then
      /etc/init.d/mysql start
    fi
    rm -f /etc/mysql/dpkg__mysql_was_running

    # DSA 303-1, CAN-2003-0150
    if [ ! -e /var/lib/mysql/my.cnf ]; then
        echo "# This file must exist - CAN-2003-0150, DSA-303" > /var/lib/mysql/my.cnf
    fi

  ;;

  abort-upgrade|abort-remove|abort-configure)
  ;;

  *)
    echo "postinst called with unknown argument '$1'" >&2
    exit 1
  ;;
esac

db_stop

# No debhelper, see last lines of configure block from the case statement.

exit 0