Browse code

More flexible configuration of the path to the source database templates. There is a new configuration option in the script containing the default path to the directory containing source database templates. The value of that option will be updated during make install. Relative pathnames are converted to absolute pathnames with respect to the location of the ser_dbtext.sh script.

Jan Janak authored on 26/06/2008 00:08:55
Showing 1 changed files
... ...
@@ -2,11 +2,11 @@
2 2
 #
3 3
 # $Id$
4 4
 #
5
-# Script for dbtext database maintenance
5
+# SER dbtext Database Administration Tool
6 6
 #
7 7
 # TODO: Check if user and group exist
8 8
 #
9
-# Copyright (C) 2006 iptelorg GmbH
9
+# Copyright (C) 2006-2008 iptelorg GmbH
10 10
 #
11 11
 
12 12
 #################################################################
... ...
@@ -16,13 +16,14 @@ DEFAULT_ROOTDIR="/var/local/lib/ser" # Default dbtext root directory
16 16
 DEFAULT_DBNAME="ser"                 # Default database name
17 17
 DEFAULT_OWNER="ser"                  # The owner of dbtext files
18 18
 DEFAULT_GROUP="ser"                  # The group of dbtext files
19
+DEFAULT_SRCDB_DIR=""                 # Default directory of the source data
19 20
 DEFAULT_SRCDB="ser_db"      # Source data generated from XML description
20 21
 
21 22
 
22 23
 usage() {
23 24
 cat <<EOF
24 25
 NAME
25
-  $COMMAND - SER dbtext database administration tool
26
+  $COMMAND - SER dbtext Database Administration Tool
26 27
 
27 28
 SYNOPSIS
28 29
   $COMMAND [options] create
... ...
@@ -31,25 +32,25 @@ SYNOPSIS
31 31
   $COMMAND [options] restore [filename.tar]
32 32
 
33 33
 DESCRIPTION
34
-  This tool is a simple shell wrapper that can be used to create, drop, or 
35
-  backup SER database stored in plain-text files on the filesystem (used
36
-  by dbtext SER module). See section COMMANDS for brief overview of supported 
34
+  This tool is a simple shell wrapper that can be used to create, drop, or
35
+  backup SER database stored in plain-text files on the filesystem (used by
36
+  dbtext SER module). See section COMMANDS for brief overview of supported
37 37
   actions.
38 38
 
39 39
   The database template for SER dbtext database is stored in dbtext_template
40
-  directory which can usualy be found in /usr/lib/ser (depending on
41
-  installation). You can use the template to create SER database manually
42
-  if you cannot or do not want to use this shell wrapper.
40
+  directory which can usualy be found in /var/lib/ser (depending on
41
+  installation). You can use the template to create SER database manually if
42
+  you cannot or do not want to use this shell wrapper.
43 43
 
44 44
 COMMANDS
45 45
   create
46
-    Create a new SER database from scratch. The database must not exist.
47
-    This command creates the database, the default name of the database
48
-    is '${DEFAULT_DBNAME}' (the default name can be changed using a command line
49
-    parameter, see below). The database will be created in the default dbtext 
46
+    Create a new SER database from scratch. The database must not exist.  This
47
+    command creates the database, the default name of the database is
48
+    '${DEFAULT_DBNAME}' (the default name can be changed using a command line
49
+    parameter, see below). The database will be created in the default dbtext
50 50
     database directory (${DEFAULT_ROOTDIR}) unless changed using -d command
51 51
     line option (see below). You can use command line options to change the
52
-    default database name, owner username and group. 
52
+    default database name, owner username and group.
53 53
 
54 54
   drop
55 55
     This command can be used to delete SER database. WARNING: This command
... ...
@@ -63,8 +64,8 @@ COMMANDS
63 63
     will dumps the contents on the standard output.
64 64
 
65 65
   restore <filename>
66
-    Load the contents of SER database from a file (if you specify one) or
67
-    from the standard input. 
66
+    Load the contents of SER database from a file (if you specify one) or from
67
+    the standard input.
68 68
 
69 69
 OPTIONS
70 70
   -h, --help
... ...
@@ -94,13 +95,13 @@ AUTHOR
94 94
   Written by Jan Janak <jan@iptel.org>
95 95
 
96 96
 COPYRIGHT
97
-  Copyright (C) 2006 iptelorg GmbH
98
-  This is free software. You may redistribute copies of it under the
99
-  termp of the GNU General Public License. There is NO WARRANTY, to the
100
-  extent permitted by law.
97
+  Copyright (C) 2006-2008 iptelorg GmbH
98
+  This is free software. You may redistribute copies of it under the termp of
99
+  the GNU General Public License. There is NO WARRANTY, to the extent
100
+  permitted by law.
101 101
 
102 102
 FILES
103
-  $SRCDB
103
+  ${SRCDB_DIR}/${SRCDB}
104 104
     
105 105
 REPORTING BUGS
106 106
   Report bugs to <ser-bugs@iptel.org>             
... ...
@@ -164,8 +165,8 @@ create_db ()
164 164
 	exit 1
165 165
     fi
166 166
     
167
-    dbg "Copying template files from ${SRCDB} to ${ROOTDIR}/${DBNAME}"
168
-    cp -a ${SRCDB}/* "${ROOTDIR}/${DBNAME}"
167
+    dbg "Copying template files from ${SRCDB_DIR}/${SRCDB} to ${ROOTDIR}/${DBNAME}"
168
+    cp -a ${SRCDB_DIR}/${SRCDB}/* "${ROOTDIR}/${DBNAME}"
169 169
 
170 170
     dbg "Setting owner and group of new files to ${OWNER}:${GROUP}"
171 171
     chown -R "${OWNER}:${GROUP}" "${ROOTDIR}/${DBNAME}"
... ...
@@ -173,14 +174,28 @@ create_db ()
173 173
 } # create_db
174 174
 
175 175
 
176
+# Convert relative path to the script directory to absolute if necessary by
177
+# extracting the directory of this script and prefixing the relative path with
178
+# it.
179
+abs_srcdb_dir()
180
+{
181
+  	my_dir=`dirname $0`;
182
+  	if [ "${SRCDB_DIR:0:1}" != "/" ] ; then
183
+  	    SCRIPT_DIR="${my_dir}/${SRCDB_DIR}"
184
+  	fi
185
+}
186
+
176 187
 
177 188
 # Main program
178 189
 COMMAND=`basename $0`
179 190
 
180
-if [ -z "$DBNAME" ] ; then DBNAME=$DEFAULT_DBNAME; fi;
181
-if [ -z "$OWNER" ]  ; then OWNER=$DEFAULT_OWNER; fi;
182
-if [ -z "$GROUP" ]  ; then GROUP=$DEFAULT_GROUP; fi;
183
-if [ -z "$SRCDB" ]  ; then SRCDB=`dirname $0`"/"$DEFAULT_SRCDB; fi
191
+if [ -z "$DBNAME" ] ; then DBNAME="$DEFAULT_DBNAME"; fi;
192
+if [ -z "$OWNER" ]  ; then OWNER="$DEFAULT_OWNER"; fi;
193
+if [ -z "$GROUP" ]  ; then GROUP="$DEFAULT_GROUP"; fi;
194
+if [ -z "$SRCDB_DIR" ] ; then SRCDB_DIR="$DEFAULT_SRCDB_DIR"; fi;
195
+if [ -z "$SRCDB" ]  ; then SRCDB="$DEFAULT_SRCDB"; fi
196
+
197
+abs_srcdb_dir
184 198
 
185 199
 TEMP=`getopt -o hn:d:o:g:v --long help,name:,dir:,owner:,group:,verbose -n $COMMAND -- "$@"`
186 200
 if [ $? != 0 ] ; then exit 1; fi