Browse Source

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

Ovidiu Sas 12 years ago
parent
commit
ef2b3a6ee8
3 changed files with 92 additions and 9 deletions
  1. 1 0
      utils/kamctl/Makefile
  2. 75 0
      utils/kamctl/kamdbctl
  3. 16 9
      utils/kamctl/kamdbctl.base

+ 1 - 0
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

+ 75 - 0
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"
 		;;

+ 16 - 9
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