[sr-dev] git:master: kamdbctl: new command - kamdbctl pframework create

Ovidiu Sas osas at voipembedded.com
Thu Jan 10 18:55:43 CET 2013


Module: sip-router
Branch: master
Commit: ef2b3a6ee84f75bd49a06635a486807eeaebc08a
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ef2b3a6ee84f75bd49a06635a486807eeaebc08a

Author: Ovidiu Sas <osas at voipembedded.com>
Committer: Ovidiu Sas <osas at voipembedded.com>
Date:   Thu Jan 10 12:50:06 2013 -0500

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

---

 utils/kamctl/Makefile      |    1 +
 utils/kamctl/kamdbctl      |   75 ++++++++++++++++++++++++++++++++++++++++++++
 utils/kamctl/kamdbctl.base |   25 +++++++++-----
 3 files changed, 92 insertions(+), 9 deletions(-)

diff --git a/utils/kamctl/Makefile b/utils/kamctl/Makefile
index ba3d67a..3056ae0 100644
--- a/utils/kamctl/Makefile
+++ b/utils/kamctl/Makefile
@@ -70,6 +70,7 @@ install-bin: $(bin_prefix)/$(bin_dir)
 		# install db setup base script
 		sed -e "s#/usr/local/sbin#$(bin_target)#g" \
 			-e "s#/usr/local/etc/kamailio#$(cfg_target)#g" \
+			-e "s#/usr/local/share/kamailio#$(data_target)#g" \
 			< kamdbctl.base > /tmp/kamdbctl.base
 		$(INSTALL_CFG) /tmp/kamdbctl.base \
 			$(modules_prefix)/$(lib_dir)/kamctl/kamdbctl.base
diff --git a/utils/kamctl/kamdbctl b/utils/kamctl/kamdbctl
index 681818e..4784729 100755
--- a/utils/kamctl/kamdbctl
+++ b/utils/kamctl/kamdbctl
@@ -168,6 +168,76 @@ kamailio_restore() #pars: <database name> <filename>
 }
 
 
+kamailio_pframework_create() #pars: none
+{
+	touch $DEFAULT_CFG_DIR/pi_framework_sample
+	if [ $? -ne 0 ] ; then
+		merr "Unable to create $DEFAULT_CFG_DIR/pi_framework_sample"
+		exit 1
+	fi
+
+	if [ -d "$DATA_DIR/xhttp_pi" ] ; then
+		PI_MODULES="$STANDARD_MODULES"
+	else
+		merr "Please install first the xhttp_pi module"
+		exit 1
+	fi
+
+
+	get_answer $INSTALL_EXTRA_TABLES "Add provisionning framework for extra tables? (y/n): "
+	if [ "$ANSWER" = "y" ]; then
+		PI_MODULES="$PI_MODULES $EXTRA_MODULES"
+	fi
+
+	get_answer $INSTALL_PRESENCE_TABLES "Add provisionning framework for presence tables? (y/n): "
+	if [ "$ANSWER" = "y" ]; then
+		PI_MODULES="$PI_MODULES $PRESENCE_TABLES"
+	fi
+
+	cat $DATA_DIR/xhttp_pi/pi_framework-00 > $DEFAULT_CFG_DIR/pi_framework_sample
+	for TABLE in $PI_MODULES; do
+		if [ -e $DATA_DIR/xhttp_pi/$TABLE-table ]; then
+			cat $DATA_DIR/xhttp_pi/$TABLE-table >> $DEFAULT_CFG_DIR/pi_framework_sample
+		else
+			merr "Unable to configure: $TABLE - missing table descriptor"
+		fi
+	done
+	cat $DATA_DIR/xhttp_pi/pi_framework-01 >> $DEFAULT_CFG_DIR/pi_framework_sample
+	for TABLE in $PI_MODULES; do
+		if [ -e $DATA_DIR/xhttp_pi/$TABLE-mod ]; then
+			cat $DATA_DIR/xhttp_pi/$TABLE-mod >> $DEFAULT_CFG_DIR/pi_framework_sample
+		else
+			merr "Unable to configure: $TABLE - missing mod descriptor"
+		fi
+	done
+	cat $DATA_DIR/xhttp_pi/pi_framework-02 >> $DEFAULT_CFG_DIR/pi_framework_sample
+
+	minfo "Sample provisionning framework saved as: $DEFAULT_CFG_DIR/pi_framework_sample"
+}
+
+kamailio_pframework() #pars: <action>
+{
+	if [ $# -ne 1 ] ; then
+		merr "kamailio_pframework function takes one parameter"
+		exit 1
+	fi
+
+	case $1 in
+		create)
+			shift
+			kamailio_pframework_create "$@"
+			exit $?
+			;;
+		*)
+			merr "Unexpected pframework action: $1"
+			usage
+			exit 1
+			;;
+	esac
+}
+
+
+
 case $1 in
 	migrate)
 		if [ "$USED_DBENGINE" != "mysql" ] ; then
@@ -303,6 +373,11 @@ case $1 in
 		kamailio_berkeley "$@"
 		exit $?
 		;;
+	pframework)
+		shift
+		kamailio_pframework "$@"
+		exit $?
+		;;
 	version)
 		echo  "$0 $VERSION"
 		;;
diff --git a/utils/kamctl/kamdbctl.base b/utils/kamctl/kamdbctl.base
index 8e367be..f387aa2 100644
--- a/utils/kamctl/kamdbctl.base
+++ b/utils/kamctl/kamdbctl.base
@@ -56,6 +56,12 @@ DEFAULT_CSEQ=${DEFAULT_CSEQ:-13}
 DEFAULT_LOCATION_EXPIRES=${DEFAULT_LOCATION_EXPIRES:-${FOREVER}}
 
 
+# default location for config files
+DEFAULT_CFG_DIR=/usr/local/etc/kamailio
+
+# default location for data files
+DEFAULT_DATA_DIR=/usr/local/share/kamailio
+
 # Needed programs
 MD5=${MD5:-md5sum}
 AWK=${AWK:-awk}
@@ -79,21 +85,22 @@ COMMAND=`basename $0`
 cat <<EOF
 $0 $VERSION
 
-usage: $COMMAND create <db name or db_path, optional> .....(creates a new database)
-       $COMMAND drop <db name or db_path, optional> .......(!entirely deletes tables!)
-       $COMMAND reinit <db name or db_path, optional> .....(!entirely deletes and than re-creates tables!)
-       $COMMAND backup <file> .................................(dumps current database to file)
-       $COMMAND restore <file> ................................(restores tables from a file)
-       $COMMAND copy <new_db> .................................(creates a new db from an existing one)
-       $COMMAND migrate <old_db> <new_db> .....................(migrates DB from 1.2 to 1.3, not implemented yet!)
-       $COMMAND presence ......................................(adds the presence related tables)
-       $COMMAND extra .........................................(adds the extra tables)
+usage: $COMMAND create <db name or db_path, optional> ...(creates a new database)
+       $COMMAND drop <db name or db_path, optional> .....(!entirely deletes tables!)
+       $COMMAND reinit <db name or db_path, optional> ...(!entirely deletes and than re-creates tables!)
+       $COMMAND backup <file> ...........................(dumps current database to file)
+       $COMMAND restore <file> ..........................(restores tables from a file)
+       $COMMAND copy <new_db> ...........................(creates a new db from an existing one)
+       $COMMAND migrate <old_db> <new_db> ...............(migrates DB from 1.2 to 1.3, not implemented yet!)
+       $COMMAND presence ................................(adds the presence related tables)
+       $COMMAND extra ...................................(adds the extra tables)
 
        if you want to manipulate database as other database user than
        root, want to change database name from default value "$DBNAME",
        or want to use other values for users and password, edit the
        "config vars" section of the command $COMMAND.
 
+       $COMMAND pframework create .......................(creates a sample provisioning framework file)
 EOF
 } #usage
 




More information about the sr-dev mailing list