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 24/06/2008 14:12:59
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="ser_db"      # Source data generated from XML description
19
+DEFAULT_SRCDB_DIR=""                 # Default directory of the source data
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 32
   $COMMAND [options] restore [filename.tar]
32 33
 
33 34
 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 
35
+  This tool is a simple shell wrapper that can be used to create, drop, or
36
+  backup SER database stored in plain-text files on the filesystem (used by
37
+  dbtext SER module). See section COMMANDS for brief overview of supported
37 38
   actions.
38 39
 
39 40
   The database template for SER dbtext database is stored in dbtext_template
40 41
   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.
42
+  installation). You can use the template to create SER database manually if
43
+  you cannot or do not want to use this shell wrapper.
43 44
 
44 45
 COMMANDS
45 46
   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 
47
+    Create a new SER database from scratch. The database must not exist.  This
48
+    command creates the database, the default name of the database is
49
+    '${DEFAULT_DBNAME}' (the default name can be changed using a command line
50
+    parameter, see below). The database will be created in the default dbtext
50 51
     database directory (${DEFAULT_ROOTDIR}) unless changed using -d command
51 52
     line option (see below). You can use command line options to change the
52
-    default database name, owner username and group. 
53
+    default database name, owner username and group.
53 54
 
54 55
   drop
55 56
     This command can be used to delete SER database. WARNING: This command
... ...
@@ -63,8 +64,8 @@ COMMANDS
63 64
     will dumps the contents on the standard output.
64 65
 
65 66
   restore <filename>
66
-    Load the contents of SER database from a file (if you specify one) or
67
-    from the standard input. 
67
+    Load the contents of SER database from a file (if you specify one) or from
68
+    the standard input.
68 69
 
69 70
 OPTIONS
70 71
   -h, --help
... ...
@@ -94,16 +95,16 @@ AUTHOR
94 95
   Written by Jan Janak <jan@iptel.org>
95 96
 
96 97
 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.
98
+  Copyright (C) 2006-2008 iptelorg GmbH
99
+  This is free software. You may redistribute copies of it under the termp of
100
+  the GNU General Public License. There is NO WARRANTY, to the extent
101
+  permitted by law.
101 102
 
102 103
 FILES
103
-  $SRCDB
104
+  ${SRCDB_DIR}/${SRCDB}
104 105
     
105 106
 REPORTING BUGS
106
-  Report bugs to <ser-bugs@iptel.org>             
107
+  Report bugs to <ser-bugs@iptel.org>
107 108
 EOF
108 109
 } #usage
109 110
 
... ...
@@ -164,8 +165,8 @@ create_db ()
164 165
 	exit 1
165 166
     fi
166 167
     
167
-    dbg "Copying template files from ${SRCDB} to ${ROOTDIR}/${DBNAME}"
168
-    cp -a ${SRCDB}/* "${ROOTDIR}/${DBNAME}"
168
+    dbg "Copying template files from ${SRCDB_DIR}/${SRCDB} to ${ROOTDIR}/${DBNAME}"
169
+    cp -a ${SRCDB_DIR}/${SRCDB}/* "${ROOTDIR}/${DBNAME}"
169 170
 
170 171
     dbg "Setting owner and group of new files to ${OWNER}:${GROUP}"
171 172
     chown -R "${OWNER}:${GROUP}" "${ROOTDIR}/${DBNAME}"
... ...
@@ -173,6 +174,17 @@ create_db ()
173 174
 } # create_db
174 175
 
175 176
 
177
+# Convert relative path to the script directory to absolute if necessary by
178
+# extracting the directory of this script and prefixing the relative path with
179
+# it.
180
+abs_srcdb_dir()
181
+{
182
+	my_dir=`dirname $0`;
183
+	if [ "${SRCDB_DIR:0:1}" != "/" ] ; then
184
+		SCRIPT_DIR="${my_dir}/${SRCDB_DIR}"
185
+    fi
186
+}
187
+
176 188
 
177 189
 # Main program
178 190
 COMMAND=`basename $0`
... ...
@@ -180,7 +192,10 @@ COMMAND=`basename $0`
180 192
 if [ -z "$DBNAME" ] ; then DBNAME=$DEFAULT_DBNAME; fi;
181 193
 if [ -z "$OWNER" ]  ; then OWNER=$DEFAULT_OWNER; fi;
182 194
 if [ -z "$GROUP" ]  ; then GROUP=$DEFAULT_GROUP; fi;
183
-if [ -z "$SRCDB" ]  ; then SRCDB=`dirname $0`"/"$DEFAULT_SRCDB; fi
195
+if [ -z "$SRCDB_DIR" ] ; then SRCDB_DIR=$DEFAULT_SRCDB_DIR; fi;
196
+if [ -z "$SRCDB" ]  ; then SRCDB=$DEFAULT_SRCDB; fi
197
+
198
+abs_srcdb_dir
184 199
 
185 200
 TEMP=`getopt -o hn:d:o:g:v --long help,name:,dir:,owner:,group:,verbose -n $COMMAND -- "$@"`
186 201
 if [ $? != 0 ] ; then exit 1; fi
... ...
@@ -190,10 +205,10 @@ while true ; do
190 205
     case "$1" in
191 206
 	-h|--help)    usage; exit 0 ;;
192 207
 	-n|--name)    DBNAME=$2; shift 2 ;;
193
-        -d|--dir)     ROOTDIR=$2; shift 2 ;;
208
+    -d|--dir)     ROOTDIR=$2; shift 2 ;;
194 209
 	-o|--owner)   OWNER=$2;  shift 2 ;;
195 210
 	-g|--group)   GROUP=$2;  shift 2 ;;
196
-        -v|--verbose) export OPTS="${OPTS} -v "; VERBOSE=1; shift ;;
211
+    -v|--verbose) export OPTS="${OPTS} -v "; VERBOSE=1; shift ;;
197 212
 	--)           shift; break ;;
198 213
 	*)            echo "Internal error"; exit 1 ;;
199 214
     esac