Browse code

kamdbctl: typo in log message - core tables successfully installed

Piotr Gregor authored on 24/02/2021 07:20:14 • Daniel-Constantin Mierla committed on 24/02/2021 07:20:14
Showing 1 changed files
... ...
@@ -315,7 +315,7 @@ standard_create () # pars: <database name>
315 315
 		fi
316 316
 	done
317 317
 
318
-	minfo "Core Kamailio tables succesfully created."
318
+	minfo "Core Kamailio tables successfully created."
319 319
 
320 320
 	if [ -e $DB_SCHEMA/extensions-create.sql ]
321 321
 	then
... ...
@@ -347,7 +347,7 @@ presence_create () # pars: <database name>
347 347
 		fi
348 348
 	done
349 349
 
350
-	minfo "Presence tables succesfully created."
350
+	minfo "Presence tables successfully created."
351 351
 }  # end presence_create
352 352
 
353 353
 
... ...
@@ -368,7 +368,7 @@ extra_create () # pars: <database name>
368 368
 			exit 1
369 369
 			fi
370 370
 		done
371
-	minfo "Extra tables succesfully created."
371
+	minfo "Extra tables successfully created."
372 372
 }  # end extra_create
373 373
 
374 374
 dbuid_create () # pars: <database name>
... ...
@@ -388,7 +388,7 @@ dbuid_create () # pars: <database name>
388 388
 			exit 1
389 389
 			fi
390 390
 		done
391
-	minfo "UID tables succesfully created."
391
+	minfo "UID tables successfully created."
392 392
 }  # end uid_create
393 393
 
394 394
 
Browse code

kamctl: kamdbclt mysql skip creating dbrouser if same as dbrwuser

Daniel-Constantin Mierla authored on 02/05/2020 06:18:58
Showing 1 changed files
... ...
@@ -161,9 +161,12 @@ kamailio_db_grant () # pars: <database name>
161 161
 
162 162
 	# Users: kamailio is the regular user, kamailioro only for reading
163 163
 	sql_query "" "CREATE USER '${DBRWUSER}'@'$DBHOST' IDENTIFIED BY '$DBRWPW';
164
-		GRANT ALL PRIVILEGES ON $1.* TO '${DBRWUSER}'@'$DBHOST';
165
-		CREATE USER '${DBROUSER}'@'$DBHOST' IDENTIFIED BY '$DBROPW';
166
-		GRANT SELECT ON $1.* TO '${DBROUSER}'@'$DBHOST';"
164
+		GRANT ALL PRIVILEGES ON $1.* TO '${DBRWUSER}'@'$DBHOST';"
165
+
166
+	if [ "${DBRWUSER}" != "${DBROUSER}" ] ; then
167
+		sql_query "" "CREATE USER '${DBROUSER}'@'$DBHOST' IDENTIFIED BY '$DBROPW';
168
+			GRANT SELECT ON $1.* TO '${DBROUSER}'@'$DBHOST';"
169
+	fi
167 170
 
168 171
 	if [ $? -ne 0 ] ; then
169 172
 		merr "granting privileges to database $1 failed!"
... ...
@@ -172,9 +175,11 @@ kamailio_db_grant () # pars: <database name>
172 175
 
173 176
 	if [ "$DBHOST" != "localhost" ] ; then
174 177
 		sql_query "" "CREATE USER '$DBRWUSER'@'localhost' IDENTIFIED BY '$DBRWPW';
175
-			GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'localhost';
176
-			CREATE USER '$DBROUSER'@'localhost' IDENTIFIED BY '$DBROPW';
177
-			GRANT SELECT ON $1.* TO '$DBROUSER'@'localhost';"
178
+			GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'localhost';"
179
+		if [ "${DBRWUSER}" != "${DBROUSER}" ] ; then
180
+			sql_query "" "CREATE USER '$DBROUSER'@'localhost' IDENTIFIED BY '$DBROPW';
181
+				GRANT SELECT ON $1.* TO '$DBROUSER'@'localhost';"
182
+		fi
178 183
 		if [ $? -ne 0 ] ; then
179 184
 			merr "granting localhost privileges to database $1 failed!"
180 185
 			exit 1
... ...
@@ -183,9 +188,11 @@ kamailio_db_grant () # pars: <database name>
183 188
 
184 189
 	if [ ! -z "$DBACCESSHOST" ] ; then
185 190
 		sql_query "" "CREATE USER '$DBRWUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBRWPW';
186
-			GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'$DBACCESSHOST';
187
-			CREATE USER '$DBROUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBROPW';
188
-			GRANT SELECT ON $1.* TO '$DBROUSER'@'$DBACCESSHOST';"
191
+			GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'$DBACCESSHOST';"
192
+		if [ "${DBRWUSER}" != "${DBROUSER}" ] ; then
193
+			sql_query "" "CREATE USER '$DBROUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBROPW';
194
+				GRANT SELECT ON $1.* TO '$DBROUSER'@'$DBACCESSHOST';"
195
+		fi
189 196
 		if [ $? -ne 0 ] ; then
190 197
 			merr "granting access host privileges to database $1 failed!"
191 198
 			exit 1
... ...
@@ -203,8 +210,11 @@ kamailio_db_revoke () # pars: <database name>
203 210
 	minfo "revoking privileges to database $1 ..."
204 211
 
205 212
 	# Users: kamailio is the regular user, kamailioro only for reading
206
-	sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '${DBRWUSER}'@'$DBHOST';
207
-		REVOKE SELECT ON $1.* FROM '${DBROUSER}'@'$DBHOST';"
213
+	sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '${DBRWUSER}'@'$DBHOST';"
214
+
215
+	if [ "${DBRWUSER}" != "${DBROUSER}" ] ; then
216
+		sql_query "" "REVOKE SELECT ON $1.* FROM '${DBROUSER}'@'$DBHOST';"
217
+	fi
208 218
 
209 219
 	if [ $? -ne 0 ] ; then
210 220
 		merr "revoking privileges to database $1 failed!"
... ...
@@ -212,8 +222,10 @@ kamailio_db_revoke () # pars: <database name>
212 222
 	fi
213 223
 
214 224
 	if [ "$DBHOST" != "localhost" ] ; then
215
-		sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '$DBRWUSER'@'localhost';
216
-			REVOKE SELECT ON $1.* FROM '$DBROUSER'@'localhost';"
225
+		sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '$DBRWUSER'@'localhost';"
226
+		if [ "${DBRWUSER}" != "${DBROUSER}" ] ; then
227
+			sql_query "" "REVOKE SELECT ON $1.* FROM '$DBROUSER'@'localhost';"
228
+		fi
217 229
 		if [ $? -ne 0 ] ; then
218 230
 			merr "granting localhost privileges to database $1 failed!"
219 231
 			exit 1
... ...
@@ -221,8 +233,10 @@ kamailio_db_revoke () # pars: <database name>
221 233
 	fi
222 234
 
223 235
 	if [ ! -z "$DBACCESSHOST" ] ; then
224
-		sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '$DBRWUSER'@'$DBACCESSHOST';
225
-			REVOKE SELECT ON $1.* FROM '$DBROUSER'@'$DBACCESSHOST';"
236
+		sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '$DBRWUSER'@'$DBACCESSHOST';"
237
+		if [ "${DBRWUSER}" != "${DBROUSER}" ] ; then
238
+			sql_query "" "REVOKE SELECT ON $1.* FROM '$DBROUSER'@'$DBACCESSHOST';"
239
+		fi
226 240
 		if [ $? -ne 0 ] ; then
227 241
 			merr "granting access host privileges to database $1 failed!"
228 242
 			exit 1
Browse code

kamdbctl: new option DBINITASK to control the steps for db init

- if set DBINITASK=yes, then each step requires confirmation (e.g.,
database creation, users creation, standard tables creation)
- can be useful when needing to run only some of the steps

Daniel-Constantin Mierla authored on 23/10/2019 06:47:19
Showing 1 changed files
... ...
@@ -238,24 +238,45 @@ kamailio_create () # pars: <database name>
238 238
 		exit 1
239 239
 	fi
240 240
 
241
-	kamailio_db_create $1
241
+	if [ "$DBINITASK" = "yes" ]; then
242
+		get_answer "ask" "Create the database '$1'? (y/n): "
243
+	else
244
+		ANSWER="y"
245
+	fi
246
+	if [ "$ANSWER" = "y" ]; then
247
+		kamailio_db_create $1
248
+	fi
242 249
 
243
-	kamailio_db_grant $1
250
+	if [ "$DBINITASK" = "yes" ]; then
251
+		get_answer "ask" "Create database users with access privileges? (y/n): "
252
+	else
253
+		ANSWER="y"
254
+	fi
255
+	if [ "$ANSWER" = "y" ]; then
256
+		kamailio_db_grant $1
257
+	fi
244 258
 
245
-	standard_create $1
259
+	if [ "$DBINITASK" = "yes" ]; then
260
+		get_answer "ask" "Create the standard database tables? (y/n): "
261
+	else
262
+		ANSWER="y"
263
+	fi
264
+	if [ "$ANSWER" = "y" ]; then
265
+		standard_create $1
266
+	fi
246 267
 
247
-	get_answer $INSTALL_PRESENCE_TABLES "Install presence related tables? (y/n): "
268
+	get_answer $INSTALL_PRESENCE_TABLES "Create the presence related tables? (y/n): "
248 269
 	if [ "$ANSWER" = "y" ]; then
249 270
 		presence_create $1
250 271
 	fi
251 272
 
252
-	get_answer $INSTALL_EXTRA_TABLES "Install tables for $EXTRA_MODULES? (y/n): "
273
+	get_answer $INSTALL_EXTRA_TABLES "Create the tables for $EXTRA_MODULES? (y/n): "
253 274
 	if [ "$ANSWER" = "y" ]; then
254 275
 		HAS_EXTRA="yes"
255 276
 		extra_create $1
256 277
 	fi
257 278
 
258
-	get_answer $INSTALL_DBUID_TABLES "Install tables for $DBUID_MODULES? (y/n): "
279
+	get_answer $INSTALL_DBUID_TABLES "Create the tables for $DBUID_MODULES? (y/n): "
259 280
 	if [ "$ANSWER" = "y" ]; then
260 281
 		HAS_EXTRA="yes"
261 282
 		dbuid_create $1
Browse code

kamdbctl: split create user and grant access statements for mysql

- MySQL 8 doesn't support all in one statement

Daniel-Constantin Mierla authored on 22/10/2019 08:49:18
Showing 1 changed files
... ...
@@ -160,8 +160,10 @@ kamailio_db_grant () # pars: <database name>
160 160
 	minfo "granting privileges to database $1 ..."
161 161
 
162 162
 	# Users: kamailio is the regular user, kamailioro only for reading
163
-	sql_query "" "GRANT ALL PRIVILEGES ON $1.* TO '${DBRWUSER}'@'$DBHOST' IDENTIFIED BY '$DBRWPW';
164
-		GRANT SELECT ON $1.* TO '${DBROUSER}'@'$DBHOST' IDENTIFIED BY '$DBROPW';"
163
+	sql_query "" "CREATE USER '${DBRWUSER}'@'$DBHOST' IDENTIFIED BY '$DBRWPW';
164
+		GRANT ALL PRIVILEGES ON $1.* TO '${DBRWUSER}'@'$DBHOST';
165
+		CREATE USER '${DBROUSER}'@'$DBHOST' IDENTIFIED BY '$DBROPW';
166
+		GRANT SELECT ON $1.* TO '${DBROUSER}'@'$DBHOST';"
165 167
 
166 168
 	if [ $? -ne 0 ] ; then
167 169
 		merr "granting privileges to database $1 failed!"
... ...
@@ -169,8 +171,10 @@ kamailio_db_grant () # pars: <database name>
169 171
 	fi
170 172
 
171 173
 	if [ "$DBHOST" != "localhost" ] ; then
172
-		sql_query "" "GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'localhost' IDENTIFIED  BY '$DBRWPW';
173
-			GRANT SELECT ON $1.* TO '$DBROUSER'@'localhost' IDENTIFIED BY '$DBROPW';"
174
+		sql_query "" "CREATE USER '$DBRWUSER'@'localhost' IDENTIFIED BY '$DBRWPW';
175
+			GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'localhost';
176
+			CREATE USER '$DBROUSER'@'localhost' IDENTIFIED BY '$DBROPW';
177
+			GRANT SELECT ON $1.* TO '$DBROUSER'@'localhost';"
174 178
 		if [ $? -ne 0 ] ; then
175 179
 			merr "granting localhost privileges to database $1 failed!"
176 180
 			exit 1
... ...
@@ -178,8 +182,10 @@ kamailio_db_grant () # pars: <database name>
178 182
 	fi
179 183
 
180 184
 	if [ ! -z "$DBACCESSHOST" ] ; then
181
-		sql_query "" "GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'$DBACCESSHOST' IDENTIFIED  BY '$DBRWPW';
182
-			GRANT SELECT ON $1.* TO '$DBROUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBROPW';"
185
+		sql_query "" "CREATE USER '$DBRWUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBRWPW';
186
+			GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'$DBACCESSHOST';
187
+			CREATE USER '$DBROUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBROPW';
188
+			GRANT SELECT ON $1.* TO '$DBROUSER'@'$DBACCESSHOST';"
183 189
 		if [ $? -ne 0 ] ; then
184 190
 			merr "granting access host privileges to database $1 failed!"
185 191
 			exit 1
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
... ...
@@ -373,172 +373,6 @@ kamailio_add_tables () # params: <database name> <tables group name>
373 373
 	fi
374 374
 }  # end kamailio_add_tables
375 375
 
376
-migrate_table () # 4 paremeters (dst_table, dst_cols, src_table, src_cols)
377
-{
378
-	if [ $# -ne 4 ] ; then
379
-		merr "migrate_table function takes 4 params $@"
380
-		exit 1
381
-	fi
382
-
383
-	src_cols=`echo $4 | sed s/?/$3./g `
384
-
385
-	X=`sql_query "" "INSERT into $1 ($2) SELECT $src_cols from $3;" 2>&1`
386
-
387
-	if [ $? -ne 0 ] ; then
388
-		echo $X | $GREP "ERROR 1146" > /dev/null
389
-		if [ $? -eq 0 ] ; then
390
-			echo " -- Migrating $3 to $1.....SKIPPED (no source)"
391
-			return 0
392
-		fi
393
-		echo "ERROR: failed to migrate $3 to $1!!!"
394
-		echo -n "Skip it and continue (y/n)? "
395
-		read INPUT
396
-		if [ "$INPUT" = "y" ] || [ "$INPUT" = "Y" ]
397
-		then
398
-			return 0
399
-		fi
400
-
401
-		exit 1;
402
-	fi
403
-
404
-	minfo " -- Migrating $3 to $1.....OK"
405
-
406
-}
407
-
408
-migrate_db () # 2 parameters (src_db, dst_db)
409
-{
410
-if [ $# -ne 2 ] ; then
411
-	merr "migrate_db function takes 2 params"
412
-	exit 1
413
-fi
414
-
415
-dst_db=$2
416
-src_db=$1
417
-
418
-migrate_table ${dst_db}.acc \
419
-	"id,method,from_tag,to_tag,callid,sip_code,sip_reason,time" \
420
-	${src_db}.acc \
421
-	"?id,?method,?from_tag,?to_tag,?callid,?sip_code,?sip_reason,?time"
422
-
423
-migrate_table ${dst_db}.missed_calls \
424
-	"id,method,from_tag,to_tag,callid,sip_code,sip_reason,time" \
425
-	${src_db}.missed_calls \
426
-	"?id,?method,?from_tag,?to_tag,?callid,?sip_code,?sip_reason,?time"
427
-
428
-migrate_table ${dst_db}.aliases \
429
-	"id,username,domain,contact,expires,q,callid,cseq,last_modified,\
430
-		flags,cflags,user_agent" \
431
-	${src_db}.aliases \
432
-	"?id,?username,?domain,?contact,?expires,?q,?callid,?cseq,?last_modified,\
433
-		?flags,?cflags,?user_agent"
434
-
435
-migrate_table ${dst_db}.dbaliases \
436
-	"id,alias_username,alias_domain,username,domain" \
437
-	${src_db}.dbaliases \
438
-	"?id,?alias_username,?alias_domain,?username,?domain"
439
-
440
-migrate_table ${dst_db}.grp \
441
-	"id,username,domain,grp,last_modified" \
442
-	${src_db}.grp \
443
-	"?id,?username,?domain,?grp,?last_modified"
444
-
445
-migrate_table ${dst_db}.re_grp \
446
-	"id,reg_exp,group_id" \
447
-	${src_db}.re_grp \
448
-	"?id,?reg_exp,?group_id"
449
-
450
-migrate_table ${dst_db}.silo \
451
-	"id,src_addr,dst_addr,username,domain,inc_time,exp_time,snd_time,\
452
-		ctype,body" \
453
-	${src_db}.silo \
454
-	"?id,?src_addr,?dst_addr,?username,?domain,?inc_time,?exp_time,?snd_time,\
455
-		?ctype,?body"
456
-
457
-migrate_table ${dst_db}.domain \
458
-	"id,domain,last_modified" \
459
-	${src_db}.domain \
460
-	"?id,?domain,?last_modified"
461
-
462
-migrate_table ${dst_db}.uri \
463
-	"id,username,domain,uri_user,last_modified" \
464
-	${src_db}.uri \
465
-	"?id,?username,?domain,?uri_user,?last_modified"
466
-
467
-migrate_table ${dst_db}.usr_preferences \
468
-	"id,uuid,username,domain,attribute,type,value,last_modified" \
469
-	${src_db}.usr_preferences \
470
-	"?id,?uuid,?username,?domain,?attribute,?type,?value,?last_modified"
471
-
472
-migrate_table ${dst_db}.trusted \
473
-	"id,src_ip,proto,from_pattern,tag" \
474
-	${src_db}.trusted \
475
-	"?id,?src_ip,?proto,?from_pattern,?tag"
476
-
477
-migrate_table ${dst_db}.address \
478
-	"id,grp,ip_addr,mask,port" \
479
-	${src_db}.address \
480
-	"?id,?grp,?ip_addr,?mask,?port"
481
-
482
-migrate_table ${dst_db}.speed_dial \
483
-	"id,username,domain,sd_username,sd_domain,new_uri,\
484
-		fname,lname,description" \
485
-	${src_db}.speed_dial \
486
-	"?id,?username,?domain,?sd_username,?sd_domain,?new_uri,\
487
-		?fname,?lname,?description"
488
-
489
-migrate_table ${dst_db}.gw \
490
-	"id,gw_name,grp_id,ip_addr,port,uri_scheme,transport,strip,prefix" \
491
-	${src_db}.gw \
492
-	"?id,?gw_name,?grp_id,?ip_addr,?port,?uri_scheme,?transport,?strip,?prefix"
493
-
494
-migrate_table ${dst_db}.gw_grp \
495
-	"grp_id,grp_name" \
496
-	${src_db}.gw_grp \
497
-	"?grp_id,?grp_name"
498
-
499
-migrate_table ${dst_db}.lcr \
500
-	"id,prefix,from_uri,grp_id,priority" \
501
-	${src_db}.lcr \
502
-	"?id,?prefix,?from_uri,?grp_id,?priority"
503
-
504
-migrate_table ${dst_db}.pdt \
505
-	"id,sdomain,prefix,domain" \
506
-	${src_db}.pdt \
507
-	"?id,?sdomain,?prefix,?domain"
508
-
509
-# migrate subscribers with no serweb support
510
-migrate_table ${dst_db}.subscriber \
511
-	"id,username,domain,password,ha1,ha1b,rpid" \
512
-	${src_db}.subscriber \
513
-	"?id,?username,?domain,?password,?ha1,?ha1b,?rpid"
514
-
515
-if [ "$HAS_EXTRA" = "yes" ] ; then
516
-	migrate_table ${dst_db}.cpl \
517
-		"id,username,domain,cpl_xml,cpl_bin" \
518
-		${src_db}.cpl \
519
-		"?id,?username,?domain,?cpl_xml,?cpl_bin"
520
-
521
-	migrate_table ${dst_db}.siptrace \
522
-		"id,date,callid,traced_user,msg,method,status,fromip,toip,\
523
-		fromtag,direction" \
524
-		${src_db}.siptrace \
525
-		"?id,?date,?callid,?traced_user,?msg,?method,?status,?fromip,?toip,\
526
-		?fromtag,?direction"
527
-
528
-	migrate_table ${dst_db}.imc_rooms \
529
-		"id,name,domain,flag" \
530
-		${src_db}.imc_rooms \
531
-		"?id,?name,?domain,?flag"
532
-
533
-	migrate_table ${dst_db}.imc_members \
534
-		"id,username,domain,room,flag" \
535
-		${src_db}.im_members \
536
-		"?id,?username,?domain,?room,?flag"
537
-fi
538
-
539
-
540
-}  #end migrate_db()
541
-
542 376
 
543 377
 export DBROOTPW
544 378
 if [ "$#" -ne 0 ] && [ "$DBROOTPW" = "" ]; then
Browse code

kamctl: expose db root password variable used by kamdbctl.mysql in kamctlrc

- DBROOTPW can be now set in kamctlrc
- targeting use for automatic testing

Daniel-Constantin Mierla authored on 01/12/2017 10:05:21
Showing 1 changed files
... ...
@@ -32,10 +32,10 @@ if [ -z "$DBROOTUSER" ]; then
32 32
 	DBROOTUSER="root"
33 33
 fi
34 34
 
35
-# Uncomment this to set the database root password if you want to run this 
36
-# script without any user prompt. This is unsafe, but useful e.g. for 
37
-# automatic testing.
38
-#PW=""
35
+# Set DBROOTPW in kamctlrc or via next line to set the database
36
+# root password if you want to run this script without any user prompt.
37
+# This is unsafe, but useful e.g. for automatic testing.
38
+#DBROOTPW=""
39 39
 
40 40
 
41 41
 if [ -z "$DBPORT" ] ; then
... ...
@@ -55,13 +55,13 @@ prompt_pw()
55 55
 	savetty=`stty -g`
56 56
 	echo -n "MySQL password for $DBROOTUSER: "
57 57
 	stty -echo
58
-	read PW
58
+	read DBROOTPW
59 59
 	stty $savetty
60 60
 	echo
61
-	export PW
61
+	export DBROOTPW
62 62
 }
63 63
 
64
-# execute sql command with optional db name 
64
+# execute sql command with optional db name
65 65
 # and password parameters given
66 66
 sql_query()
67 67
 {
... ...
@@ -72,14 +72,14 @@ sql_query()
72 72
 			DB=""
73 73
 		fi
74 74
 		shift
75
-		if [ -n "$PW" ]; then
76
-			$CMD "-p$PW" $DB -e "$@"
75
+		if [ -n "$DBROOTPW" ]; then
76
+			$CMD "-p$DBROOTPW" $DB -e "$@"
77 77
 		else
78 78
 			$CMD $DB -e "$@"
79 79
 		fi
80 80
 	else
81
-		if [ -n "$PW" ]; then
82
-			$CMD "-p$PW" "$@"
81
+		if [ -n "$DBROOTPW" ]; then
82
+			$CMD "-p$DBROOTPW" "$@"
83 83
 		else
84 84
 			$CMD "$@"
85 85
 		fi
... ...
@@ -106,9 +106,9 @@ kamailio_drop()  # pars: <database name>
106 106
 
107 107
 db_charset_test()
108 108
 {
109
-	if [ -n "$PW" ]; then
110
-		CURRCHARSET=`echo "show variables like '%character_set_server%'" | $CMD "-p$PW" | $AWK '{print $2}' | $SED -e 1d`
111
-		ALLCHARSETS=`echo "show character set" | $CMD "-p$PW" | $AWK '{print $1}' | $SED -e 1d | $GREP -iv -e "utf8\|ucs2"`
109
+	if [ -n "$DBROOTPW" ]; then
110
+		CURRCHARSET=`echo "show variables like '%character_set_server%'" | $CMD "-p$DBROOTPW" | $AWK '{print $2}' | $SED -e 1d`
111
+		ALLCHARSETS=`echo "show character set" | $CMD "-p$DBROOTPW" | $AWK '{print $1}' | $SED -e 1d | $GREP -iv -e "utf8\|ucs2"`
112 112
 	else
113 113
 		CURRCHARSET=`echo "show variables like '%character_set_server%'" | $CMD | $AWK '{print $2}' | $SED -e 1d`
114 114
 		ALLCHARSETS=`echo "show character set" | $CMD | $AWK '{print $1}' | $SED -e 1d | $GREP -iv -e "utf8\|ucs2"`
... ...
@@ -386,7 +386,7 @@ migrate_table () # 4 paremeters (dst_table, dst_cols, src_table, src_cols)
386 386
 
387 387
 	if [ $? -ne 0 ] ; then
388 388
 		echo $X | $GREP "ERROR 1146" > /dev/null
389
-		if [ $? -eq 0 ] ; then 
389
+		if [ $? -eq 0 ] ; then
390 390
 			echo " -- Migrating $3 to $1.....SKIPPED (no source)"
391 391
 			return 0
392 392
 		fi
... ...
@@ -540,9 +540,9 @@ fi
540 540
 }  #end migrate_db()
541 541
 
542 542
 
543
-export PW
544
-if [ "$#" -ne 0 ] && [ "$PW" = "" ]; then
545
-	if [ "$PWSKIP" = "" ]; then
543
+export DBROOTPW
544
+if [ "$#" -ne 0 ] && [ "$DBROOTPW" = "" ]; then
545
+	if [ "$DBROOTPWSKIP" = "" ]; then
546 546
 		prompt_pw
547 547
 	fi
548 548
 fi
Browse code

kamctl: added DBPORT option

- allows to specify database engine (mysql/psql) port
- requested by GH #916

Daniel-Constantin Mierla authored on 09/01/2017 19:35:47
Showing 1 changed files
... ...
@@ -38,8 +38,14 @@ fi
38 38
 #PW=""
39 39
 
40 40
 
41
-CMD="mysql -h $DBHOST -u$DBROOTUSER "
42
-DUMP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c -t "
41
+if [ -z "$DBPORT" ] ; then
42
+	CMD="mysql -h $DBHOST -u$DBROOTUSER "
43
+	DUMP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c -t "
44
+else
45
+	CMD="mysql -h $DBHOST -P $DBPORT -u$DBROOTUSER "
46
+	DUMP_CMD="mysqldump -h $DBHOST -P $DBPORT -u$DBROOTUSER -c -t "
47
+fi
48
+
43 49
 #################################################################
44 50
 
45 51
 
Browse code

kamctl remove svn ID's and history

Olle E. Johansson authored on 03/06/2016 08:34:25
Showing 1 changed files
... ...
@@ -1,4 +1,3 @@
1
-# $Id$
2 1
 #
3 2
 # Script for adding and dropping Kamailio MySQL tables
4 3
 #
Browse code

kamdbctl: option to run without asking mysql root password if empty

- provide PWSKIP=yes - good for automate testing

Daniel-Constantin Mierla authored on 01/10/2014 12:44:40
Showing 1 changed files
... ...
@@ -130,9 +130,10 @@ kamailio_db_create () # pars: <database name>
130 130
 		exit 1
131 131
 	fi
132 132
 
133
-	minfo "test server charset"
134
-
135
-	db_charset_test
133
+	if [ "$CHARSET" = "" ]; then
134
+		minfo "test server charset"
135
+		db_charset_test
136
+	fi
136 137
 
137 138
 	minfo "creating database $1 ..."
138 139
 
... ...
@@ -536,5 +537,7 @@ fi
536 537
 
537 538
 export PW
538 539
 if [ "$#" -ne 0 ] && [ "$PW" = "" ]; then
539
-	prompt_pw
540
+	if [ "$PWSKIP" = "" ]; then
541
+		prompt_pw
542
+	fi
540 543
 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
... ...
@@ -345,6 +345,28 @@ dbuid_create () # pars: <database name>
345 345
 }  # end uid_create
346 346
 
347 347
 
348
+kamailio_add_tables () # params: <database name> <tables group name>
349
+{
350
+	if [ $# -ne 2 ] ; then
351
+		merr "kamailio_add_tables function takes two params"
352
+		exit 1
353
+	fi
354
+
355
+	minfo "creating group of tables [$2] into database [$1] ..."
356
+
357
+	if [ -e $DB_SCHEMA/$2-create.sql ]
358
+	then
359
+		sql_query $1 < $DB_SCHEMA/$2-create.sql
360
+		if [ $? -ne 0 ] ; then
361
+			merr "Creating group of tables [$2] failed"
362
+			exit 1
363
+		fi
364
+	else
365
+		merr "Script for creating group of tables [$2] not found"
366
+		exit 1
367
+	fi
368
+}  # end kamailio_add_tables
369
+
348 370
 migrate_table () # 4 paremeters (dst_table, dst_cols, src_table, src_cols)
349 371
 {
350 372
 	if [ $# -ne 4 ] ; then
Browse code

kamctl: added option to grant sql access from a remote host

- set DBACCESSHOST in kamctlrc

Daniel-Constantin Mierla authored on 23/01/2013 11:49:16
Showing 1 changed files
... ...
@@ -170,6 +170,15 @@ kamailio_db_grant () # pars: <database name>
170 170
 			exit 1
171 171
 		fi
172 172
 	fi
173
+
174
+	if [ ! -z "$DBACCESSHOST" ] ; then
175
+		sql_query "" "GRANT ALL PRIVILEGES ON $1.* TO '$DBRWUSER'@'$DBACCESSHOST' IDENTIFIED  BY '$DBRWPW';
176
+			GRANT SELECT ON $1.* TO '$DBROUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBROPW';"
177
+		if [ $? -ne 0 ] ; then
178
+			merr "granting access host privileges to database $1 failed!"
179
+			exit 1
180
+		fi
181
+	fi
173 182
 }
174 183
 
175 184
 kamailio_db_revoke () # pars: <database name>
... ...
@@ -198,6 +207,15 @@ kamailio_db_revoke () # pars: <database name>
198 207
 			exit 1
199 208
 		fi
200 209
 	fi
210
+
211
+	if [ ! -z "$DBACCESSHOST" ] ; then
212
+		sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '$DBRWUSER'@'$DBACCESSHOST';
213
+			REVOKE SELECT ON $1.* FROM '$DBROUSER'@'$DBACCESSHOST';"
214
+		if [ $? -ne 0 ] ; then
215
+			merr "granting access host privileges to database $1 failed!"
216
+			exit 1
217
+		fi
218
+	fi
201 219
 }
202 220
 
203 221
 
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
... ...
@@ -136,7 +136,7 @@ kamailio_db_create () # pars: <database name>
136 136
 
137 137
 	minfo "creating database $1 ..."
138 138
 
139
-	sql_query "" "CREATE DATACASE $1 CHARACTER SET $CHARSET;"
139
+	sql_query "" "CREATE DATABASE $1 CHARACTER SET $CHARSET;"
140 140
 
141 141
 	if [ $? -ne 0 ] ; then
142 142
 		merr "Creating database $1 failed!"
... ...
@@ -172,128 +172,190 @@ kamailio_db_grant () # pars: <database name>
172 172
 	fi
173 173
 }
174 174
 
175
-kamailio_create () # pars: <database name>
175
+kamailio_db_revoke () # pars: <database name>
176 176
 {
177
-if [ $# -ne 1 ] ; then
178
-	merr "kamailio_create function takes one param"
179
-	exit 1
180
-fi
177
+	if [ $# -ne 1 ] ; then
178
+		merr "kamailio_db_revoke function takes one param"
179
+		exit 1
180
+	fi
181 181
 
182
-kamailio_db_create $1
182
+	minfo "revoking privileges to database $1 ..."
183 183
 
184
-kamailio_db_grant $1
184
+	# Users: kamailio is the regular user, kamailioro only for reading
185
+	sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '${DBRWUSER}'@'$DBHOST';
186
+		REVOKE SELECT ON $1.* FROM '${DBROUSER}'@'$DBHOST';"
185 187
 
186
-for TABLE in $STANDARD_MODULES; do
187
-	mdbg "Creating core table: $TABLE"
188
-	sql_query $1 < $DB_SCHEMA/$TABLE-create.sql
189 188
 	if [ $? -ne 0 ] ; then
190
-		merr "Creating core tables failed!"
189
+		merr "revoking privileges to database $1 failed!"
191 190
 		exit 1
192 191
 	fi
193
-done
194 192
 
195
-minfo "Core Kamailio tables succesfully created."
193
+	if [ "$DBHOST" != "localhost" ] ; then
194
+		sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM '$DBRWUSER'@'localhost';
195
+			REVOKE SELECT ON $1.* FROM '$DBROUSER'@'localhost';"
196
+		if [ $? -ne 0 ] ; then
197
+			merr "granting localhost privileges to database $1 failed!"
198
+			exit 1
199
+		fi
200
+	fi
201
+}
196 202
 
197
-if [ -e $DB_SCHEMA/extensions-create.sql ]
198
-then
199
-	minfo "Creating custom extensions tables"
200
-	sql_query $1 < $DB_SCHEMA/extensions-create.sql
201
-	if [ $? -ne 0 ] ; then
202
-		merr "Creating custom extensions tables failed!"
203
+
204
+kamailio_create () # pars: <database name>
205
+{
206
+	if [ $# -ne 1 ] ; then
207
+		merr "kamailio_create function takes one param"
203 208
 		exit 1
204 209
 	fi
205
-fi
206 210
 
207
-get_answer $INSTALL_PRESENCE_TABLES "Install presence related tables? (y/n): "
208
-if [ "$ANSWER" = "y" ]; then
209
-	presence_create $1
210
-fi
211
+	kamailio_db_create $1
211 212
 
212
-get_answer $INSTALL_EXTRA_TABLES "Install tables for $EXTRA_MODULES? (y/n): "
213
-if [ "$ANSWER" = "y" ]; then
214
-	HAS_EXTRA="yes"
215
-	extra_create $1
216
-fi
217
-} # kamailio_create
213
+	kamailio_db_grant $1
218 214
 
215
+	standard_create $1
219 216
 
220
-presence_create () # pars: <database name>
217
+	get_answer $INSTALL_PRESENCE_TABLES "Install presence related tables? (y/n): "
218
+	if [ "$ANSWER" = "y" ]; then
219
+		presence_create $1
220
+	fi
221
+
222
+	get_answer $INSTALL_EXTRA_TABLES "Install tables for $EXTRA_MODULES? (y/n): "
223
+	if [ "$ANSWER" = "y" ]; then
224
+		HAS_EXTRA="yes"
225
+		extra_create $1
226
+	fi
227
+
228
+	get_answer $INSTALL_DBUID_TABLES "Install tables for $DBUID_MODULES? (y/n): "
229
+	if [ "$ANSWER" = "y" ]; then
230
+		HAS_EXTRA="yes"
231
+		dbuid_create $1
232
+	fi
233
+} # end kamailio_create
234
+
235
+standard_create () # pars: <database name>
221 236
 {
222
-if [ $# -ne 1 ] ; then
223
-	merr "presence_create function takes one param"
224
-	exit 1
225
-fi
237
+	if [ $# -ne 1 ] ; then
238
+		merr "standard_create function takes one param"
239
+		exit 1
240
+	fi
226 241
 
227
-minfo "creating presence tables into $1 ..."
242
+	minfo "creating standard tables into $1 ..."
228 243
 
229
-sql_query $1 < $DB_SCHEMA/presence-create.sql
244
+	for TABLE in $STANDARD_MODULES; do
245
+		mdbg "Creating core table: $TABLE"
246
+		sql_query $1 < $DB_SCHEMA/$TABLE-create.sql
247
+		if [ $? -ne 0 ] ; then
248
+			merr "Creating core tables failed at $TABLE!"
249
+			exit 1
250
+		fi
251
+	done
230 252
 
231
-if [ $? -ne 0 ] ; then
232
-	merr "Failed to create presence tables!"
233
-	exit 1
234
-fi
253
+	minfo "Core Kamailio tables succesfully created."
235 254
 
236
-sql_query $1 < $DB_SCHEMA/rls-create.sql
255
+	if [ -e $DB_SCHEMA/extensions-create.sql ]
256
+	then
257
+		minfo "Creating custom extensions tables"
258
+		sql_query $1 < $DB_SCHEMA/extensions-create.sql
259
+		if [ $? -ne 0 ] ; then
260
+			merr "Creating custom extensions tables failed!"
261
+			exit 1
262
+		fi
263
+	fi
264
+}  # end standard_create
237 265
 
238
-if [ $? -ne 0 ] ; then
239
-	merr "Failed to create rls-presence tables!"
240
-	exit 1
241
-fi
242 266
 
243
-minfo "Presence tables succesfully created."
267
+presence_create () # pars: <database name>
268
+{
269
+	if [ $# -ne 1 ] ; then
270
+		merr "presence_create function takes one param"
271
+		exit 1
272
+	fi
273
+
274
+	minfo "creating presence tables into $1 ..."
275
+
276
+	for TABLE in $PRESENCE_MODULES; do
277
+		mdbg "Creating presence tables for $TABLE"
278
+		sql_query $1 < $DB_SCHEMA/$TABLE-create.sql
279
+		if [ $? -ne 0 ] ; then
280
+			merr "Creating presence tables failed at $TABLE!"
281
+			exit 1
282
+		fi
283
+	done
284
+
285
+	minfo "Presence tables succesfully created."
244 286
 }  # end presence_create
245 287
 
246 288
 
247 289
 extra_create () # pars: <database name>
248 290
 {
249
-if [ $# -ne 1 ] ; then
250
-	merr "extra_create function takes one param"
251
-	exit 1
252
-fi
291
+	if [ $# -ne 1 ] ; then
292
+		merr "extra_create function takes one param"
293
+		exit 1
294
+	fi
253 295
 
254
-minfo "creating extra tables into $1 ..."
296
+	minfo "creating extra tables into $1 ..."
255 297
 
256
-for TABLE in $EXTRA_MODULES; do
257
-	mdbg "Creating extra table: $TABLE"
258
-	sql_query $1 < $DB_SCHEMA/$TABLE-create.sql
259
-	if [ $? -ne 0 ] ; then
260
-		merr "Creating extra tables failed at $TABLE!"
261
-		exit 1
262
-		fi
263
-	done
264
-minfo "Extra tables succesfully created."
298
+	for TABLE in $EXTRA_MODULES; do
299
+		mdbg "Creating extra table: $TABLE"
300
+		sql_query $1 < $DB_SCHEMA/$TABLE-create.sql
301
+		if [ $? -ne 0 ] ; then
302
+			merr "Creating extra tables failed at $TABLE!"
303
+			exit 1
304
+			fi
305
+		done
306
+	minfo "Extra tables succesfully created."
265 307
 }  # end extra_create
266 308
 
309
+dbuid_create () # pars: <database name>
310
+{
311
+	if [ $# -ne 1 ] ; then
312
+		merr "dbuid_create function takes one param"
313
+		exit 1
314
+	fi
315
+
316
+	minfo "creating uid tables into $1 ..."
317
+
318
+	for TABLE in $DBUID_MODULES; do
319
+		mdbg "Creating uid table: $TABLE"
320
+		sql_query $1 < $DB_SCHEMA/$TABLE-create.sql
321
+		if [ $? -ne 0 ] ; then
322
+			merr "Creating uid tables failed at $TABLE!"
323
+			exit 1
324
+			fi
325
+		done
326
+	minfo "UID tables succesfully created."
327
+}  # end uid_create
328
+
267 329
 
268 330
 migrate_table () # 4 paremeters (dst_table, dst_cols, src_table, src_cols)
269 331
 {
270
-if [ $# -ne 4 ] ; then
271
-	merr "migrate_table function takes 4 params $@"
272
-	exit 1
273
-fi
332
+	if [ $# -ne 4 ] ; then
333
+		merr "migrate_table function takes 4 params $@"
334
+		exit 1
335
+	fi
274 336
 
275
-src_cols=`echo $4 | sed s/?/$3./g `
337
+	src_cols=`echo $4 | sed s/?/$3./g `
276 338
 
277
-X=`sql_query "" "INSERT into $1 ($2) SELECT $src_cols from $3;" 2>&1`
339
+	X=`sql_query "" "INSERT into $1 ($2) SELECT $src_cols from $3;" 2>&1`
278 340
 
279
-if [ $? -ne 0 ] ; then
280
-	echo $X | $GREP "ERROR 1146" > /dev/null
281
-	if [ $? -eq 0 ] ; then 
282
-		echo " -- Migrating $3 to $1.....SKIPPED (no source)"
283
-		return 0
284
-	fi
285
-	echo "ERROR: failed to migrate $3 to $1!!!"
286
-	echo -n "Skip it and continue (y/n)? "
287
-	read INPUT
288
-	if [ "$INPUT" = "y" ] || [ "$INPUT" = "Y" ]
289
-	then
290
-		return 0
291
-	fi
341
+	if [ $? -ne 0 ] ; then
342
+		echo $X | $GREP "ERROR 1146" > /dev/null
343
+		if [ $? -eq 0 ] ; then 
344
+			echo " -- Migrating $3 to $1.....SKIPPED (no source)"
345
+			return 0
346
+		fi
347
+		echo "ERROR: failed to migrate $3 to $1!!!"
348
+		echo -n "Skip it and continue (y/n)? "
349
+		read INPUT
350
+		if [ "$INPUT" = "y" ] || [ "$INPUT" = "Y" ]
351
+		then
352
+			return 0
353
+		fi
292 354
 
293
-	exit 1;
294
-fi
355
+		exit 1;
356
+	fi
295 357
 
296
-minfo " -- Migrating $3 to $1.....OK"
358
+	minfo " -- Migrating $3 to $1.....OK"
297 359
 
298 360
 }
299 361
 
Browse code

kamctl: cleaned db creation

Daniel-Constantin Mierla authored on 22/01/2013 22:09:47
Showing 1 changed files
... ...
@@ -84,18 +84,18 @@ sql_query()
84 84
 
85 85
 kamailio_drop()  # pars: <database name>
86 86
 {
87
-if [ $# -ne 1 ] ; then
88
-	merr "kamailio_drop function takes two params"
89
-	exit 1
90
-fi
87
+	if [ $# -ne 1 ] ; then
88
+		merr "kamailio_drop function takes two params"
89
+		exit 1
90
+	fi
91 91
 
92
-sql_query "" "drop database $1;"
92
+	sql_query "" "DROP DATABASE $1;"
93 93
 
94
-if [ $? -ne 0 ] ; then
95
-	merr "Dropping database $1 failed!"
96
-	exit 1
97
-fi
98
-minfo "Database $1 deleted"
94
+	if [ $? -ne 0 ] ; then
95
+		merr "Dropping database $1 failed!"
96
+		exit 1
97
+	fi
98
+	minfo "Database $1 deleted"
99 99
 }
100 100
 
101 101
 
... ...
@@ -123,33 +123,66 @@ db_charset_test()
123 123
 	CHARSET=$CURRCHARSET
124 124
 }
125 125
 
126
-
127
-kamailio_create () # pars: <database name>
126
+kamailio_db_create () # pars: <database name>