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