File: mysql-server.preinst

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 (76 lines) | stat: -rw-r--r-- 2,121 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
#!/bin/sh -e

test $DEBIAN_SCRIPT_DEBUG && set -v -x

export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
MYADMIN="/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf"

# is everything in place ?
if [ ! -x "`which adduser`" ]; then 
	echo "I need adduser(8) from the adduser.deb package !";
	exit 1;
fi
if [ ! -x "`which addgroup`" ]; then 
	echo "I need addgroup(8) from the adduser.deb package !";
	exit 1;
fi
if [ ! -x "`which usermod`" ]; then
	echo "I need usermod(8) from the passwd.deb package !";
	exit 1;
fi

# to be sure
if [ -n "`$MYADMIN ping 2>/dev/null`" -a -x /etc/init.d/mysql ]; then
  /etc/init.d/mysql stop
fi

#
# Now we have to ensure the following state:
# /etc/passwd: mysql:x:100:101:MySQL Server:/var/lib/mysql:/bin/false
# /etc/group:  mysql:x:101:
# 
# Sadly there could any state be present on the system so we have to
# modify everything carefully i.e. not doing a chown before creating
# the user etc...
#

# creating mysql group if he isn't already there
if ! getent group mysql >/dev/null; then
	#echo Adding system group: mysql.
	addgroup mysql >/dev/null
fi

# creating mysql user if he isn't already there
if ! getent passwd mysql >/dev/null; then
	#echo Adding system user: mysql.
	adduser --system --ingroup mysql --home /var/lib/mysql mysql  >/dev/null
fi

# creating mysql home directory
if ! test -d /var/lib/mysql -o -L /var/lib/mysql; then
	mkdir /var/lib/mysql
fi

if ! test -d /var/log/mysql -o -L /var/log/mysql; then
	mkdir /var/log/mysql
fi

# modifying the user
usermod -c "MySQL Server" 	mysql
usermod -d "/var/lib/mysql"	mysql
usermod -g "mysql"		mysql
usermod -s "/bin/false" 	mysql

# Since the home directory was created before putting the user into
# the mysql group and moreover we cannot guarantee that the 
# permissions were correctly *before* calling this script, we fix them now.
#echo 
#echo "SECURITY: Fixing permission of /var/lib/mysql !"
#echo "(I.e. replacing GIDs other than root and mysql with mysql.)"
#echo
chown mysql.mysql /var/lib/mysql
find /var/lib/mysql \
	-not \( -group root -or -group mysql \) \
	-exec chgrp mysql {} \;

#DEBHELPER#