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 26
        $COMMAND drop    [database]
27 27
        $COMMAND backup  [database] <file> 
28 28
        $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.
29
+
30
+  Command 'create' creates database named '${DBNAME}' containing tables needed
31
+  for SER and SERWeb. In addition to that two users are created, one with
32
+  read/write permissions and one with read-only permissions.
33 33
 
34 34
   Commmand 'drop' deletes database named '${DBNAME}' and associated users.
35 35
 
... ...
@@ -86,7 +88,7 @@ db_drop()
86 86
     # Revoke user permissions
87 87
 
88 88
     echo "Dropping database $1"
89
-    $CMD "template1" < ${DROP_SCRIPT}
89
+    $CMD "template1" < ${SCRIPT_DIR}/${DROP_SCRIPT}
90 90
     echo "DROP DATABASE $1" | $CMD "template1" 
91 91
 }
92 92
 
... ...
@@ -96,11 +98,22 @@ db_create ()
96 96
 {
97 97
     echo "Creating database $1"
98 98
     echo "CREATE DATABASE $1" | $CMD "template1"
99
-    $CMD $1 < $CREATE_SCRIPT
100
-    $CMD $1 < $DATA_SCRIPT
99
+    $CMD $1 < ${SCRIPT_DIR}/${CREATE_SCRIPT}
100
+    $CMD $1 < ${SCRIPT_DIR}/${DATA_SCRIPT}
101 101
 }
102 102
 
103 103
 
104
+# Convert relative path to the script directory to absolute if necessary by
105
+# extracting the directory of this script and prefixing the relative path with
106
+# it.
107
+abs_script_dir()
108
+{
109
+  	my_dir=`dirname $0`;
110
+  	if [ "${SCRIPT_DIR:0:1}" != "/" ] ; then
111
+  	    SCRIPT_DIR="${my_dir}/${SCRIPT_DIR}"
112
+  	fi
113
+}
114
+
104 115
 
105 116
 # Main program
106 117
 
... ...
@@ -138,6 +151,10 @@ if [ -z "$DROP_SCRIPT" ]; then
138 138
     DROP_SCRIPT=$DEFAULT_DROP_SCRIPT;
139 139
 fi
140 140
 
141
+if [ -z "$SCRIPT_DIR" ]; then
142
+	SCRIPT_DIR=$DEFAULT_SCRIPT_DIR;
143
+fi
144
+
141 145
 if [ $# -eq 0 ]; then
142 146
     usage
143 147
     exit 1
... ...
@@ -152,6 +169,8 @@ fi
152 152
 CMD="$PSQL ${DBHOST} -U $SQLUSER"
153 153
 DUMP_CMD="$PG_DUMP ${DBHOST} -U $SQLUSER"
154 154
 
155
+abs_script_dir
156
+
155 157
 case $1 in
156 158
     create) # Create SER database and users
157 159
 	shift