Browse code

utils: Change sh(1) "test ==" usage to "="

The POSIX sh(1) specification says that strings are compared with
test(1) (also "[") with "=". Bash accepts "==" and this leads to
non-portable code. This commit simply changes "==" within test/[ to
"=".

Greg Troxel authored on 29/11/2019 01:53:23 • Henning Westerholt committed on 29/11/2019 17:39:58
Showing 1 changed files
... ...
@@ -153,7 +153,7 @@ kamailio_dump()  # pars: <database name>
153 153
 		merr "kamailio_dump function takes two param"
154 154
 		exit 1
155 155
 	fi
156
-	if [ "$USED_DBENGINE" == "oracle" ]; then
156
+	if [ "$USED_DBENGINE" = "oracle" ]; then
157 157
 		oracle_dump $1 $2
158 158
 	elif [ "$PW" = "" ] ; then
159 159
 		$DUMP_CMD $1 > $2
... ...
@@ -174,7 +174,7 @@ kamailio_restore() #pars: <database name> <filename>
174 174
 		merr "kamailio_restore function takes two params"
175 175
 		exit 1
176 176
 	fi
177
-	if [ "$USED_DBENGINE" == "oracle" ]; then
177
+	if [ "$USED_DBENGINE" = "oracle" ]; then
178 178
 		oracle_restore $1 $2
179 179
 	else
180 180
 		sql_query $1 < $2
... ...
@@ -290,7 +290,7 @@ kamailio_pframework() #pars: <action>
290 290
 case $1 in
291 291
 	copy)
292 292
 		# copy database to some other name
293
-		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
293
+		if [ "$USED_DBENGINE" = "berkeley" -o "$USED_DBENGINE" = "dbtext" ] ; then
294 294
 			merr "$USED_DBENGINE don't support this operation"
295 295
 			exit 1
296 296
 		fi
... ...
@@ -323,7 +323,7 @@ case $1 in
323 323
 		exit $ret
324 324
 		;;
325 325
 	backup)
326
-		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
326
+		if [ "$USED_DBENGINE" = "berkeley" -o "$USED_DBENGINE" = "dbtext" ] ; then
327 327
 			merr "$USED_DBENGINE don't support this operation"
328 328
 			exit 1
329 329
 		fi
... ...
@@ -337,7 +337,7 @@ case $1 in
337 337
 		exit $?
338 338
 		;;
339 339
 	restore)
340
-		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
340
+		if [ "$USED_DBENGINE" = "berkeley" -o "$USED_DBENGINE" = "dbtext" ] ; then
341 341
 			merr "$USED_DBENGINE don't support this operation"
342 342
 			exit 1
343 343
 		fi
Browse code

kamctl: updated the version for kamctl and kamdbctl

Daniel-Constantin Mierla authored on 08/10/2019 10:25:14
Showing 1 changed files
... ...
@@ -5,7 +5,7 @@
5 5
 #===================================================================
6 6
 
7 7
 ### version for this script
8
-VERSION='5.2.0'
8
+VERSION='5.4.0'
9 9
 
10 10
 PATH=$PATH:/usr/local/sbin/
11 11
 
Browse code

kamdbctl: warn that drop cmd will drop existing DB, ask for confirmation (GH #1858)

- warn that the drop command will drop existing DB, ask for confirmation
- manually merge pull request GH #1858 from fredposner, fred at qxork dot com

Henning Westerholt authored on 18/02/2019 19:44:29
Showing 1 changed files
... ...
@@ -375,6 +375,14 @@ case $1 in
375 375
 	drop)
376 376
 		# delete kamailio database
377 377
 		# create new database structures
378
+
379
+		# confirm dropping of database
380
+		echo -e "This will drop your current database.\nIt is recommended to first backup your database.\n"
381
+		get_answer ask "Continue with drop? (y/n): "
382
+		if [ "$ANSWER" != "y" ]; then
383
+			exit 1
384
+		fi
385
+
378 386
 		shift
379 387
 		if [ $# -eq 1 ] ; then
380 388
 			DBNAME="$1"
Browse code

kamdbctl: added verification before reinit (#1852)

kamdbctl: added verification before reinit command (GH #1852)
- add get_answer and warning that reinit command will drop existing database
- even seasoned users forget and ther is no backing out, results in data loss

Fred Posner authored on 17/02/2019 18:38:33 • Henning Westerholt committed on 17/02/2019 18:38:33
Showing 1 changed files
... ...
@@ -386,6 +386,14 @@ case $1 in
386 386
 	reinit)
387 387
 		# delete database and create a new one
388 388
 		# create new database structures
389
+
390
+		# confirm dropping of database
391
+		echo -e "This will drop your current database and create a new one.\nIt is recommended to first backup your database.\n"
392
+		get_answer ask "Continue with reinit? (y/n): "
393
+		if [ "$ANSWER" != "y" ]; then
394
+			exit 1
395
+		fi
396
+
389 397
 		shift
390 398
 		if [ $# -eq 1 ] ; then
391 399
 			DBNAME="$1"
Browse code

utils: kamctl, kamdbctl improve POSIX compatibility for embedded systems (#1815)

- Use portable "#!/bin/sh" shebang. This may still be a symlink to bash (or some other shell).
- Also replace the redirection to "/dev/stderr" with a POSIX redirection to stderr. "/dev/stderr" is not available on all systems and is also not recognized by all shells (example: ash). On systems without a working "/dev/stderr" the user will not see the prompts etc.
- Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>

micmac1 authored on 20/01/2019 19:58:11 • Henning Westerholt committed on 20/01/2019 19:58:11
Showing 1 changed files
... ...
@@ -1,4 +1,4 @@
1
-#!/bin/bash
1
+#!/bin/sh
2 2
 #
3 3
 # control tool for maintaining Kamailio databases
4 4
 #
Browse code

kamdbctl: remove not working db migrate command

- remove db migrate implementation in kamdbctl, .base, .mysql and .db_berkley files
- it was not working for mysql anyway, and not implemented for berkleydb
- this state was already documtend some weeks ago in commit 52a8def8d2a3e831

Henning Westerholt authored on 03/03/2018 18:08:30
Showing 1 changed files
... ...
@@ -288,29 +288,6 @@ kamailio_pframework() #pars: <action>
288 288
 
289 289
 
290 290
 case $1 in
291
-	migrate)
292
-		if [ "$USED_DBENGINE" != "mysql" ] ; then
293
-			merr "$USED_DBENGINE don't support migrate operation"
294
-			exit 1
295
-		fi
296
-		if [ $# -ne 3 ] ; then
297
-			merr "migrate requires 2 parameters: old and new database"
298
-			exit 1
299
-		fi
300
-		# create new database
301
-		minfo "Creating new Database $3...."
302
-		NO_USER_INIT="yes"
303
-		kamailio_create $3
304
-		if [ "$?" -ne 0 ] ; then
305
-			echo "migrate: creating new database failed"
306
-			exit 1
307
-		fi
308
-		# migrate data
309
-		minfo "Migrating data from $2 to $3...."
310
-		migrate_db $2 $3
311
-		minfo "Migration successfully completed."
312
-		exit 0;
313
-		;;
314 291
 	copy)
315 292
 		# copy database to some other name
316 293
 		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
Browse code

utils: kamdbctl - version set to 5.2.0

Daniel-Constantin Mierla authored on 29/01/2018 08:11:24
Showing 1 changed files
... ...
@@ -1,11 +1,11 @@
1
-#!/bin/bash 
1
+#!/bin/bash
2 2
 #
3 3
 # control tool for maintaining Kamailio databases
4 4
 #
5 5
 #===================================================================
6 6
 
7 7
 ### version for this script
8
-VERSION='4.4.0'
8
+VERSION='5.2.0'
9 9
 
10 10
 PATH=$PATH:/usr/local/sbin/
11 11
 
Browse code

kamctl: updated version of the scripts

Daniel-Constantin Mierla authored on 08/12/2015 21:56:53
Showing 1 changed files
... ...
@@ -5,7 +5,7 @@
5 5
 #===================================================================
6 6
 
7 7
 ### version for this script
8
-VERSION='4.2.0'
8
+VERSION='4.4.0'
9 9
 
10 10
 PATH=$PATH:/usr/local/sbin/
11 11
 
Browse code

kamdbctl: divert stderr when searching for greadlink

Daniel-Constantin Mierla authored on 02/11/2015 14:23:31
Showing 1 changed files
... ...
@@ -16,12 +16,12 @@ TEST="false"
16 16
 ### include resource files, if any
17 17
 
18 18
 # check for rc file at same location with kamdbctl
19
-which greadlink > /dev/null
19
+which greadlink > /dev/null 2>&1
20 20
 ret=$?
21 21
 if [ $ret -eq 0 ] ; then
22 22
 	KAMCTLFULLPATH=$(greadlink -f "$0")
23 23
 else
24
-	which readlink > /dev/null
24
+	which readlink > /dev/null 2>&1
25 25
 	ret=$?
26 26
 	if [ $ret -eq 0 ] ; then
27 27
 		KAMCTLFULLPATH=$(readlink -f "$0")
Browse code

kamdbctl: search for greadlink first

- bsd version of readlink is different than gnu version

Daniel-Constantin Mierla authored on 12/10/2014 22:06:18
Showing 1 changed files
... ...
@@ -14,15 +14,27 @@ PATH=$PATH:/usr/local/sbin/
14 14
 TEST="false"
15 15
 
16 16
 ### include resource files, if any
17
-which readlink > /dev/null
17
+
18
+# check for rc file at same location with kamdbctl
19
+which greadlink > /dev/null
18 20
 ret=$?
19 21
 if [ $ret -eq 0 ] ; then
20
-	KAMCTLFULLPATH=$(readlink -f "$0")
22
+	KAMCTLFULLPATH=$(greadlink -f "$0")
23
+else
24
+	which readlink > /dev/null
25
+	ret=$?
26
+	if [ $ret -eq 0 ] ; then
27
+		KAMCTLFULLPATH=$(readlink -f "$0")
28
+	fi
29
+fi
30
+if [ -n "$KAMCTLFULLPATH" ] ; then
21 31
 	KAMCTLDIRPATH=$(dirname "$KAMCTLFULLPATH")
22 32
 	if [ -f $KAMCTLDIRPATH/kamctlrc ]; then
23 33
 		. $KAMCTLDIRPATH/kamctlrc
24 34
 	fi
25 35
 fi
36
+
37
+# check for rc file at standard locations
26 38
 if [ -f /etc/kamailio/kamctlrc ]; then
27 39
 	. /etc/kamailio/kamctlrc
28 40
 fi
Browse code

kamdbctl: check if kamctlrc is in the same folder

Daniel-Constantin Mierla authored on 05/10/2014 08:08:20
Showing 1 changed files
... ...
@@ -1,11 +1,12 @@
1 1
 #!/bin/bash 
2 2
 #
3
-# $Id$
4
-#
5 3
 # control tool for maintaining Kamailio databases
6 4
 #
7 5
 #===================================================================
8 6
 
7
+### version for this script
8
+VERSION='4.2.0'
9
+
9 10
 PATH=$PATH:/usr/local/sbin/
10 11
 
11 12
 # for testing only, please don't enable this in production environments
... ...
@@ -13,6 +14,15 @@ PATH=$PATH:/usr/local/sbin/
13 14
 TEST="false"
14 15
 
15 16
 ### include resource files, if any
17
+which readlink > /dev/null
18
+ret=$?
19
+if [ $ret -eq 0 ] ; then
20
+	KAMCTLFULLPATH=$(readlink -f "$0")
21
+	KAMCTLDIRPATH=$(dirname "$KAMCTLFULLPATH")
22
+	if [ -f $KAMCTLDIRPATH/kamctlrc ]; then
23
+		. $KAMCTLDIRPATH/kamctlrc
24
+	fi
25
+fi
16 26
 if [ -f /etc/kamailio/kamctlrc ]; then
17 27
 	. /etc/kamailio/kamctlrc
18 28
 fi
... ...
@@ -30,9 +40,6 @@ if [ $TEST = "true" ]; then
30 40
 fi
31 41
 
32 42
 
33
-### version for this script
34
-VERSION='$Revision$'
35
-
36 43
 if [ -z "$MYDIR" ] ; then
37 44
 	MYDIR=`dirname $0`
38 45
 fi
Browse code

kamdbctl: new command add-tables

- creates only tables that are groupped under same id, thus have the sql
script in a file
- syntax: kamdbctl add-tables <gid>
- there has to be a <gid>-create.sql script
- eg: kamdbctl add-tables lcr

Daniel-Constantin Mierla authored on 27/08/2013 12:00:17
Showing 1 changed files
... ...
@@ -444,6 +444,23 @@ case $1 in
444 444
 		kamailio_db_revoke $DBNAME
445 445
 		exit $?
446 446
 		;;
447
+	add-tables)
448
+		if [ "$USED_DBENGINE" != "mysql" ] ; then
449
+			merr "$USED_DBENGINE don't support add-tables operation"
450
+			exit 1
451
+		fi
452
+		if [ $# -ne 2 ] ; then
453
+			merr "add-tables requires 1 parameter: group id of tables"
454
+			exit 1
455
+		fi
456
+		if [ -z "$DBNAME" ] ; then
457
+			merr "DBNAME is not set"
458
+			exit 1
459
+		fi
460
+
461
+		kamailio_add_tables $DBNAME $2
462
+		exit $?
463
+		;;
447 464
 	bdb|db_berkeley)
448 465
 		shift
449 466
 		kamailio_berkeley "$@"
Browse code

kamctl: added option to creat uid-related tables

- few more options to be able to create database only, grant or revoke
privileges from command line
- the extensions were added for mysql

Daniel-Constantin Mierla authored on 22/01/2013 23:45:17
Showing 1 changed files
... ...
@@ -372,6 +372,10 @@ case $1 in
372 372
 		extra_create $DBNAME
373 373
 		exit $?
374 374
 		;;
375
+	dbuid)
376
+		dbuid_create $DBNAME
377
+		exit $?
378
+		;;
375 379
 	drop)
376 380
 		# delete kamailio database
377 381
 		# create new database structures
... ...
@@ -398,6 +402,48 @@ case $1 in
398 402
 		kamailio_create $DBNAME
399 403
 		exit $?
400 404
 		;;
405
+	dbonly)
406
+		# create only an empty database
407
+		if [ "$USED_DBENGINE" != "mysql" ] ; then
408
+			merr "$USED_DBENGINE db engine doesn't support this operation"
409
+			exit 1
410
+		fi
411
+		shift
412
+		if [ $# -eq 1 ] ; then
413
+			DBNAME="$1"
414
+		fi
415
+
416
+		kamailio_db_create $DBNAME
417
+		exit $?
418
+		;;
419
+	grant)
420
+		# grant privileges to database
421
+		if [ "$USED_DBENGINE" != "mysql" ] ; then
422
+			merr "$USED_DBENGINE db engine doesn't support this operation"
423
+			exit 1
424
+		fi
425
+		shift
426
+		if [ $# -eq 1 ] ; then
427
+			DBNAME="$1"
428
+		fi
429
+
430
+		kamailio_db_grant $DBNAME
431
+		exit $?
432
+		;;
433
+	revoke)
434
+		# revoke privileges to database
435
+		if [ "$USED_DBENGINE" != "mysql" ] ; then
436
+			merr "$USED_DBENGINE db engine doesn't support this operation"
437
+			exit 1
438
+		fi
439
+		shift
440
+		if [ $# -eq 1 ] ; then
441
+			DBNAME="$1"
442
+		fi
443
+
444
+		kamailio_db_revoke $DBNAME
445
+		exit $?
446
+		;;
401 447
 	bdb|db_berkeley)
402 448
 		shift
403 449
 		kamailio_berkeley "$@"
Browse code

kamdbctl: fix presence tables provisioning

Ovidiu Sas authored on 21/01/2013 20:10:39
Showing 1 changed files
... ...
@@ -170,6 +170,12 @@ kamailio_restore() #pars: <database name> <filename>
170 170
 
171 171
 kamailio_pframework_create() #pars: none
172 172
 {
173
+	if [ -e $DEFAULT_CFG_DIR/pi_framework_sample ] ; then
174
+		get_answer ask "Sample already exists. Overwrite? (y/n): "
175
+		if [ "$ANSWER" != "y" ]; then
176
+			exit 1
177
+		fi
178
+	fi
173 179
 	touch $DEFAULT_CFG_DIR/pi_framework_sample
174 180
 	if [ $? -ne 0 ] ; then
175 181
 		merr "Unable to create $DEFAULT_CFG_DIR/pi_framework_sample"
... ...
@@ -191,7 +197,7 @@ kamailio_pframework_create() #pars: none
191 197
 
192 198
 	get_answer $INSTALL_PRESENCE_TABLES "Add provisionning framework for presence tables? (y/n): "
193 199
 	if [ "$ANSWER" = "y" ]; then
194
-		PI_MODULES="$PI_MODULES $PRESENCE_TABLES"
200
+		PI_PRESENCE_MODULES="TRUE"
195 201
 	fi
196 202
 
197 203
 	cat $DATA_DIR/xhttp_pi/pi_framework-00 > $DEFAULT_CFG_DIR/pi_framework_sample
... ...
@@ -202,6 +208,18 @@ kamailio_pframework_create() #pars: none
202 208
 			merr "Unable to configure: $TABLE - missing table descriptor"
203 209
 		fi
204 210
 	done
211
+	if [ "$PI_PRESENCE_MODULES" = "TRUE" ]; then
212
+		if [ -e $DATA_DIR/xhttp_pi/presence-table ]; then
213
+			cat $DATA_DIR/xhttp_pi/presence-table >> $DEFAULT_CFG_DIR/pi_framework_sample
214
+		else
215
+			merr "Unable to configure: presence - missing table descriptor"
216
+		fi
217
+		if [ -e $DATA_DIR/xhttp_pi/rls-table ]; then
218
+			cat $DATA_DIR/xhttp_pi/rls-table >> $DEFAULT_CFG_DIR/pi_framework_sample
219
+		else
220
+			merr "Unable to configure: rls - missing table descriptor"
221
+		fi
222
+	fi
205 223
 	cat $DATA_DIR/xhttp_pi/pi_framework-01 >> $DEFAULT_CFG_DIR/pi_framework_sample
206 224
 	for TABLE in $PI_MODULES; do
207 225
 		if [ -e $DATA_DIR/xhttp_pi/$TABLE-mod ]; then
... ...
@@ -210,6 +228,18 @@ kamailio_pframework_create() #pars: none
210 228
 			merr "Unable to configure: $TABLE - missing mod descriptor"
211 229
 		fi
212 230
 	done
231
+	if [ "$PI_PRESENCE_MODULES" = "TRUE" ]; then
232
+		if [ -e $DATA_DIR/xhttp_pi/presence-mod ]; then
233
+			cat $DATA_DIR/xhttp_pi/presence-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
234
+		else
235
+			merr "Unable to configure: presence - missing mod descriptor"
236
+		fi
237
+		if [ -e $DATA_DIR/xhttp_pi/rls-mod ]; then
238
+			cat $DATA_DIR/xhttp_pi/rls-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
239
+		else
240
+			merr "Unable to configure: rls - missing mod descriptor"
241
+		fi
242
+	fi
213 243
 	cat $DATA_DIR/xhttp_pi/pi_framework-02 >> $DEFAULT_CFG_DIR/pi_framework_sample
214 244
 
215 245
 	minfo "Sample provisionning framework saved as: $DEFAULT_CFG_DIR/pi_framework_sample"
Browse code

kamdbctl: new command - kamdbctl pframework create - creates a provisioning framework for the installed db tables

Ovidiu Sas authored on 10/01/2013 17:50:06
Showing 1 changed files
... ...
@@ -168,6 +168,76 @@ kamailio_restore() #pars: <database name> <filename>
168 168
 }
169 169
 
170 170
 
171
+kamailio_pframework_create() #pars: none
172
+{
173
+	touch $DEFAULT_CFG_DIR/pi_framework_sample
174
+	if [ $? -ne 0 ] ; then
175
+		merr "Unable to create $DEFAULT_CFG_DIR/pi_framework_sample"
176
+		exit 1
177
+	fi
178
+
179
+	if [ -d "$DATA_DIR/xhttp_pi" ] ; then
180
+		PI_MODULES="$STANDARD_MODULES"
181
+	else
182
+		merr "Please install first the xhttp_pi module"
183
+		exit 1
184
+	fi
185
+
186
+
187
+	get_answer $INSTALL_EXTRA_TABLES "Add provisionning framework for extra tables? (y/n): "
188
+	if [ "$ANSWER" = "y" ]; then
189
+		PI_MODULES="$PI_MODULES $EXTRA_MODULES"
190
+	fi
191
+
192
+	get_answer $INSTALL_PRESENCE_TABLES "Add provisionning framework for presence tables? (y/n): "
193
+	if [ "$ANSWER" = "y" ]; then
194
+		PI_MODULES="$PI_MODULES $PRESENCE_TABLES"
195
+	fi
196
+
197
+	cat $DATA_DIR/xhttp_pi/pi_framework-00 > $DEFAULT_CFG_DIR/pi_framework_sample
198
+	for TABLE in $PI_MODULES; do
199
+		if [ -e $DATA_DIR/xhttp_pi/$TABLE-table ]; then
200
+			cat $DATA_DIR/xhttp_pi/$TABLE-table >> $DEFAULT_CFG_DIR/pi_framework_sample
201
+		else
202
+			merr "Unable to configure: $TABLE - missing table descriptor"
203
+		fi
204
+	done
205
+	cat $DATA_DIR/xhttp_pi/pi_framework-01 >> $DEFAULT_CFG_DIR/pi_framework_sample
206
+	for TABLE in $PI_MODULES; do
207
+		if [ -e $DATA_DIR/xhttp_pi/$TABLE-mod ]; then
208
+			cat $DATA_DIR/xhttp_pi/$TABLE-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
209
+		else
210
+			merr "Unable to configure: $TABLE - missing mod descriptor"
211
+		fi
212
+	done
213
+	cat $DATA_DIR/xhttp_pi/pi_framework-02 >> $DEFAULT_CFG_DIR/pi_framework_sample
214
+
215
+	minfo "Sample provisionning framework saved as: $DEFAULT_CFG_DIR/pi_framework_sample"
216
+}
217
+
218
+kamailio_pframework() #pars: <action>
219
+{
220
+	if [ $# -ne 1 ] ; then
221
+		merr "kamailio_pframework function takes one parameter"
222
+		exit 1
223
+	fi
224
+
225
+	case $1 in
226
+		create)
227
+			shift
228
+			kamailio_pframework_create "$@"
229
+			exit $?
230
+			;;
231
+		*)
232
+			merr "Unexpected pframework action: $1"
233
+			usage
234
+			exit 1
235
+			;;
236
+	esac
237
+}
238
+
239
+
240
+
171 241
 case $1 in
172 242
 	migrate)
173 243
 		if [ "$USED_DBENGINE" != "mysql" ] ; then
... ...
@@ -303,6 +373,11 @@ case $1 in
303 373
 		kamailio_berkeley "$@"
304 374
 		exit $?
305 375
 		;;
376
+	pframework)
377
+		shift
378
+		kamailio_pframework "$@"
379
+		exit $?
380
+		;;
306 381
 	version)
307 382
 		echo  "$0 $VERSION"
308 383
 		;;
Browse code

kamctl: replaced openser with kamailio in variable and function names

Daniel-Constantin Mierla authored on 23/10/2012 14:49:29
Showing 1 changed files
... ...
@@ -128,10 +128,10 @@ fi
128 128
 
129 129
 
130 130
 # dump all rows
131
-openser_dump()  # pars: <database name>
131
+kamailio_dump()  # pars: <database name>
132 132
 {
133 133
 	if [ $# -ne 2 ] ; then
134
-		merr "openser_dump function takes two param"
134
+		merr "kamailio_dump function takes two param"
135 135
 		exit 1
136 136
 	fi
137 137
 	if [ "$USED_DBENGINE" == "oracle" ]; then
... ...
@@ -149,10 +149,10 @@ openser_dump()  # pars: <database name>
149 149
 }
150 150
 
151 151
 
152
-openser_restore() #pars: <database name> <filename>
152
+kamailio_restore() #pars: <database name> <filename>
153 153
 {
154 154
 	if [ $# -ne 2 ] ; then
155
-		merr "openser_restore function takes two params"
155
+		merr "kamailio_restore function takes two params"
156 156
 		exit 1
157 157
 	fi
158 158
 	if [ "$USED_DBENGINE" == "oracle" ]; then
... ...
@@ -181,7 +181,7 @@ case $1 in
181 181
 		# create new database
182 182
 		minfo "Creating new Database $3...."
183 183
 		NO_USER_INIT="yes"
184
-		openser_create $3
184
+		kamailio_create $3
185 185
 		if [ "$?" -ne 0 ] ; then
186 186
 			echo "migrate: creating new database failed"
187 187
 			exit 1
... ...
@@ -208,20 +208,20 @@ case $1 in
208 208
 			exit $?
209 209
 		fi
210 210
 		tmp_file=`mktemp /tmp/kamdbctl.XXXXXXXXXX` || exit 1
211
-		openser_dump $DBNAME $tmp_file
211
+		kamailio_dump $DBNAME $tmp_file
212 212
 		ret=$?
213 213
 		if [ "$ret" -ne 0 ]; then
214 214
 			rm $tmp_file
215 215
 			exit $ret
216 216
 		fi
217 217
 		NO_USER_INIT="yes"
218
-		openser_create $1
218
+		kamailio_create $1
219 219
 		ret=$?
220 220
 		if [ "$ret" -ne 0 ]; then
221 221
 			rm $tmp_file
222 222
 			exit $ret
223 223
 		fi
224
-		openser_restore $1 $tmp_file
224
+		kamailio_restore $1 $tmp_file
225 225
 		ret=$?
226 226
 		rm -f $tmp_file
227 227
 		exit $ret
... ...
@@ -237,7 +237,7 @@ case $1 in
237 237
 			usage
238 238
 			exit 1
239 239
 		fi
240
-		openser_dump $DBNAME $1
240
+		kamailio_dump $DBNAME $1
241 241
 		exit $?
242 242
 		;;
243 243
 	restore)
... ...
@@ -251,7 +251,7 @@ case $1 in
251 251
 			usage
252 252
 			exit 1
253 253
 		fi
254
-		openser_restore $DBNAME $1
254
+		kamailio_restore $DBNAME $1
255 255
 		exit $?
256 256
 		;;
257 257
 	create)
... ...
@@ -261,7 +261,7 @@ case $1 in
261 261
 			DBNAME="$1"
262 262
 		fi
263 263
 
264
-		openser_create $DBNAME
264
+		kamailio_create $DBNAME
265 265
 		exit $?
266 266
 		;;
267 267
 	presence)
... ...
@@ -273,14 +273,14 @@ case $1 in
273 273
 		exit $?
274 274
 		;;
275 275
 	drop)
276
-		# delete openser database
276
+		# delete kamailio database
277 277
 		# create new database structures
278 278
 		shift
279 279
 		if [ $# -eq 1 ] ; then
280 280
 			DBNAME="$1"
281 281
 		fi
282 282
 
283
-		openser_drop $DBNAME
283
+		kamailio_drop $DBNAME
284 284
 		exit $?
285 285
 		;;
286 286
 	reinit)
... ...
@@ -290,17 +290,17 @@ case $1 in
290 290
 		if [ $# -eq 1 ] ; then
291 291
 			DBNAME="$1"
292 292
 		fi
293
-		openser_drop $DBNAME
293
+		kamailio_drop $DBNAME
294 294
 		ret=$?
295 295
 		if [ "$ret" -ne 0 ]; then
296 296
 			exit $ret
297 297
 		fi
298
-		openser_create $DBNAME
298
+		kamailio_create $DBNAME
299 299
 		exit $?
300 300
 		;;
301 301
 	bdb|db_berkeley)
302 302
 		shift
303
-		openser_berkeley "$@"
303
+		kamailio_berkeley "$@"
304 304
 		exit $?
305 305
 		;;
306 306
 	version)
Browse code

utils: add sqlite support to kamctl/kamdbctl

- sql scripts copied from postgres versions and converted to sqlite
(only major change was: sed s/SERIAL/INTEGER/)
- kamdbctl.sqlite based on kamdbctl.postgres with permissions stuff
removed (sqlite has unix file permissions only) and some mysql
emulation removed too
- no real ro-mode

Natanael Copa authored on 26/05/2011 07:18:44 • Timo Teräs committed on 26/05/2011 07:35:37
Showing 1 changed files
... ...
@@ -108,6 +108,15 @@ case $DBENGINE in
108 108
 			merr "could not load the script in $MYLIBDIR/kamdbctl.db_berkeley for database engine $DBENGINE"
109 109
 		fi
110 110
 		;;
111
+	SQLITE|sqlite)
112
+		if [ -f "$MYLIBDIR/kamdbctl.sqlite" ]; then
113
+			. "$MYLIBDIR/kamdbctl.sqlite"
114
+			USED_DBENGINE="sqlite"
115
+			DBNAME=$DB_PATH
116
+		else
117
+			merr "could not load the script in $MYLIBDIR/kamdbctl.sqlite for database engine $DBENGINE"
118
+		fi
119
+		;;
111 120
 esac
112 121
 
113 122
 if [ -z "$USED_DBENGINE" ] ; then
... ...
@@ -194,6 +203,10 @@ case $1 in
194 203
 			usage
195 204
 			exit 1
196 205
 		fi
206
+		if [ "$USED_DBENGINE" = "sqlite" ]; then
207
+			cp $DB_PATH $1
208
+			exit $?
209
+		fi
197 210
 		tmp_file=`mktemp /tmp/kamdbctl.XXXXXXXXXX` || exit 1
198 211
 		openser_dump $DBNAME $tmp_file
199 212
 		ret=$?
Browse code

kamctl: moved from tools/ to utils/

- mv tools/kamctl utils/kamctl
- updated srdb1 Makefile and test/unit/include/common with the new
kamctl path

Andrei Pelinescu-Onciul authored on 09/10/2009 12:05:15
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,300 @@
1
+#!/bin/bash 
2
+#
3
+# $Id$
4
+#
5
+# control tool for maintaining Kamailio databases
6
+#
7
+#===================================================================
8
+
9
+PATH=$PATH:/usr/local/sbin/
10
+
11
+# for testing only, please don't enable this in production environments
12
+# as this introduce security risks
13
+TEST="false"
14
+
15
+### include resource files, if any
16
+if [ -f /etc/kamailio/kamctlrc ]; then
17
+	. /etc/kamailio/kamctlrc
18
+fi
19
+if [ -f /usr/local/etc/kamailio/kamctlrc ]; then
20
+	. /usr/local/etc/kamailio/kamctlrc
21
+fi
22
+if [ -f ~/.kamctlrc ]; then
23
+	. ~/.kamctlrc
24
+fi
25
+
26
+if [ $TEST = "true" ]; then
27
+	if [ -f ./kamctlrc ]; then
28
+		. ./kamctlrc
29
+	fi
30
+fi
31
+
32
+
33
+### version for this script
34
+VERSION='$Revision$'
35
+
36
+if [ -z "$MYDIR" ] ; then
37
+	MYDIR=`dirname $0`
38
+fi
39
+
40
+if [ -z "$MYLIBDIR" ] ; then
41
+	MYLIBDIR="/usr/local/lib/kamailio/kamctl"
42
+	if [ ! -d "$MYLIBDIR" ]; then
43
+		MYLIBDIR=$MYDIR
44
+	fi
45
+fi
46
+
47
+
48
+##### ------------------------------------------------ #####
49
+### load base functions
50
+#
51
+if [ -f "$MYLIBDIR/kamdbctl.base" ]; then
52
+	. "$MYLIBDIR/kamdbctl.base"
53
+else
54
+	echo -e "Cannot load core functions '$MYLIBDIR/kamdbctl.base' - exiting ...\n"
55
+	exit -1
56
+fi
57
+
58
+#
59
+##### ------------------------------------------------ #####
60
+### DBENGINE
61
+#
62
+unset USED_DBENGINE
63
+if [ -z "$DBENGINE" ] ; then
64
+	merr "database engine not specified, please setup one in the config script"
65
+	exit 1
66
+fi
67
+
68
+case $DBENGINE in
69
+	MYSQL|mysql|MySQL)
70
+		if [ -f "$MYLIBDIR/kamdbctl.mysql" ]; then
71
+			. "$MYLIBDIR/kamdbctl.mysql"
72
+			USED_DBENGINE="mysql"
73
+		else
74
+			merr "could not load the script in $MYLIBDIR/kamdbctl.mysql for database engine $DBENGINE"
75
+		fi
76
+		;;
77
+	PGSQL|pgsql|postgres|postgresql|POSTGRESQL)
78
+		if [ -f "$MYLIBDIR/kamdbctl.pgsql" ]; then
79
+			. "$MYLIBDIR/kamdbctl.pgsql"
80
+			USED_DBENGINE="postgres"
81
+		else
82
+			merr "could not load the script in $MYLIBDIR/kamdbctl.pgsql for database engine $DBENGINE"
83
+		fi
84
+		;;
85
+	ORACLE|oracle|Oracle)
86
+		if [ -f "$MYLIBDIR/kamdbctl.oracle" ]; then
87
+			. "$MYLIBDIR/kamdbctl.oracle"
88
+			USED_DBENGINE="oracle"
89
+		else
90
+			merr "could not load the script in $MYLIBDIR/kamdbctl.oracle for database engine $DBENGINE"
91
+		fi
92
+		;;
93
+	DBTEXT|dbtext|textdb)
94
+		if [ -f "$MYLIBDIR/kamdbctl.dbtext" ]; then
95
+			. "$MYLIBDIR/kamdbctl.dbtext"
96
+			USED_DBENGINE="dbtext"
97
+			DBNAME=$DB_PATH
98
+		else
99
+			merr "could not load the script in $MYLIBDIR/kamdbctl.dbtext for database engine $DBENGINE"
100
+		fi
101
+		;;
102
+	DB_BERKELEY|db_berkeley|BERKELEY|berkeley)
103
+		if [ -f "$MYLIBDIR/kamdbctl.db_berkeley" ]; then
104
+			. "$MYLIBDIR/kamdbctl.db_berkeley"
105
+			USED_DBENGINE="berkeley"
106
+			DBNAME=$DB_PATH
107
+		else
108
+			merr "could not load the script in $MYLIBDIR/kamdbctl.db_berkeley for database engine $DBENGINE"
109
+		fi
110
+		;;
111
+esac
112
+
113
+if [ -z "$USED_DBENGINE" ] ; then
114
+	merr "database engine not loaded - tried '$DBENGINE'"
115
+	exit 1
116
+else
117
+	mdbg "database engine '$USED_DBENGINE' loaded"
118
+fi
119
+
120
+
121
+# dump all rows
122
+openser_dump()  # pars: <database name>
123
+{
124
+	if [ $# -ne 2 ] ; then
125
+		merr "openser_dump function takes two param"
126
+		exit 1
127
+	fi
128
+	if [ "$USED_DBENGINE" == "oracle" ]; then
129
+		oracle_dump $1 $2
130
+	elif [ "$PW" = "" ] ; then
131
+		$DUMP_CMD $1 > $2
132
+	else
133
+		$DUMP_CMD "-p$PW" $1 > $2
134
+	fi
135
+	if [ "$?" -ne 0 ]; then
136
+			merr "db dump failed"
137
+			exit 1
138
+	fi
139
+	minfo "db dump successful"
140
+}
141
+
142
+
143
+openser_restore() #pars: <database name> <filename>
144
+{
145
+	if [ $# -ne 2 ] ; then
146
+		merr "openser_restore function takes two params"
147
+		exit 1
148
+	fi
149
+	if [ "$USED_DBENGINE" == "oracle" ]; then
150
+		oracle_restore $1 $2
151
+	else
152
+		sql_query $1 < $2
153
+	fi
154
+	if [ "$?" -ne 0 ]; then
155
+			merr "db restore failed"
156
+			exit 1
157
+	fi
158
+	minfo "db restore successful"
159
+}
160
+
161
+
162
+case $1 in
163
+	migrate)
164
+		if [ "$USED_DBENGINE" != "mysql" ] ; then
165
+			merr "$USED_DBENGINE don't support migrate operation"
166
+			exit 1
167
+		fi
168
+		if [ $# -ne 3 ] ; then
169
+			merr "migrate requires 2 parameters: old and new database"
170
+			exit 1
171
+		fi
172
+		# create new database
173
+		minfo "Creating new Database $3...."
174
+		NO_USER_INIT="yes"
175
+		openser_create $3
176
+		if [ "$?" -ne 0 ] ; then
177
+			echo "migrate: creating new database failed"
178
+			exit 1
179
+		fi
180
+		# migrate data
181
+		minfo "Migrating data from $2 to $3...."
182
+		migrate_db $2 $3
183
+		minfo "Migration successfully completed."
184
+		exit 0;
185
+		;;
186
+	copy)
187
+		# copy database to some other name
188
+		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
189
+			merr "$USED_DBENGINE don't support this operation"
190
+			exit 1
191
+		fi
192
+		shift
193
+		if [ $# -ne 1 ]; then
194
+			usage
195
+			exit 1
196
+		fi
197
+		tmp_file=`mktemp /tmp/kamdbctl.XXXXXXXXXX` || exit 1
198
+		openser_dump $DBNAME $tmp_file
199
+		ret=$?
200
+		if [ "$ret" -ne 0 ]; then
201
+			rm $tmp_file
202
+			exit $ret
203
+		fi
204
+		NO_USER_INIT="yes"
205
+		openser_create $1
206
+		ret=$?
207
+		if [ "$ret" -ne 0 ]; then
208
+			rm $tmp_file
209
+			exit $ret
210
+		fi
211
+		openser_restore $1 $tmp_file
212
+		ret=$?
213
+		rm -f $tmp_file
214
+		exit $ret
215
+		;;
216
+	backup)
217
+		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
218
+			merr "$USED_DBENGINE don't support this operation"
219
+			exit 1
220
+		fi
221
+		# backup current database
222
+		shift
223
+		if [ $# -ne 1 ]; then
224
+			usage
225
+			exit 1
226
+		fi
227
+		openser_dump $DBNAME $1
228
+		exit $?
229
+		;;
230
+	restore)
231
+		if [ "$USED_DBENGINE" == "berkeley" -o "$USED_DBENGINE" == "dbtext" ] ; then
232
+			merr "$USED_DBENGINE don't support this operation"
233
+			exit 1
234
+		fi
235
+		# restore database from a backup
236
+		shift
237
+		if [ $# -ne 1 ]; then
238
+			usage
239
+			exit 1
240
+		fi
241
+		openser_restore $DBNAME $1
242
+		exit $?
243
+		;;
244
+	create)
245
+		# create new database structures
246
+		shift
247
+		if [ $# -eq 1 ] ; then
248
+			DBNAME="$1"
249
+		fi
250
+
251
+		openser_create $DBNAME
252
+		exit $?
253
+		;;
254
+	presence)
255
+		presence_create $DBNAME
256
+		exit $?
257
+		;;
258
+	extra)
259
+		extra_create $DBNAME
260
+		exit $?
261
+		;;
262
+	drop)
263
+		# delete openser database
264
+		# create new database structures
265
+		shift
266
+		if [ $# -eq 1 ] ; then
267
+			DBNAME="$1"
268
+		fi
269
+
270
+		openser_drop $DBNAME
271
+		exit $?
272
+		;;
273
+	reinit)
274
+		# delete database and create a new one
275
+		# create new database structures
276
+		shift
277
+		if [ $# -eq 1 ] ; then
278
+			DBNAME="$1"
279
+		fi
280
+		openser_drop $DBNAME
281
+		ret=$?
282
+		if [ "$ret" -ne 0 ]; then
283
+			exit $ret