utils/kamctl/kamdbctl.base
b2750804
 PATH=$PATH:/usr/local/sbin
 
 # config vars
 
860c33c5
 # name of the database to be used by Kamailio
923b738f
 DBNAME=${DBNAME:-kamailio}
884851c9
 
b2750804
 # address of database server
884851c9
 DBHOST=${DBHOST:-localhost}
 
b2750804
 # user with full privileges over DBNAME database
923b738f
 DBRWUSER=${DBRWUSER:-kamailio}
884851c9
 
b2750804
 # password user with full privileges over DBNAME database
923b738f
 DBRWPW=${DBRWPW:-kamailiorw}
884851c9
 
b2750804
 # read-only user
923b738f
 DBROUSER=${DBROUSER:-kamailioro}
884851c9
 
b2750804
 # password for read-only user
923b738f
 DBROPW=${DBROPW:-kamailioro}
b2750804
 
 # user name column
884851c9
 USERCOL=${USERCOL:-username}
b2750804
 
27a71bd2
 # Describe what additional tables to install. Valid values for the variables
 # below are yes/no/ask. With ask it will interactively ask the user for the
 # answer, while yes/no allow for automated, unassisted installs.
 
884851c9
 INSTALL_EXTRA_TABLES=${INSTALL_EXTRA_TABLES:-ask}
 INSTALL_PRESENCE_TABLES=${INSTALL_PRESENCE_TABLES:-ask}
1fd2b4ec
 INSTALL_DBUID_TABLES=${INSTALL_DBUID_TABLES:-ask}
27a71bd2
 
5f72f337
 # Used by dbtext and db_berkeley to define tables to be created, used by
 # postgres to do the grants
c6e62f93
 STANDARD_TABLES=${STANDARD_TABLES:-'version acc dbaliases domain domain_attrs
1fd2b4ec
 		grp uri speed_dial lcr_gw lcr_rule lcr_rule_target pdt subscriber
 		location location_attrs re_grp trusted address missed_calls
15a14440
 		usr_preferences aliases silo dialog dialog_vars dispatcher dialplan
c6e62f93
 		acc_cdrs topos_d topos_t'}
 EXTRA_TABLES=${EXTRA_TABLES:-'imc_members imc_rooms cpl sip_trace domainpolicy
719c2987
 		carrierroute carrier_name domain_name carrierfailureroute userblocklist
66370c47
 		globalblocklist htable purplemap uacreg pl_pipes mtree mtrees
5df2d12a
 		sca_subscriptions mohqcalls mohqueues rtpproxy rtpengine
c6e62f93
 		dr_gateways dr_rules dr_gw_lists dr_groups secfilter'}
 PRESENCE_TABLES=${PRESENCE_TABLES:-'presentity active_watchers watchers xcap
 		pua rls_presentity rls_watchers'}
 DBUID_TABLES=${UID_TABLES:-'uid_credentials uid_domain uid_domain_attrs
 		uid_global_attrs uid_uri uid_uri_attrs uid_user_attrs'}
c327195e
 
b2750804
 # SQL definitions
 # If you change this definitions here, then you must change them
a6a37ad2
 # in ../../lib/srdb1/schema/entities.xml too. They are used in this
 # script and needed to be the same as in the database definitions.
b2750804
 # FIXME
 
97173572
 FOREVER=${FOREVER:-2030-05-28 21:32:15}
884851c9
 
ef2b3a6e
 # default location for config files
 DEFAULT_CFG_DIR=/usr/local/etc/kamailio
 
 # default location for data files
 DEFAULT_DATA_DIR=/usr/local/share/kamailio
 
884851c9
 # Needed programs
 MD5=${MD5:-md5sum}
 AWK=${AWK:-awk}
021fcd00
 GREP=${GREP:-grep}
884851c9
 SED=${SED:-sed}
 
b2750804
 # define what modules should be installed
c6e62f93
 STANDARD_MODULES=${STANDARD_MODULES:-'standard acc lcr domain group
1fd2b4ec
 		permissions registrar usrloc msilo alias_db uri_db speeddial
c6e62f93
 		avpops auth_db pdt dialog dispatcher dialplan topos'}
1fd2b4ec
 
c6e62f93
 PRESENCE_MODULES=${PRESENCE_MODULES:-'presence rls'}
1fd2b4ec
 
c6e62f93
 EXTRA_MODULES=${EXTRA_MODULES:-'imc cpl siptrace domainpolicy carrierroute
719c2987
 		drouting userblocklist htable purple uac pipelimit mtree sca mohqueue
c6e62f93
 		rtpproxy rtpengine secfilter'}
1fd2b4ec
 
c6e62f93
 DBUID_MODULES=${UID_MODULES:-'uid_auth_db uid_avp_db uid_domain uid_gflags
 		uid_uri_db'}
b2750804
 
 ############################################################
 
 # common functions
 
 usage() {
 COMMAND=`basename $0`
 cat <<EOF
5f72f337
 $0 $VERSION
 
ef2b3a6e
 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 presence ................................(adds the presence related tables)
        $COMMAND extra ...................................(adds the extra tables)
1fd2b4ec
        $COMMAND dbuid ...................................(adds the uid tables)
        $COMMAND dbonly ..................................(creates empty database)
        $COMMAND grant ...................................(grant privileges to database)
        $COMMAND revoke ..................................(revoke privileges to database)
727aa357
        $COMMAND add-tables <gid> ........................(creates only tables groupped in gid)
b2750804
 
96a2629b
        if you want to manipulate database as other database user than
b2750804
        root, want to change database name from default value "$DBNAME",
        or want to use other values for users and password, edit the
96a2629b
        "config vars" section of the command $COMMAND.
b2750804
 
ef2b3a6e
        $COMMAND pframework create .......................(creates a sample provisioning framework file)
b2750804
 EOF
 } #usage
 
 
 
 
 # read realm
 prompt_realm()
 {
 	printf "Domain (realm) for the default user 'admin': "
 	read SIP_DOMAIN
 	echo
 }
 
 
 # calculate credentials for admin
 credentials()
 {
 	HA1=`echo -n "admin:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
 	if [ $? -ne 0 ] ; then
96a2629b
 		merr "HA1 calculation failed"
b2750804
 		exit 1
 	fi
 	HA1B=`echo -n "admin@$SIP_DOMAIN:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
 	if [ $? -ne 0 ] ; then
96a2629b
 		merr "HA1B calculation failed"
b2750804
 		exit 1
 	fi
 
 	#PHPLIB_ID of users should be difficulty to guess for security reasons
 	NOW=`date`;
 	PHPLIB_ID=`echo -n "$RANDOM:$NOW:$SIP_DOMAIN" | $MD5 | $AWK '{ print $1 }'`
 	if [ $? -ne 0 ] ; then
96a2629b
 		merr "PHPLIB_ID calculation failed"
b2750804
 		exit 1
 	fi
 }
 
de1a4247
 # FIXME use the definition from kamctl.base
96a2629b
 
 mdbg() {
 	if [ "0$VERBOSE" -ne 0 ] ; then
 		if [ -t 1 -a -z "$NOHLPRINT" ] ; then
 			echo -e "\033[1m$1\033[0m"
 		else
 			echo "$1"
 		fi
 	fi
 }
 
 mwarn() {
 	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
 		echo -e '\E[37;32m'"\033[1mWARNING: $1\033[0m"
 	else
 		echo "** WARNING: $1"
 	fi
 }
 
 minfo() {
 	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
 		echo -e '\E[37;33m'"\033[1mINFO: $1\033[0m"
 	else
 		echo "** INFO: $1"
 	fi
 }
 
 mecho() {
 	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
 		echo -e "\033[1m$1\033[0m"
 	else
 		echo "$1"
 	fi
 }
 
 merr() {
 	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
 		echo -e '\E[37;31m'"\033[1mERROR: $1\033[0m"
 	else
 		echo "** ERROR: $1"
 	fi
 }
27a71bd2
 
 # Get a y/n value from a variable. If the variable contains the keyword
 # `ask', then interactively ask the user for an answer.
 #
 # Arguments:
 #  $1 - variable holding yes/no/ask
 #  $2 - question to print if value of variable is ask
 #
 # Return:
 #  On return $ANSWER will be available with y/n
 #
 get_answer ()
 {
88d06a08
 	value=$1
 	question=$2
 	if [ "${value}" = "ask" ]; then
 		echo -n "$question"
 		read value
 	fi
 	ANSWER=$(echo ${value} | grep -o -e '[YyNn]' | sed -e 's/Y/y/' -e 's/N/n/')
27a71bd2
 }