1PATH=$PATH:/usr/local/sbin
2
3# config vars
4
5# name of the database to be used by Kamailio
6DBNAME=${DBNAME:-kamailio}
7
8# address of database server
9DBHOST=${DBHOST:-localhost}
10
11# user with full privileges over DBNAME database
12DBRWUSER=${DBRWUSER:-kamailio}
13
14# password user with full privileges over DBNAME database
15DBRWPW=${DBRWPW:-kamailiorw}
16
17# read-only user
18DBROUSER=${DBROUSER:-kamailioro}
19
20# password for read-only user
21DBROPW=${DBROPW:-kamailioro}
22
23# user name column
24USERCOL=${USERCOL:-username}
25
26# Describe what additional tables to install. Valid values for the variables
27# below are yes/no/ask. With ask it will interactively ask the user for the
28# answer, while yes/no allow for automated, unassisted installs.
29
30INSTALL_EXTRA_TABLES=${INSTALL_EXTRA_TABLES:-ask}
31INSTALL_PRESENCE_TABLES=${INSTALL_PRESENCE_TABLES:-ask}
32INSTALL_DBUID_TABLES=${INSTALL_DBUID_TABLES:-ask}
33
34# Used by dbtext and db_berkeley to define tables to be created, used by
35# postgres to do the grants
36STANDARD_TABLES=${STANDARD_TABLES:-'version acc dbaliases domain domain_attrs
37		grp uri speed_dial lcr_gw lcr_rule lcr_rule_target pdt subscriber
38		location location_attrs re_grp trusted address missed_calls
39		usr_preferences aliases silo dialog dialog_vars dispatcher dialplan
40		acc_cdrs topos_d topos_t'}
41EXTRA_TABLES=${EXTRA_TABLES:-'imc_members imc_rooms cpl sip_trace domainpolicy
42		carrierroute carrier_name domain_name carrierfailureroute userblacklist
43		globalblacklist htable purplemap uacreg pl_pipes mtree mtrees
44		sca_subscriptions mohqcalls mohqueues rtpproxy rtpengine
45		dr_gateways dr_rules dr_gw_lists dr_groups secfilter'}
46PRESENCE_TABLES=${PRESENCE_TABLES:-'presentity active_watchers watchers xcap
47		pua rls_presentity rls_watchers'}
48DBUID_TABLES=${UID_TABLES:-'uid_credentials uid_domain uid_domain_attrs
49		uid_global_attrs uid_uri uid_uri_attrs uid_user_attrs'}
50
51# SQL definitions
52# If you change this definitions here, then you must change them
53# in ../../lib/srdb1/schema/entities.xml too. They are used in this
54# script and needed to be the same as in the database definitions.
55# FIXME
56
57FOREVER=${FOREVER:-2030-05-28 21:32:15}
58
59# default location for config files
60DEFAULT_CFG_DIR=/usr/local/etc/kamailio
61
62# default location for data files
63DEFAULT_DATA_DIR=/usr/local/share/kamailio
64
65# Needed programs
66MD5=${MD5:-md5sum}
67AWK=${AWK:-awk}
68GREP=${GREP:-grep}
69SED=${SED:-sed}
70
71# define what modules should be installed
72STANDARD_MODULES=${STANDARD_MODULES:-'standard acc lcr domain group
73		permissions registrar usrloc msilo alias_db uri_db speeddial
74		avpops auth_db pdt dialog dispatcher dialplan topos'}
75
76PRESENCE_MODULES=${PRESENCE_MODULES:-'presence rls'}
77
78EXTRA_MODULES=${EXTRA_MODULES:-'imc cpl siptrace domainpolicy carrierroute
79		drouting userblacklist htable purple uac pipelimit mtree sca mohqueue
80		rtpproxy rtpengine secfilter'}
81
82DBUID_MODULES=${UID_MODULES:-'uid_auth_db uid_avp_db uid_domain uid_gflags
83		uid_uri_db'}
84
85############################################################
86
87# common functions
88
89usage() {
90COMMAND=`basename $0`
91cat <<EOF
92$0 $VERSION
93
94usage: $COMMAND create <db name or db_path, optional> ...(creates a new database)
95       $COMMAND drop <db name or db_path, optional> .....(!entirely deletes tables!)
96       $COMMAND reinit <db name or db_path, optional> ...(!entirely deletes and than re-creates tables!)
97       $COMMAND backup <file> ...........................(dumps current database to file)
98       $COMMAND restore <file> ..........................(restores tables from a file)
99       $COMMAND copy <new_db> ...........................(creates a new db from an existing one)
100       $COMMAND presence ................................(adds the presence related tables)
101       $COMMAND extra ...................................(adds the extra tables)
102       $COMMAND dbuid ...................................(adds the uid tables)
103       $COMMAND dbonly ..................................(creates empty database)
104       $COMMAND grant ...................................(grant privileges to database)
105       $COMMAND revoke ..................................(revoke privileges to database)
106       $COMMAND add-tables <gid> ........................(creates only tables groupped in gid)
107
108       if you want to manipulate database as other database user than
109       root, want to change database name from default value "$DBNAME",
110       or want to use other values for users and password, edit the
111       "config vars" section of the command $COMMAND.
112
113       $COMMAND pframework create .......................(creates a sample provisioning framework file)
114EOF
115} #usage
116
117
118
119
120# read realm
121prompt_realm()
122{
123	printf "Domain (realm) for the default user 'admin': "
124	read SIP_DOMAIN
125	echo
126}
127
128
129# calculate credentials for admin
130credentials()
131{
132	HA1=`echo -n "admin:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
133	if [ $? -ne 0 ] ; then
134		merr "HA1 calculation failed"
135		exit 1
136	fi
137	HA1B=`echo -n "admin@$SIP_DOMAIN:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
138	if [ $? -ne 0 ] ; then
139		merr "HA1B calculation failed"
140		exit 1
141	fi
142
143	#PHPLIB_ID of users should be difficulty to guess for security reasons
144	NOW=`date`;
145	PHPLIB_ID=`echo -n "$RANDOM:$NOW:$SIP_DOMAIN" | $MD5 | $AWK '{ print $1 }'`
146	if [ $? -ne 0 ] ; then
147		merr "PHPLIB_ID calculation failed"
148		exit 1
149	fi
150}
151
152# FIXME use the definition from kamctl.base
153
154mdbg() {
155	if [ "0$VERBOSE" -ne 0 ] ; then
156		if [ -t 1 -a -z "$NOHLPRINT" ] ; then
157			echo -e "\033[1m$1\033[0m"
158		else
159			echo "$1"
160		fi
161	fi
162}
163
164mwarn() {
165	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
166		echo -e '\E[37;32m'"\033[1mWARNING: $1\033[0m"
167	else
168		echo "** WARNING: $1"
169	fi
170}
171
172minfo() {
173	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
174		echo -e '\E[37;33m'"\033[1mINFO: $1\033[0m"
175	else
176		echo "** INFO: $1"
177	fi
178}
179
180mecho() {
181	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
182		echo -e "\033[1m$1\033[0m"
183	else
184		echo "$1"
185	fi
186}
187
188merr() {
189	if [ -t 1 -a -z "$NOHLPRINT" ] ; then
190		echo -e '\E[37;31m'"\033[1mERROR: $1\033[0m"
191	else
192		echo "** ERROR: $1"
193	fi
194}
195
196# Get a y/n value from a variable. If the variable contains the keyword
197# `ask', then interactively ask the user for an answer.
198#
199# Arguments:
200#  $1 - variable holding yes/no/ask
201#  $2 - question to print if value of variable is ask
202#
203# Return:
204#  On return $ANSWER will be available with y/n
205#
206get_answer ()
207{
208	value=$1
209	question=$2
210	if [ "${value}" = "ask" ]; then
211		echo -n "$question"
212		read value
213	fi
214	ANSWER=$(echo ${value} | grep -o -e '[YyNn]' | sed -e 's/Y/y/' -e 's/N/n/')
215}
216