Browse code

- more database setup script work - add now generic file 'openserdbctl' for all database related tasks - move generic functions to this file - rename mysqldb.sh and postgresqldb.sh to openserdbctl.mysql and openserdbctl.psql - use 'color' info functions for user informations like the openserctl tool - remove unused mysqldb.sh backup function - make create user for postgres more error tolerant, needed for db copy - tested with mysql and postgresql for create, drop, reinit, backup, restore and copy - backup command needs now a filename, backup to stdout interfer with command prompting. This makes more sense as restore also wants a filename.

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2356 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 12/06/2007 11:36:05
Showing 5 changed files
... ...
@@ -7,7 +7,7 @@
7 7
 ## your SIP domain
8 8
 # SIP_DOMAIN=openser.org
9 9
 
10
-## database type: MYSQL or PGSQL, by defaulte none is loaded
10
+## database type: MYSQL, PGSQL or DBTEXT, by default none is loaded
11 11
 # DBENGINE=MYSQL
12 12
 
13 13
 ## database host
14 14
new file mode 100755
... ...
@@ -0,0 +1,265 @@
0
+#!/bin/bash 
1
+#
2
+# $Id$
3
+#
4
+# openser control tool for maintaining openser databases
5
+#
6
+#===================================================================
7
+
8
+PATH=$PATH:/usr/local/sbin/
9
+
10
+
11
+### include resource files, if any
12
+if [ -f /usr/local/etc/openser/openserctlrc ]; then
13
+	. /usr/local/etc/openser/openserctlrc
14
+fi
15
+if [ -f ~/.openserctlrc ]; then
16
+	. ~/.openserctlrc
17
+fi
18
+### for testing only
19
+#if [ -f ./openserctlrc ]; then
20
+#	. ./openserctlrc
21
+#fi
22
+
23
+
24
+##### ------------------------------------------------ #####
25
+### force values for variables in this section
26
+#
27
+
28
+# you better set the variables in ~/.openserctlrc
29
+
30
+
31
+if [ -z "$ETCDIR" ] ; then
32
+	ETCDIR="/usr/local/etc/openser"
33
+fi
34
+
35
+##### ------------------------------------------------ #####
36
+### 
37
+#
38
+### version for this script
39
+VERSION='1.3dev - $Revision$'
40
+
41
+if [ -z "$MYDIR" ] ; then
42
+	MYDIR=`dirname $0`
43
+fi
44
+
45
+if [ -z "$MYLIBDIR" ] ; then
46
+	MYLIBDIR="/usr/local/lib/openser/openserctl"
47
+	if [ ! -d "$MYLIBDIR" ]; then
48
+		MYLIBDIR=$MYDIR
49
+	fi
50
+fi
51
+
52
+
53
+### include resource files, if any
54
+if [ -f /usr/local/etc/openser/openserctlrc ]; then
55
+	. /usr/local/etc/openser/openserctlrc
56
+fi
57
+if [ -f ~/.openserctlrc ]; then
58
+	. ~/.openserctlrc
59
+fi
60
+if [ -f ./openserctlrc ]; then
61
+	. ./openserctlrc
62
+fi
63
+
64
+# force values for variables in this section
65
+# you better set the variables in ~/.openserctlrc
66
+if [ -z "$ETCDIR" ] ; then
67
+	ETCDIR="/usr/local/etc/openser"
68
+fi
69
+
70
+
71
+##### ------------------------------------------------ #####
72
+### load base functions
73
+#
74
+if [ -f "$MYLIBDIR/openserdbctl.base" ]; then
75
+	. "$MYLIBDIR/openserdbctl.base"
76
+else
77
+	merr "Cannot load core functions '$MYLIBDIR/openserdbctl.base' - exiting ..."
78
+	exit -1
79
+fi
80
+
81
+#
82
+##### ------------------------------------------------ #####
83
+### DBENGINE
84
+#
85
+DBENGINELOADED=0
86
+if [ -z "$DBENGINE" ] ; then
87
+	merr "database engine not specified, please setup one in the config script"
88
+	exit 1
89
+fi
90
+
91
+case $DBENGINE in
92
+	MYSQL|mysql|MySQL)
93
+		if [ -f "$MYLIBDIR/openserdbctl.mysql" ]; then
94
+			. "$MYLIBDIR/openserdbctl.mysql"
95
+			DBENGINELOADED=1
96
+		fi
97
+		;;
98
+	PGSQL|pgsql|postgres|postgresql|POSTGRESQL)
99
+		if [ -f "$MYLIBDIR/openserdbctl.pgsql" ]; then
100
+			. "$MYLIBDIR/openserdbctl.pgsql"
101
+			DBENGINELOADED=1
102
+		fi
103
+		;;
104
+	DBTEXT|dbtext|textdb)
105
+		if [ -f "$MYLIBDIR/openserdbctl.dbtext" ]; then
106
+			. "$MYLIBDIR/openserdbctl.dbtext"
107
+			DBENGINELOADED=1
108
+		fi
109
+		;;
110
+esac
111
+
112
+if [ $DBENGINELOADED -eq 1 ] ; then
113
+	mdbg "database engine '$DBENGINE' loaded"
114
+elif [ -n "$DBENGINE" ] ; then
115
+	merr "database engine not found - tried '$DBENGINE'"
116
+	exit 1
117
+fi
118
+
119
+
120
+# dump all rows
121
+openser_dump()  # pars: <database name>
122
+{
123
+	if [ $# -ne 2 ] ; then
124
+		merr "openser_dump function takes two param"
125
+		exit 1
126
+	fi
127
+	if [ "$PW" = "" ] ; then
128
+		$DUMP_CMD $1 > $2
129
+	else
130
+		$DUMP_CMD "-p$PW" $1 > $2
131
+	fi
132
+	if [ "$?" -ne 0 ]; then
133
+			merr "db dump failed"
134
+			exit 1
135
+	fi
136
+	minfo "db dump successful"
137
+}
138
+
139
+
140
+openser_restore() #pars: <database name> <filename>
141
+{
142
+	if [ $# -ne 2 ] ; then
143
+		merr "openser_restore function takes two params"
144
+		exit 1
145
+	fi
146
+	sql_query $1 < $2
147
+	if [ "$?" -ne 0 ]; then
148
+			merr "db restore failed"
149
+			exit 1
150
+	fi
151
+	minfo "db restore successful"
152
+}
153
+
154
+
155
+case $1 in
156
+# FIXME needs update for 1.3
157
+	migrate)
158
+		merr "not implemented yet"
159
+#		if [ $# -ne 3 ] ; then
160
+#			merr "migrate requires 2 parameters: old and new database"
161
+#			exit 1
162
+#		fi
163
+#		# create new database
164
+#		minfo "Creating new Database $3...."
165
+#		NO_USER_INIT="yes"
166
+#		openser_create $3
167
+#		if [ "$?" -ne 0 ] ; then
168
+#			echo "migrate: creating new database failed"
169
+#			exit 1
170
+#		fi
171
+#		# migrate data
172
+#		minfo "Migrating data from $2 to $3...."
173
+#		migrate_db $2 $3
174
+#		minfo "Migration successfully completed."
175
+#		exit 0;
176
+		usage
177
+		;;
178
+	copy)
179
+		# copy database to some other name
180
+		shift
181
+		if [ $# -ne 1 ]; then
182
+			usage
183
+			exit 1
184
+		fi
185
+		tmp_file=/tmp/openser_database.$$
186
+		openser_dump $DBNAME $tmp_file
187
+		ret=$?
188
+		if [ "$ret" -ne 0 ]; then
189
+			rm $tmp_file
190
+			exit $ret
191
+		fi
192
+		NO_USER_INIT="yes"
193
+		openser_create $1
194
+		ret=$?
195
+		if [ "$ret" -ne 0 ]; then
196
+			rm $tmp_file
197
+			exit $ret
198
+		fi
199
+		openser_restore $1 $tmp_file
200
+		ret=$?
201
+		rm -f $tmp_file
202
+		exit $ret
203
+		;;
204
+	backup)
205
+		# backup current database
206
+		shift
207
+		if [ $# -ne 1 ]; then
208
+			usage
209
+			exit 1
210
+		fi
211
+		openser_dump $DBNAME $1
212
+		exit $?
213
+		;;
214
+	restore)
215
+		# restore database from a backup
216
+		shift
217
+		if [ $# -ne 1 ]; then
218
+			usage
219
+			exit 1
220
+		fi
221
+		openser_restore $DBNAME $1
222
+		exit $?
223
+		;;
224
+	create)
225
+		# create new database structures
226
+		shift
227
+		if [ $# -eq 1 ] ; then
228
+			DBNAME="$1"
229
+		fi
230
+		openser_create $DBNAME
231
+		exit $?
232
+		;;
233
+	serweb)
234
+		serweb_create $DBNAME
235
+		exit $?
236
+		;;
237
+	presence)
238
+		presence_create $DBNAME
239
+		exit $?
240
+		;;
241
+	extra)
242
+		extra_create $DBNAME
243
+		exit $?
244
+		;;
245
+	drop)
246
+		# delete openser database
247
+		openser_drop $DBNAME
248
+		exit $?
249
+		;;
250
+	reinit)
251
+		# delete database and create a new one
252
+		openser_drop $DBNAME
253
+		ret=$?
254
+		if [ "$ret" -ne 0 ]; then
255
+			exit $ret
256
+		fi
257
+		openser_create $DBNAME
258
+		exit $?
259
+		;;
260
+	*)
261
+		usage
262
+		exit 1;
263
+		;;
264
+esac
... ...
@@ -87,21 +87,21 @@ fi
87 87
 usage() {
88 88
 COMMAND=`basename $0`
89 89
 cat <<EOF
90
-usage: $COMMAND create
91
-       $COMMAND drop   (!!entirely deletes tables)
92
-       $COMMAND reinit (!!entirely deletes and than re-creates tables
93
-       $COMMAND backup (dumps current database to stdout)
90
+usage: $COMMAND create (creates a new database)
91
+       $COMMAND drop   (!entirely deletes tables!)
92
+       $COMMAND reinit (!entirely deletes and than re-creates tables!)
93
+       $COMMAND backup <file> (dumps current database to file)
94 94
        $COMMAND restore <file> (restores tables from a file)
95 95
        $COMMAND copy <new_db> (creates a new db from an existing one)
96
-       $COMMAND migrate <old_db> <new_db> (migrates DB from 1.1 to 1.2)
96
+       $COMMAND migrate <old_db> <new_db> (migrates DB from 1.2 to 1.3, not implemented yet!)
97 97
        $COMMAND presence (adds the presence related tables)
98 98
        $COMMAND extra (adds the extra tables - imc,cpl,siptrace,domainpolicy)
99 99
        $COMMAND serweb (adds the SERWEB specific tables)
100 100
 
101
-       if you want to manipulate database as other MySQL user than
101
+       if you want to manipulate database as other database user than
102 102
        root, want to change database name from default value "$DBNAME",
103 103
        or want to use other values for users and password, edit the
104
-       "config vars" section of the command $COMMAND
104
+       "config vars" section of the command $COMMAND.
105 105
 
106 106
 EOF
107 107
 } #usage
... ...
@@ -123,12 +123,12 @@ credentials()
123 123
 {
124 124
 	HA1=`echo -n "admin:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
125 125
 	if [ $? -ne 0 ] ; then
126
-		echo "HA1 calculation failed"
126
+		merr "HA1 calculation failed"
127 127
 		exit 1
128 128
 	fi
129 129
 	HA1B=`echo -n "admin@$SIP_DOMAIN:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
130 130
 	if [ $? -ne 0 ] ; then
131
-		echo "HA1B calculation failed"
131
+		merr "HA1B calculation failed"
132 132
 		exit 1
133 133
 	fi
134 134
 
... ...
@@ -136,7 +136,7 @@ credentials()
136 136
 	NOW=`date`;
137 137
 	PHPLIB_ID=`echo -n "$RANDOM:$NOW:$SIP_DOMAIN" | $MD5 | $AWK '{ print $1 }'`
138 138
 	if [ $? -ne 0 ] ; then
139
-		echo "PHPLIB_ID calculation failed"
139
+		merr "PHPLIB_ID calculation failed"
140 140
 		exit 1
141 141
 	fi
142 142
 }
... ...
@@ -157,3 +157,47 @@ serweb_message()
157 157
 	echo "!                                                 !"
158 158
 	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
159 159
 }
160
+
161
+# FIXME use the definition from openserctl.base
162
+
163
+mdbg() {
164
+	if [ "0$VERBOSE" -ne 0 ] ; then
165
+		if [ -t 1 -a -z "$NOHLPRINT" ] ; then
166
+			echo -e "\033[1m$1\033[0m"
167
+		else
168
+			echo "$1"
169
+		fi
170
+	fi
171
+}
172
+
173
+mwarn() {
174
+	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
175
+		echo -e '\E[37;32m'"\033[1mWARNING: $1\033[0m"
176
+	else
177
+		echo "** WARNING: $1"
178
+	fi
179
+}
180
+
181
+minfo() {
182
+	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
183
+		echo -e '\E[37;33m'"\033[1mINFO: $1\033[0m"
184
+	else
185
+		echo "** INFO: $1"
186
+	fi
187
+}
188
+
189
+mecho() {
190
+	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
191
+		echo -e "\033[1m$1\033[0m"
192
+	else
193
+		echo "$1"
194
+	fi
195
+}
196
+
197
+merr() {
198
+	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
199
+		echo -e '\E[37;31m'"\033[1mERROR: $1\033[0m"
200
+	else
201
+		echo "** ERROR: $1"
202
+	fi
203
+}
160 204
similarity index 71%
161 205
rename from tools/mysqldb.sh
162 206
rename to tools/openserdbctl.mysql
... ...
@@ -1,5 +1,3 @@
1
-#!/bin/sh
2
-#
3 1
 # $Id$
4 2
 #
5 3
 # Script for adding and dropping OpenSER MySQL tables
... ...
@@ -29,52 +27,10 @@
29 29
 # 2006-10-27  subscriber table cleanup; some columns are created only if
30 30
 #             serweb is installed (bogdan)
31 31
 # 2007-02-28  DB migration added (bogdan)
32
-#
33 32
 # 2007-05-21  Move SQL database definitions out of this script (henning)
34
-#
35 33
 # 2007-05-31  Move common definitions to openserdbctl.base file (henningw)
36
-
37
-PATH=$PATH:/usr/local/sbin
38
-
39
-### include resource files, if any
40
-if [ -f /usr/local/etc/openser/openserctlrc ]; then
41
-	. /usr/local/etc/openser/openserctlrc
42
-fi
43
-if [ -f ~/.openserctlrc ]; then
44
-	. ~/.openserctlrc
45
-fi
46
-if [ -f ./openserctlrc ]; then
47
-	. ./openserctlrc
48
-fi
49
-
50
-# force values for variables in this section
51
-# you better set the variables in ~/.openserctlrc
52
-if [ -z "$ETCDIR" ] ; then
53
-	ETCDIR="/usr/local/etc/openser"
54
-fi
55
-
56
-### version for this script
57
-VERSION='1.3dev - $Revision$'
58
-
59
-if [ -z "$MYDIR" ] ; then
60
-	MYDIR=`dirname $0`
61
-fi
62
-
63
-if [ -z "$MYLIBDIR" ] ; then
64
-	MYLIBDIR="/usr/local/lib/openser/openserctl"
65
-	if [ ! -d "$MYLIBDIR" ]; then
66
-		MYLIBDIR=$MYDIR
67
-	fi
68
-fi
69
-
70
-# load base functions
71
-if [ -f "$MYLIBDIR/openserdbctl.base" ]; then
72
-	. "$MYLIBDIR/openserdbctl.base"
73
-else
74
-	echo "Cannot load core functions '$MYLIBDIR/openserdbctl.base' - exiting ..."
75
-	exit -1
76
-fi
77
-
34
+#
35
+# 2007-06-11  Use a common control tool for database tasks, like the openserctl
78 36
 
79 37
 # path to the database schemas
80 38
 DATA_DIR="/usr/local/share/openser"
... ...
@@ -95,8 +51,6 @@ fi
95 95
 
96 96
 CMD="mysql -h $DBHOST -u$DBROOTUSER "
97 97
 DUMP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c -t "
98
-BACKUP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c "
99
-
100 98
 #################################################################
101 99
 
102 100
 
... ...
@@ -104,7 +58,7 @@ BACKUP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c "
104 104
 prompt_pw()
105 105
 {
106 106
 	savetty=`stty -g`
107
-	printf "MySQL password for $DBROOTUSER: "
107
+	echo -n "MySQL password for $DBROOTUSER: "
108 108
 	stty -echo
109 109
 	read PW
110 110
 	stty $savetty
... ...
@@ -137,65 +91,21 @@ sql_query()
137 137
 	fi
138 138
 }
139 139
 
140
-# dump all rows
141
-openser_dump()  # pars: <database name>
142
-{
143
-	if [ $# -ne 1 ] ; then
144
-		echo "openser_dump function takes one param"
145
-		exit 1
146
-	fi
147
-	$DUMP_CMD "-p$PW" $1
148
-}
149
-
150
-
151
-# copy a database to database_bak
152
-openser_backup() # par: <database name>
153
-{
154
-	if [ $# -ne 1 ] ; then
155
-		echo  "openser_backup function takes one param"
156
-		exit 1
157
-	fi
158
-	BU=/tmp/mysql_bup.$$
159
-	$BACKUP_CMD "-p$PW" $1 > $BU
160
-	if [ "$?" -ne 0 ] ; then
161
-		echo "openser_backup dump failed"
162
-		exit 1
163
-	fi
164
-	sql_query "" "create database $1_bak;"
165
-
166
-	openser_restore $1_bak $BU
167
-	if [ "$?" -ne 0 ]; then
168
-		echo "openser backup/restore failed"
169
-		rm $BU
170
-		exit 1
171
-	fi
172
-}
173
-
174
-
175
-openser_restore() #pars: <database name> <filename>
176
-{
177
-if [ $# -ne 2 ] ; then
178
-	echo "openser_restore function takes two params"
179
-	exit 1
180
-fi
181
-sql_query $1 < $2
182
-}
183
-
184 140
 
185 141
 openser_drop()  # pars: <database name>
186 142
 {
187 143
 if [ $# -ne 1 ] ; then
188
-	echo "openser_drop function takes two params"
144
+	merr "openser_drop function takes two params"
189 145
 	exit 1
190 146
 fi
191 147
 
192 148
 sql_query "" "drop database $1;"
193 149
 
194 150
 if [ $? -ne 0 ] ; then
195
-	echo "Dropping database $1 failed!"
151
+	merr "Dropping database $1 failed!"
196 152
 	exit 1
197 153
 fi
198
-echo "Database $1 deleted"
154
+minfo "Database $1 deleted"
199 155
 }
200 156
 
201 157
 
... ...
@@ -205,12 +115,12 @@ db_charset_test()
205 205
 	ALLCHARSETS=`echo "show character set" | $CMD "-p$PW" | $AWK '{print $1}' | $SED -e 1d | $GREP -iv utf8\|ucs2`
206 206
 	while [ `echo "$ALLCHARSETS" | $GREP -icw $CURRCHARSET`  = "0" ]
207 207
 	do
208
-		echo "Your current default mysql characters set cannot be used to create DB. Please choice another one from the following list:"
209
-		echo "$ALLCHARSETS"
210
-		echo -n "Enter character set name: "
208
+		mwarn "Your current default mysql characters set cannot be used to create DB. Please choice another one from the following list:"
209
+		mecho "$ALLCHARSETS"
210
+		mecho -n "Enter character set name: "
211 211
 		read CURRCHARSET
212 212
 		if [ `echo $CURRCHARSET | $GREP -cE "\w+"` = "0" ]; then
213
-			echo "can't continue: user break"
213
+			merr "can't continue: user break"
214 214
 			exit 1
215 215
 		fi
216 216
 	done
... ...
@@ -221,13 +131,13 @@ db_charset_test()
221 221
 openser_create () # pars: <database name>
222 222
 {
223 223
 if [ $# -ne 1 ] ; then
224
-	echo "openser_create function takes one param"
224
+	merr "openser_create function takes one param"
225 225
 	exit 1
226 226
 fi
227 227
 
228 228
 db_charset_test
229 229
 
230
-echo "creating database $1 ..."
230
+minfo "creating database $1 ..."
231 231
 
232 232
 # Users: ser is the regular user, serro only for reading
233 233
 sql_query "" "create database $1 character set $CHARSET;
... ...
@@ -238,20 +148,20 @@ sql_query "" "create database $1 character set $CHARSET;
238 238
 
239 239
 
240 240
 if [ $? -ne 0 ] ; then
241
-	echo "Creating core database and grant privileges failed!"
241
+	merr "Creating core database and grant privileges failed!"
242 242
 	exit 1
243 243
 fi
244 244
 
245 245
 for TABLE in $STANDARD_MODULES; do
246
-    echo "Creating core table: $TABLE"
246
+    mdbg "Creating core table: $TABLE"
247 247
     sql_query $1 < $DB_SCHEMA/$TABLE-create.sql
248 248
     if [ $? -ne 0 ] ; then
249
-	echo "Creating core tables failed!"
249
+	merr "Creating core tables failed!"
250 250
 	exit 1
251 251
     fi
252 252
 done
253 253
 
254
-echo "Core OpenSER tables succesfully created."
254
+minfo "Core OpenSER tables succesfully created."
255 255
 
256 256
 echo -n "Install presence related tables ?(y/n):"
257 257
 read INPUT
... ...
@@ -281,58 +191,58 @@ fi
281 281
 presence_create () # pars: <database name>
282 282
 {
283 283
 if [ $# -ne 1 ] ; then
284
-	echo "presence_create function takes one param"
284
+	merr "presence_create function takes one param"
285 285
 	exit 1
286 286
 fi
287 287
 
288
-echo "creating presence tables into $1 ..."
288
+minfo "creating presence tables into $1 ..."
289 289
 
290 290
 sql_query $1 < $DB_SCHEMA/presence-create.sql
291 291
 
292 292
 if [ $? -ne 0 ] ; then
293
-	echo "Failed to create presence tables!"
293
+	merr "Failed to create presence tables!"
294 294
 	exit 1
295 295
 fi
296 296
 
297
-echo "Presence tables succesfully created."
297
+minfo "Presence tables succesfully created."
298 298
 }  # end presence_create
299 299
 
300 300
 
301 301
 extra_create () # pars: <database name>
302 302
 {
303 303
 if [ $# -ne 1 ] ; then
304
-	echo "extra_create function takes one param"
304
+	merr "extra_create function takes one param"
305 305
 	exit 1
306 306
 fi
307 307
 
308
-echo "creating extra tables into $1 ..."
308
+minfo "creating extra tables into $1 ..."
309 309
 
310 310
 for TABLE in $EXTRA_MODULES; do
311
-    echo "Creating extra table: $TABLE"
311
+    mdbg "Creating extra table: $TABLE"
312 312
     sql_query $1 < $DB_SCHEMA/$TABLE-create.sql
313 313
     if [ $? -ne 0 ] ; then
314
-	echo "Creating extra tables failed!"
314
+	merr "Creating extra tables failed!"
315 315
 	exit 1
316 316
     fi
317 317
 done
318 318
 
319
-echo "Extra tables succesfully created."
319
+minfo "Extra tables succesfully created."
320 320
 }  # end extra_create
321 321
 
322 322
 
323 323
 serweb_create () # pars: <database name>
324 324
 {
325 325
 if [ $# -ne 1 ] ; then
326
-	echo "serweb_create function takes one param"
326
+	merr "serweb_create function takes one param"
327 327
 	exit 1
328 328
 fi
329 329
 
330
-echo "creating serweb tables into $1 ..."
330
+minfo "creating serweb tables into $1 ..."
331 331
 
332 332
 sql_query $1 < $DB_SCHEMA/serweb-create.sql 
333 333
 
334 334
 if [ $? -ne 0 ] ; then
335
-	echo "Failed to create serweb tables!"
335
+	merr "Failed to create serweb tables!"
336 336
 	exit 1
337 337
 fi
338 338
 
... ...
@@ -349,7 +259,7 @@ sql_query $1 "ALTER TABLE subscriber
349 349
     ADD UNIQUE KEY phplib_id (phplib_id);"
350 350
 
351 351
 if [ $? -ne 0 ] ; then
352
-	echo "Failed to alter subscriber table for serweb!"
352
+	merr "Failed to alter subscriber table for serweb!"
353 353
 	exit 1
354 354
 fi
355 355
 
... ...
@@ -372,15 +282,16 @@ if [ -z "$NO_USER_INIT" ] ; then
372 372
 	VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
373 373
 
374 374
 	if [ $? -ne 0 ] ; then
375
-		echo "Failed to create serweb credentials tables!"
375
+		merr "Failed to create serweb credentials tables!"
376 376
 		exit 1
377 377
 	fi
378
+	serweb_message
378 379
 fi
379 380
 
380 381
 
381
-echo "SERWEB tables succesfully created."
382
+minfo "SERWEB tables succesfully created."
383
+
382 384
 
383
-serweb_message
384 385
 }  # end serweb_create
385 386
 
386 387
 
... ...
@@ -388,7 +299,7 @@ serweb_message
388 388
 migrate_table () # 4 paremeters (dst_table, dst_cols, src_table, src_cols)
389 389
 {
390 390
 if [ $# -ne 4 ] ; then
391
-	echo "migrate_table function takes 4 params $@"
391
+	merr "migrate_table function takes 4 params $@"
392 392
 	exit 1
393 393
 fi
394 394
 
... ...
@@ -413,15 +324,15 @@ if [ $? -ne 0 ] ; then
413 413
 	exit 1;
414 414
 fi
415 415
 
416
-echo " -- Migrating $3 to $1.....OK"
416
+minfo " -- Migrating $3 to $1.....OK"
417 417
 
418 418
 }
419 419
 
420
-
420
+# FIXME needs update for 1.3
421 421
 migrate_db () # 2 parameters (src_db, dst_db)
422 422
 {
423 423
 if [ $# -ne 2 ] ; then
424
-	echo "migrate_db function takes 2 params"
424
+	merr "migrate_db function takes 2 params"
425 425
 	exit 1
426 426
 fi
427 427
 
... ...
@@ -603,115 +514,3 @@ export PW
603 603
 if [ "$#" -ne 0 ] && [ "$PW" = "" ]; then
604 604
 	prompt_pw
605 605
 fi
606
-
607
-
608
-
609
-
610
-case $1 in
611
-	migrate)
612
-		if [ $# -ne 3 ] ; then
613
-			echo "migrate requires 2 paramets: old and new database"
614
-			exit 1
615
-		fi
616
-		# create new database
617
-		echo "Creating new Database $3...."
618
-		NO_USER_INIT="yes"
619
-		openser_create $3
620
-		if [ "$?" -ne 0 ] ; then
621
-			echo "migrate: creating new database failed"
622
-			exit 1
623
-		fi
624
-		# migrate data
625
-		echo "Migrating data from $2 to $3...."
626
-		migrate_db $2 $3
627
-		echo "Migration successfully completed."
628
-		exit 0;
629
-		;;
630
-	copy)
631
-		# copy database to some other name
632
-		shift
633
-		if [ $# -ne 1 ]; then
634
-			usage
635
-			exit 1
636
-		fi
637
-		tmp_file=/tmp/openser_mysql.$$
638
-		openser_dump $DBNAME > $tmp_file
639
-		ret=$?
640
-		if [ "$ret" -ne 0 ]; then
641
-			echo "copy: dumping original db failed"
642
-			rm $tmp_file
643
-			exit $ret
644
-		fi
645
-		NO_USER_INIT="yes"
646
-		openser_create $1
647
-		ret=$?
648
-		if [ "$ret" -ne 0 ]; then
649
-			echo "copy: creating new db failed"
650
-			rm $tmp_file
651
-			exit $ret
652
-		fi
653
-		openser_restore $1 $tmp_file
654
-		ret=$?
655
-		rm -f $tmp_file
656
-		if [ "$ret" -ne 0 ]; then
657
-			echo "copy: restoring old db failed"
658
-		fi
659
-		exit $ret
660
-		;;
661
-	backup)
662
-		# backup current database
663
-		openser_dump $DBNAME
664
-		exit $?
665
-		;;
666
-	restore)
667
-		# restore database from a backup
668
-		shift
669
-		if [ $# -ne 1 ]; then
670
-			usage
671
-			exit 1
672
-		fi
673
-		openser_restore $DBNAME $1
674
-		exit $?
675
-		;;
676
-	create)
677
-		# create new database structures
678
-		shift
679
-		if [ $# -eq 1 ] ; then
680
-			DBNAME="$1"
681
-		fi
682
-		openser_create $DBNAME
683
-		exit $?
684
-		;;
685
-	serweb)
686
-		serweb_create $DBNAME
687
-		exit $?
688
-		;;
689
-	presence)
690
-		presence_create $DBNAME
691
-		exit $?
692
-		;;
693
-	extra)
694
-		extra_create $DBNAME
695
-		exit $?
696
-		;;
697
-	drop)
698
-		# delete openser database
699
-		openser_drop $DBNAME
700
-		exit $?
701
-		;;
702
-	reinit)
703
-		# delete database and create a new one
704
-		openser_drop $DBNAME
705
-		ret=$?
706
-		if [ "$ret" -ne 0 ]; then
707
-			exit $ret
708
-		fi
709
-		openser_create $DBNAME
710
-		exit $?
711
-		;;
712
-	*)
713
-		usage
714
-		exit 1;
715
-		;;
716
-esac
717
-
718 606
similarity index 59%
719 607
rename from tools/postgresqldb.sh
720 608
rename to tools/openserdbctl.pgsql
... ...
@@ -48,51 +48,10 @@
48 48
 #             serweb is installed (bogdan)
49 49
 # 2007-01-26  added seperate installation routine for presence related tables
50 50
 #             and fix permissions for the SERIAL sequences.
51
-#
52 51
 # 2007-05-21  Move SQL database definitions out of this script (henning)
53
-#
54 52
 # 2007-05-31  Move common definitions to openserdbctl.base file (henningw)
55
-
56
-PATH=$PATH:/usr/local/sbin
57
-
58
-### include resource files, if any
59
-if [ -f /usr/local/etc/openser/openserctlrc ]; then
60
-	. /usr/local/etc/openser/openserctlrc
61
-fi
62
-if [ -f ~/.openserctlrc ]; then
63
-	. ~/.openserctlrc
64
-fi
65
-if [ -f ./openserctlrc ]; then
66
-	. ./openserctlrc
67
-fi
68
-
69
-# force values for variables in this section
70
-# you better set the variables in ~/.openserctlrc
71
-if [ -z "$ETCDIR" ] ; then
72
-	ETCDIR="/usr/local/etc/openser"
73
-fi
74
-
75
-### version for this script
76
-VERSION='1.3dev - $Revision$'
77
-
78
-if [ -z "$MYDIR" ] ; then
79
-	MYDIR=`dirname $0`
80
-fi
81
-
82
-if [ -z "$MYLIBDIR" ] ; then
83
-	MYLIBDIR="/usr/local/lib/openser/openserctl"
84
-	if [ ! -d "$MYLIBDIR" ]; then
85
-		MYLIBDIR=$MYDIR
86
-	fi
87
-fi
88
-
89
-# load base functions
90
-if [ -f "$MYLIBDIR/openserdbctl.base" ]; then
91
-	. "$MYLIBDIR/openserdbctl.base"
92
-else
93
-	echo "Cannot load core functions '$MYLIBDIR/openserdbctl.base' - exiting ..."
94
-	exit -1
95
-fi
53
+#
54
+# 2007-06-11  Use a common control tool for database tasks, like the openserctl
96 55
 
97 56
 # path to the database schemas
98 57
 DATA_DIR="/usr/local/share/openser"
... ...
@@ -110,46 +69,17 @@ fi
110 110
 if [ -z "$DBROOTUSER" ]; then
111 111
 	DBROOTUSER="postgres"
112 112
 	if [ ! -r ~/.pgpass ]; then
113
-		echo "~./pgpass does not exist, please create this file and support proper credentials for user postgres."
114
-		echo "Note: you need at least postgresql>= 7.3"
113
+		merr "~./pgpass does not exist, please create this file and support proper credentials for user postgres."
114
+		merr "Note: you need at least postgresql>= 7.3"
115 115
 		exit 1
116 116
 	fi
117 117
 fi
118 118
 
119 119
 CMD="psql -h $DBHOST -U $DBROOTUSER "
120
-# the following commands are untested:
121
-#   DUMP_CMD="pg_dump -h $DBHOST -u$DBROOTUSER -c -t "
122
-#   BACKUP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c "
123
-
120
+DUMP_CMD="pg_dump -h $DBHOST -U $DBROOTUSER -c"
124 121
 #################################################################
125 122
 
126 123
 
127
-usage() {
128
-COMMAND=`basename $0`
129
-cat <<EOF
130
-usage: $COMMAND create
131
-       $COMMAND drop   (!!entirely deletes tables)
132
-       $COMMAND reinit (!!entirely deletes and than re-creates tables
133
-       $COMMAND presence (adds the presence related tables)
134
-       $COMMAND extra (adds the extra tables - imc,cpl,siptrace,domainpolicy)
135
-       $COMMAND serweb (adds the SERWEB specific tables)
136
-
137
- NOTE: the following commands are not tested with postgresql,
138
- thus they are disabled.
139
-       $COMMAND backup (dumps current database to stdout)
140
-       $COMMAND restore <file> (restores tables from a file)
141
-       $COMMAND copy <new_db> (creates a new db from an existing one)
142
-       $COMMAND reinstall (updates to a new OpenSER database)
143
-
144
-       if you want to manipulate database as other postgresql user than
145
-       "postgres", want to change database name from default value "$DBNAME",
146
-       or want to use other values for users and password, edit the
147
-       "config vars" section of the command $COMMAND
148
-
149
-EOF
150
-} #usage
151
-
152
-
153 124
 # execute sql command with optional db name
154 125
 sql_query()
155 126
 {
... ...
@@ -167,56 +97,10 @@ sql_query()
167 167
 }
168 168
 
169 169
 
170
-# dump all rows
171
-openser_dump()  # pars: <database name>
172
-{
173
-	if [ $# -ne 1 ] ; then
174
-		echo "openser_dump function takes one param"
175
-		exit 1
176
-	fi
177
-	$DUMP_CMD "-p$PW" $1
178
-}
179
-
180
-
181
-# copy a database to database_bak
182
-openser_backup() # par: <database name>
183
-{
184
-	if [ $# -ne 1 ] ; then
185
-		echo  "openser_backup function takes one param"
186
-		exit 1
187
-	fi
188
-	BU=/tmp/mysql_bup.$$
189
-	$BACKUP_CMD "-p$PW" $1 > $BU
190
-	if [ "$?" -ne 0 ] ; then
191
-		echo "ser backup dump failed"
192
-		exit 1
193
-	fi
194
-	sql_query <<EOF
195
-	create database $1_bak;
196
-EOF
197
-
198
-	openser_restore $1_bak $BU
199
-	if [ "$?" -ne 0 ]; then
200
-		echo "ser backup/restore failed"
201
-		rm $BU
202
-		exit 1
203
-	fi
204
-}
205
-
206
-openser_restore() #pars: <database name> <filename>
207
-{
208
-if [ $# -ne 2 ] ; then
209
-	echo "openser_restore function takes two params"
210
-	exit 1
211
-fi
212
-sql_query $1 < $2
213
-}
214
-
215
-
216 170
 openser_drop()  # pars: <database name>
217 171
 {
218 172
 if [ $# -ne 1 ] ; then
219
-	echo "openser_drop function takes two params"
173
+	merr "openser_drop function takes two params"
220 174
 	exit 1
221 175
 fi
222 176
 
... ...
@@ -224,25 +108,25 @@ fi
224 224
 sql_query "template1" "drop database $1; drop user \"$DBRWUSER\"; drop user \"$DBROUSER\";"
225 225
 
226 226
 if [ $? -ne 0 ] ; then
227
-	echo "Dropping database $1 failed!"
227
+	merr "Dropping database $1 failed!"
228 228
 	exit 1
229 229
 fi
230
-echo "Database $1 dropped"
230
+minfo "Database $1 dropped"
231 231
 } #openser_drop
232 232
 
233 233
 
234 234
 openser_create () # pars: <database name>
235 235
 {
236 236
 if [ $# -ne 1 ] ; then
237
-	echo "openser_create function takes one param"
237
+	merr "openser_create function takes one param"
238 238
 	exit 1
239 239
 fi
240 240
 
241
-echo "creating database $1 ..."
241
+minfo "creating database $1 ..."
242 242
 
243 243
 sql_query "template1" "create database $1;"
244 244
 if [ $? -ne 0 ] ; then
245
-	echo "Creating database failed!"
245
+	merr "Creating database failed!"
246 246
 	exit 1
247 247
 fi
248 248
 
... ...
@@ -251,22 +135,26 @@ sql_query "$1" "CREATE FUNCTION "concat" (text,text) RETURNS text AS 'SELECT \$1
251 251
 # emulate mysql proprietary functions used by the lcr module in postgresql
252 252
 
253 253
 if [ $? -ne 0 ] ; then
254
-	echo "Creating mysql emulation functions failed!"
254
+	merr "Creating mysql emulation functions failed!"
255 255
 	exit 1
256 256
 fi
257 257
 
258 258
 for TABLE in $STANDARD_MODULES; do
259
-    echo "Creating core table: $TABLE"
259
+    mdbg "Creating core table: $TABLE"
260 260
     sql_query "$1" < $DB_SCHEMA/$TABLE-create.sql
261 261
     if [ $? -ne 0 ] ; then
262
-	echo "Creating core tables failed!"
262
+	merr "Creating core tables failed!"
263 263
 	exit 1
264 264
     fi
265 265
 done
266 266
 
267 267
 sql_query "$1" "CREATE USER $DBRWUSER WITH PASSWORD '$DBRWPW';
268
-		CREATE USER $DBROUSER WITH PASSWORD '$DBROPW';
269
-		GRANT ALL PRIVILEGES ON TABLE version, acc, acc_id_seq, address, address_id_seq, 
268
+		CREATE USER $DBROUSER WITH PASSWORD '$DBROPW';"
269
+if [ $? -ne 0 ] ; then
270
+	mwarn "Create user in database failed, perhaps they allready exist? Try to continue.."
271
+fi
272
+
273
+sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE version, acc, acc_id_seq, address, address_id_seq, 
270 274
 		aliases, aliases_id_seq, dbaliases, dbaliases_id_seq, domain, domain_id_seq, 
271 275
 		grp, grp_id_seq, gw, gw_id_seq, gw_grp, gw_grp_grp_id_seq, lcr, lcr_id_seq, 
272 276
 		location, location_id_seq, missed_calls, missed_calls_id_seq, pdt, pdt_id_seq, 
... ...
@@ -278,11 +166,11 @@ sql_query "$1" "CREATE USER $DBRWUSER WITH PASSWORD '$DBRWPW';
278 278
 		subscriber, trusted, uri, usr_preferences TO $DBROUSER;"
279 279
 
280 280
 if [ $? -ne 0 ] ; then
281
-	echo "Grant privileges to database failed!"
281
+	merr "Grant privileges to database failed!"
282 282
 	exit 1
283 283
 fi
284 284
 
285
-echo "Core OpenSER tables succesfully created."
285
+minfo "Core OpenSER tables succesfully created."
286 286
 
287 287
 echo -n "Install presence related tables ?(y/n):"
288 288
 read INPUT
... ...
@@ -310,16 +198,16 @@ fi
310 310
 presence_create () # pars: <database name>
311 311
 {
312 312
 if [ $# -ne 1 ] ; then
313
-	echo "presence_create function takes one param"
313
+	merr "presence_create function takes one param"
314 314
 	exit 1
315 315
 fi
316 316
 
317
-echo "creating presence tables into $1 ..."
317
+minfo "creating presence tables into $1 ..."
318 318
 
319 319
 sql_query "$1" < $DB_SCHEMA/presence-create.sql
320 320
 
321 321
 if [ $? -ne 0 ] ; then
322
-	echo "Failed to create presence tables!"
322
+	merr "Failed to create presence tables!"
323 323
 	exit 1
324 324
 fi
325 325
 
... ...
@@ -330,26 +218,28 @@ sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE 	active_watchers, active_watchers_
330 330
 		pua TO $DBROUSER;"
331 331
 
332 332
 if [ $? -ne 0 ] ; then
333
-	echo "Grant privileges to presences tables failed!"
333
+	merr "Grant privileges to presences tables failed!"
334 334
 	exit 1
335 335
 fi
336 336
 
337
-echo "Presence tables succesfully created."
337
+minfo "Presence tables succesfully created."
338 338
 }  # end presence_create
339 339
 
340 340
 
341 341
 extra_create () # pars: <database name>
342 342
 {
343 343
 if [ $# -ne 1 ] ; then
344
-	echo "extra_create function takes one param"
344
+	merr "extra_create function takes one param"
345 345
 	exit 1
346 346
 fi
347 347
 
348
+minfo "creating extra tables into $1 ..."
349
+
348 350
 for TABLE in $EXTRA_MODULES; do
349
-    echo "Creating extra table: $TABLE"
351
+    mdbg "Creating extra table: $TABLE"
350 352
     sql_query "$1" < $DB_SCHEMA/$TABLE-create.sql
351 353
     if [ $? -ne 0 ] ; then
352
-	echo "Creating extra tables failed!"
354
+	merr "Creating extra tables failed!"
353 355
 	exit 1
354 356
     fi
355 357
 done
... ...
@@ -362,31 +252,22 @@ sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE cpl, cpl_id_seq, imc_members,
362 362
 		domainpolicy TO $DBROUSER;"
363 363
 
364 364
 if [ $? -ne 0 ] ; then
365
-	echo "Grant privileges to extra tables failed!"
366
-	exit 1
367
-fi
368
-
369
-
370
-echo "creating extra tables into $1 ..."
371
-
372
-
373
-if [ $? -ne 0 ] ; then
374
-	echo "Failed to create extra tables!"
365
+	merr "Grant privileges to extra tables failed!"
375 366
 	exit 1
376 367
 fi
377 368
 
378
-echo "Extra tables succesfully created."
369
+minfo "Extra tables succesfully created."
379 370
 }  # end extra_create
380 371
 
381 372
 
382 373
 serweb_create () # pars: <database name>
383 374
 {
384 375
 if [ $# -ne 1 ] ; then
385
-	echo "serweb_create function takes one param"
376
+	merr "serweb_create function takes one param"
386 377
 	exit 1
387 378
 fi
388 379
 
389
-echo "creating serweb tables into $1 ..."
380
+minfo "creating serweb tables into $1 ..."
390 381
 
391 382
 # Extend table 'subscriber' with serweb specific columns
392 383
 # It would be easier to drop the table and create a new one,
... ...
@@ -427,14 +308,14 @@ sql_query "$1" "ALTER TABLE subscriber ADD COLUMN phplib_id varchar(32);
427 427
 		greeting = DEFAULT, allow_find = DEFAULT;"
428 428
 
429 429
 if [ $? -ne 0 ] ; then
430
-	echo "Failed to alter subscriber table for serweb!"
430
+	merr "Failed to alter subscriber table for serweb!"
431 431
 	exit 1
432 432
 fi
433 433
 
434 434
 sql_query "$1" < $DB_SCHEMA/serweb-create.sql
435 435
 
436 436
 if [ $? -ne 0 ] ; then
437
-	echo "Failed to create presence tables!"
437
+	merr "Failed to create presence tables!"
438 438
 	exit 1
439 439
 fi
440 440
 
... ...
@@ -445,7 +326,7 @@ sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE phonebook, phonebook_id_seq, pendi
445 445
 		server_monitoring_agg, usr_preferences_types, admin_privileges to $DBROUSER;" 
446 446
 
447 447
 if [ $? -ne 0 ] ; then
448
-	echo "Grant privileges to serweb tables failed!"
448
+	merr "Grant privileges to serweb tables failed!"
449 449
 	exit 1
450 450
 fi
451 451
 
... ...
@@ -466,9 +347,10 @@ if [ -z "$NO_USER_INIT" ] ; then
466 466
 			VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
467 467
 
468 468
 	if [ $? -ne 0 ] ; then
469
-		echo "Failed to create serweb credentials tables!"
469
+		merr "Failed to create serweb credentials tables!"
470 470
 		exit 1
471 471
 	fi
472
+	serweb_message
472 473
 fi
473 474
 
474 475
 # emulate mysql proprietary functions used by the serweb in postgresql
... ...
@@ -477,152 +359,9 @@ sql_query "$1" "CREATE FUNCTION truncate(numeric, int) RETURNS numeric AS 'SELEC
477 477
 		AS result' LANGUAGE 'sql';"
478 478
 
479 479
 if [ $? -ne 0 ] ; then
480
-	echo "Failed to create mysql emulation functions for serweb!"
480
+	merr "Failed to create mysql emulation functions for serweb!"
481 481
 	exit 1
482 482
 fi
483 483
 
484
-echo "SERWEB tables succesfully created."
485
-
486
-serweb_message
484
+minfo "SERWEB tables succesfully created."
487 485
 }  # end serweb_create
488
-
489
-
490
-
491
-#export PW
492
-#if [ "$#" -ne 0 ]; then
493
-#  prompt_pw
494
-#fi
495
-
496
-case $1 in
497
-#	reinstall)
498
-#
499
-#		#1 create a backup database (named *_bak)
500
-#		echo "creating backup database"
501
-#		openser_backup $DBNAME
502
-#		if [ "$?" -ne 0 ] ; then
503
-#			echo "reinstall: openser_backup failed"
504
-#			exit 1
505
-#		fi
506
-#		#2 dump original database and change names in it
507
-#		echo "dumping table content ($DBNAME)"
508
-#		tmp_file=/tmp/openser_mysql.$$
509
-#		openser_dump $DBNAME  > $tmp_file
510
-#		if [ "$?" -ne 0 ] ; then
511
-#			echo "reinstall: dumping original db failed"
512
-#			exit 1
513
-#		fi
514
-#		sed "s/[uU][sS][eE][rR]_[iI][dD]/user/g" $tmp_file |
515
-#			sed "s/[uU][sS][eE][rR]\($\|[^a-zA-Z]\)/$USERCOL\1/g" |
516
-#			sed "s/[rR][eE][aA][lL][mM]/domain/g"> ${tmp_file}.2
517
-#		#3 drop original database
518
-#		echo "dropping table ($DBNAME)"
519
-#		openser_drop $DBNAME
520
-#		if [ "$?" -ne 0 ] ; then
521
-#			echo "reinstall: dropping table failed"
522
-#			rm $tmp_file*
523
-#			exit 1
524
-#		fi
525
-#		#4 change names in table definition and restore
526
-#		echo "creating new structures"
527
-#		NO_USER_INIT="yes"
528
-#		openser_create $DBNAME
529
-#		if [ "$?" -ne 0 ] ; then
530
-#			echo "reinstall: creating new table failed"
531
-#			rm $tmp_file*
532
-#			exit 1
533
-#		fi
534
-#		#5 restoring table content
535
-#		echo "restoring table content"
536
-#		openser_restore $DBNAME ${tmp_file}.2
537
-#		if [ "$?" -ne 0 ] ; then
538
-#			echo "reinstall: restoring table failed"
539
-#			rm $tmp_file*
540
-#			exit 1
541
-#		fi
542
-#
543
-##		rm $tmp_file*
544
-#		exit 0
545
-#		;;
546
-#	copy)
547
-#		# copy database to some other name
548
-#		shift
549
-#		if [ $# -ne 1 ]; then
550
-#			usage
551
-#			exit 1
552
-#		fi
553
-#		tmp_file=/tmp/openser_mysql.$$
554
-#		openser_dump $DBNAME  > $tmp_file
555
-#		ret=$?
556
-#		if [ "$ret" -ne 0 ]; then
557
-#			rm $tmp_file
558
-#			exit $ret
559
-#		fi
560
-#		NO_USER_INIT="yes"
561
-#		openser_create $1
562
-#		ret=$?
563
-#		if [ "$ret" -ne 0 ]; then
564
-#			rm $tmp_file
565
-#			exit $ret
566
-#		fi
567
-#		openser_restore $1 $tmp_file
568
-#		ret=$?
569
-#		rm $tmp_file
570
-#		exit $ret
571
-#		;;
572
-#	backup)
573
-#		# backup current database
574
-#		openser_dump $DBNAME
575
-#		exit $?
576
-#		;;
577
-#	restore)
578
-#		# restore database from a backup
579
-#		shift
580
-#		if [ $# -ne 1 ]; then
581
-#			usage
582
-#			exit 1
583
-#		fi
584
-#		openser_restore $DBNAME $1
585
-#		exit $?
586
-#		;;
587
-	create)
588
-		# create new database structures
589
-		shift
590
-		if [ $# -eq 1 ] ; then
591
-			DBNAME="$1"
592
-		fi
593
-		openser_create $DBNAME
594
-		exit $?
595
-		;;
596
-	serweb)
597
-		serweb_create $DBNAME
598
-		exit $?
599
-		;;
600
-	presence)
601
-		presence_create $DBNAME
602
-		exit $?
603
-		;;
604
-	extra)
605
-		extra_create $DBNAME
606
-		exit $?
607
-		;;
608
-	drop)
609
-		# delete openser database
610
-		openser_drop $DBNAME
611
-		exit $?
612
-		;;
613
-	reinit)
614
-		# delete database and create a new one
615
-		openser_drop $DBNAME
616
-		ret=$?
617
-		if [ "$ret" -ne 0 ]; then
618
-			exit $ret
619
-		fi
620
-		openser_create $DBNAME
621
-		exit $?
622
-		;;
623
-	*)
624
-		usage
625
-		exit 1;
626
-		;;
627
-esac
628
-