Browse code

More flexible configuration of the path to SQL script files. There is a new configuration option in the script containing the default path to the directory containing SQL script files. 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_postgres.sh script.

Jan Janak authored on 26/06/2008 00:01:52
Showing 1 changed files
... ...
@@ -11,6 +11,8 @@
11 11
 DEFAULT_DBNAME="ser"
12 12
 DEFAULT_SQLUSER="postgres"
13 13
 
14
+DEFAULT_SCRIPT_DIR=""
15
+
14 16
 DEFAULT_PSQL="/usr/bin/psql"
15 17
 DEFAULT_PG_DUMP="/usr/bin/pg_dump"
16 18
 
... ...
@@ -26,10 +28,10 @@ Usage: $COMMAND create  [database]
26 28
        $COMMAND drop    [database]
27 29
        $COMMAND backup  [database] <file> 
28 30
        $COMMAND restore [database] <file>
29
-   
30
-  Command 'create' creates database named '${DBNAME}' containing tables 
31
-  needed for SER and SERWeb. In addition to that two users are created, 
32
-  one with read/write permissions and one with read-only permissions.
31
+
32
+  Command 'create' creates database named '${DBNAME}' containing tables needed
33
+  for SER and SERWeb. In addition to that two users are created, one with
34
+  read/write permissions and one with read-only permissions.
33 35
 
34 36
   Commmand 'drop' deletes database named '${DBNAME}' and associated users.
35 37
 
... ...
@@ -86,7 +88,7 @@ db_drop()
86 88
     # Revoke user permissions
87 89
 
88 90
     echo "Dropping database $1"
89
-    $CMD "template1" < ${DROP_SCRIPT}
91
+    $CMD "template1" < ${SCRIPT_DIR}/${DROP_SCRIPT}
90 92
     echo "DROP DATABASE $1" | $CMD "template1" 
91 93
 }
92 94
 
... ...
@@ -96,11 +98,22 @@ db_create ()
96 98
 {
97 99
     echo "Creating database $1"
98 100
     echo "CREATE DATABASE $1" | $CMD "template1"
99
-    $CMD $1 < $CREATE_SCRIPT
100
-    $CMD $1 < $DATA_SCRIPT
101
+    $CMD $1 < ${SCRIPT_DIR}/${CREATE_SCRIPT}
102
+    $CMD $1 < ${SCRIPT_DIR}/${DATA_SCRIPT}
101 103
 }
102 104
 
103 105
 
106
+# Convert relative path to the script directory to absolute if necessary by
107
+# extracting the directory of this script and prefixing the relative path with
108
+# it.
109
+abs_script_dir()
110
+{
111
+  	my_dir=`dirname $0`;
112
+  	if [ "${SCRIPT_DIR:0:1}" != "/" ] ; then
113
+  	    SCRIPT_DIR="${my_dir}/${SCRIPT_DIR}"
114
+  	fi
115
+}
116
+
104 117
 
105 118
 # Main program
106 119
 
... ...
@@ -138,6 +151,10 @@ if [ -z "$DROP_SCRIPT" ]; then
138 151
     DROP_SCRIPT=$DEFAULT_DROP_SCRIPT;
139 152
 fi
140 153
 
154
+if [ -z "$SCRIPT_DIR" ]; then
155
+	SCRIPT_DIR=$DEFAULT_SCRIPT_DIR;
156
+fi
157
+
141 158
 if [ $# -eq 0 ]; then
142 159
     usage
143 160
     exit 1
... ...
@@ -152,6 +169,8 @@ fi
152 169
 CMD="$PSQL ${DBHOST} -U $SQLUSER"
153 170
 DUMP_CMD="$PG_DUMP ${DBHOST} -U $SQLUSER"
154 171
 
172
+abs_script_dir
173
+
155 174
 case $1 in
156 175
     create) # Create SER database and users
157 176
 	shift