File: phpbb2-conf-mysql.postinst

package info (click to toggle)
phpbb2 2.0.21-6
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 4,224 kB
  • ctags: 12
  • sloc: sh: 476; makefile: 108; perl: 29; php: 21
file content (191 lines) | stat: -rw-r--r-- 5,550 bytes parent folder | download | duplicates (2)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/sh
# postinst script for phpbb2
# By Jeroen van Wolffelaar <jeroen@wolffelaar.nl>

set -e

#export DEBCONF_DEBUG=developer

. /usr/share/debconf/confmodule

db_version 2.0

for i in setup server name user pass pass_generated rootpass; do
	db_get phpbb2-conf-mysql/db$i || true
	eval db$i'="$RET"'
done

# purge database rootpassword
db_reset phpbb2-conf-mysql/dbrootpass

if [ -z "$dbpass" ]; then
	if [ -z "$dbpass_generated" ]; then
		dbpass="`makepasswd --chars 12`"
		db_set phpbb2-conf-mysql/dbpass_generated $dbpass
	else
		dbpass="$dbpass_generated"
	fi
fi

bailout ()
{
	echo "Postinstallation of phpbb2-conf-mysql failed. Run"
	echo "\`dpkg --configure -a' to retry"
	for i in setup server name user pass _created; do
		db_fset phpbb2-conf-mysql/db$i seen false
	done
	exit 1
}

if [ "$dbserver" = localhost ] && ! [ -e /usr/sbin/mysqld ]; then
	echo "You need to have mysql-server installed if you want the MySQL
	database to be hosted locally. Aborting." >&2
	bailout
fi

	db_get phpbb2-conf-mysql/db_created
	if [ "$dbsetup" = Create ] && [ "$RET" != true ]; then
			dbadmin=root
			dbadmpass="$dbrootpass"
			echo "Creating MySQL database..."
			. /usr/share/wwwconfig-common/mysql-createdb.sh
			if [ "$status" = "error" ]; then
				db_reset phpbb2-conf-mysql/dbfailcreate
				db_subst phpbb2-conf-mysql/dbfailcreate error $(echo "$error"|head -1)
				db_input high phpbb2-conf-mysql/dbfailcreate || true
				db_go || true
				bailout
			fi

			dballow=localhost
			if [ "$dbserver" != localhost ]; then
				dballow=%
			fi
			echo "Creating MySQL user..."
			. /usr/share/wwwconfig-common/mysql-createuser.sh 
			if [ "$status" = "error" ]; then
				db_reset phpbb2-conf-mysql/dbfailcreateuser
				db_subst phpbb2-conf-mysql/dbfailcreateuser error $(echo "$error"|head -1) 
				db_input high phpbb2-conf-mysql/dbfailcreateuser || true
				db_go || true
				bailout
			fi
			db_set phpbb2-conf-mysql/db_created true
	fi
	if [ "$dbsetup" = Populate ] || [ "$dbsetup" = Create ]; then
# Okay, being idempotent in creating tables and adding a few rows is extremely
# hard thing to do. The tables is possible, but those rows? How can one
# distinguish from not having added a row yet because of a crash, and the row
# being intermittingly removed/edited by the user

# I'll assume that either the creating/populating of tables succeeds fully or
# it fails fully
			dbadmin="$dbuser"
			dbadmpass="$dbpass"
			statement='SELECT * FROM phpbb_config'
			sqlfile=`mktemp -t phpbb2-conf-mysql.schema.XXXXXX`
			zcat /usr/share/phpbb2/schemas/mysql_schema.sql.gz \
				> $sqlfile
			zcat /usr/share/phpbb2/schemas/mysql_basic.sql.gz \
				>> $sqlfile
			echo "Creating MySQL tables if they don't exist yet..."
			. /usr/share/wwwconfig-common/mysql-ifnot-exec.sh
			rm -f $sqlfile
			case "$status" in
			*error)
				db_reset phpbb2-conf-mysql/dbfailcreatetables || true
				db_subst phpbb2-conf-mysql/dbfailcreatetables error $(echo "$error"|head -1)
				db_input high phpbb2-conf-mysql/dbfailcreatetables || true
				db_go || true
				bailout
				;;
			exec)
				# this is the table layout version, manually updated
				db_set phpbb2-conf-mysql/db_version 2.0.18-1
				;;
			nothing)
				# the config table already existed. But maybe we're still
				# missing the sessions_keys table. Huge code duplication
				# follows...
				statement='SELECT * FROM phpbb_sessions_keys'
				sqlfile=`mktemp -t phpbb2-conf-mysql.schema.XXXXXX`
				zcat /usr/share/phpbb2/schemas/mysql_schema.sql.gz \
					| sed -n '/^CREATE TABLE phpbb_sessions_keys /,/^)/p' \
					> $sqlfile
				echo "Creating phpbb_sessions_keys table if it doesn't exist yet..."
				. /usr/share/wwwconfig-common/mysql-ifnot-exec.sh
				rm -f $sqlfile
				case "$status" in
				*error)
					db_reset phpbb2-conf-mysql/dbfailcreatetables || true
					db_subst phpbb2-conf-mysql/dbfailcreatetables error $(echo "$error"|head -1)
					db_input high phpbb2-conf-mysql/dbfailcreatetables || true
					db_go || true
					bailout
					;;
				exec|nothing)
					# [nothing] We were already running with the new table,
					# apparantly, or [exec] at least, we're now
					db_set phpbb2-conf-mysql/db_version 2.0.18-1
					;;
				*)
					echo "Unrecognized status from \
						wwwconfig-common/mysql-ifnot-exec.sh: $status" >&2
					exit 1
				esac
				;;
			*)
				echo "Unrecognized status from \
					wwwconfig-common/mysql-ifnot-exec.sh: $status" >&2
				exit 1
			esac
	fi

# Install/update config file
	tmpfile=`mktemp /tmp/phpbb2.config.php.XXXXXX`

	cat <<-NEWCONFIG > $tmpfile
	<?php
	// Database configuration file for phpbb2. This file is automatically
	// generated by phpbb2-conf-mysql
	
	/*
		Please use \`dpkg-reconfigure phpbb2-conf-mysql' if you want to modify
		these variables, or deinstall phpbb2-conf-mysql altogether.

		Only this way phpbb2-conf-mysql can upgrade your table definitions
		when needed.
	*/

	\$dbms         = "mysql";

	\$dbhost       = "$dbserver";
	\$dbname       = "$dbname";
	\$dbuser       = "$dbuser";
	\$dbpasswd     = "$dbpass";

	\$table_prefix = "phpbb_";

	define('PHPBB_INSTALLED', true);

	?>
	NEWCONFIG

	# If /etc/phpbb2/config.php disappeared, purge it from ucf too, otherwise
	# ucf will go crazy
	if [ ! -e /etc/phpbb2/config.php ]; then
		ucf --purge /etc/phpbb2/config.php
	fi

	# because of debconf, make ucf read from /dev/tty
	ucf --three-way $tmpfile /etc/phpbb2/config.php < /dev/tty
		
	rm -f $tmpfile

# fix permissions
chgrp www-data /etc/phpbb2/config.php
chmod g=r,o=   /etc/phpbb2/config.php

# Debhelper

#DEBHELPER#