1d8f9b87605b36c15e0baec996d02fdab302798c
[mysql-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$1" = "configure" ] || exit 0
6
7 PKG="mysql-cn"
8
9 # Load CARNet Tools
10 . /usr/share/carnet-tools/functions.sh
11
12 if [ -f /etc/mysql/my.cnf ]; then
13   # ukljuci networking, da mysql visi na portu 3306
14   cp_check_and_sed '^skip-networking' \
15                    's/^skip-networking$/#skip-networking/' \
16                    /etc/mysql/my.cnf && restart=yes || true
17
18   # ukljuci podrsku za innodb, istinabog neznam zasto, al neka :-)
19   cp_check_and_sed '^skip-innodb$' \
20                    's/^skip-innodb$/#skip-innodb/' \
21                    /etc/mysql/my.cnf && restart=yes || true
22
23   # izgasi logiranje zbog prelude logova
24   cp_check_and_sed '^log.*mysql.log' \
25                    "s,^\([\t ]*log[\t ]*=\),#\1," \
26                    /etc/mysql/my.cnf && restart=yes || true
27
28   # ukljuci podrsku za hrvatsko znakovlje
29   # ne radi na Etch-u
30   #if ! grep -q default-character-set /etc/mysql/my.cnf; then
31   #  awk '/^\[mysqld\]/{print "[mysqld]"; print "default-character-set=croat"; getline}{print $0}' \
32   #    /etc/mysql/my.cnf > /etc/mysql/mysql-cn.$$
33   #  cp_mv /etc/mysql/mysql-cn.$$ /etc/mysql/my.cnf
34   #  restart=yes
35   #fi
36 fi
37
38 # pristup samo sa lokalne mreze, preko tcp-wrappera...
39 DOMAIN=`hostname -d`
40 if ! grep -q '^mysqld' /etc/hosts.deny; then
41         echo "mysqld: ALL" >> /etc/hosts.deny
42 fi
43 if ! grep -q '^mysqld' /etc/hosts.allow; then
44         echo "mysqld: .$DOMAIN 127.0.0.1" >> /etc/hosts.allow
45 fi
46
47 # ako nije setiran admin pass, setiraj
48 [ -f ~root/.my.cnf ] && grep -q "password.*=" ~root/.my.cnf && rootmycnf=1
49 if [ -z "$rootmycnf" ]; then
50   if ! grep -q "password.*=" /etc/mysql/my.cnf; then
51     if echo | mysql mysql 2> /dev/null; then
52       mypwd="`makepasswd`"
53       mysqladmin password $mypwd
54       cp_echo "CN: Password for MySQL administrator (root@localhost) is: $mypwd"
55       cp_mail $PKG
56     fi
57   fi
58 fi
59
60 if su - nobody -c '[ -r ~root/.my.cnf ]' 2>&1 > /dev/null; then
61   if grep -q "password.*=" ~root/.my.cnf; then
62     echo "CN: WARNING: ~root/.my.cnf is world readable."
63   fi
64 fi
65
66 [ "$restart" = "yes" ] || exit 0
67 # restart mysql-a
68 if [ -x /usr/sbin/invoke-rc.d ]; then
69   [ -x /etc/init.d/mysql ] && invoke-rc.d mysql restart
70 else
71   [ -x /etc/init.d/mysql ] && /etc/init.d/mysql restart
72 fi