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. In addition to that the script also accepts a new cmd line option -d which can be used to specify the directory with SQL files manually. Relative pathnames are converted to absolute pathnames with respect to the location of the ser_mysql.sh script.

Jan Janak authored on 24/06/2008 13:20:00
Showing 1 changed files
... ...
@@ -21,6 +21,8 @@ DEFAULT_RWPASS="heslo"       # Default password of read-write user
21 21
 DEFAULT_MYSQL="mysql"
22 22
 DEFAULT_MYSQLDUMP="mysqldump"
23 23
 
24
+DEFAULT_SCRIPT_DIR=""
25
+
24 26
 DEFAULT_CREATE_SCRIPT="my_create.sql"
25 27
 DEFAULT_DATA_SCRIPT="my_data.sql"
26 28
 DEFAULT_DROP_SCRIPT="my_drop.sql"
... ...
@@ -138,6 +140,11 @@ OPTIONS
138 140
       administrator is needed and will not ask for it.
139 141
       (No default value)
140 142
 
143
+  -d DIRECTORY, --script-dir=DIRECTORY
144
+      Directory containing the SQL scripts with database schema and
145
+      initial data definition.
146
+      (Default value is '$DEFAULT_SCRIPT_DIR')
147
+
141 148
   -k, --keep-users
142 149
       Do not delete database users when removing the database. This
143 150
       is useful if you have multiple databases and use the same users
... ...
@@ -155,15 +162,15 @@ AUTHOR
155 162
   Written by Jan Janak <jan@iptel.org>
156 163
 
157 164
 COPYRIGHT
158
-  Copyright (C) 2006 iptelorg GmbH
165
+  Copyright (C) 2006-2008 iptelorg GmbH
159 166
   This is free software. You may redistribute copies of it under the
160 167
   termp of the GNU General Public License. There is NO WARRANTY, to the
161 168
   extent permitted by law.
162 169
 
163 170
 FILES
164
-  $CREATE_SCRIPT
165
-  $DATA_SCRIPT
166
-  $DROP_SCRIPT
171
+  ${SCRIPT_DIR}/${CREATE_SCRIPT}
172
+  ${SCRIPT_DIR}/${DATA_SCRIPT}
173
+  ${SCRIPT_DIR}/${DROP_SCRIPT}
167 174
     
168 175
 REPORTING BUGS
169 176
   Report bugs to <ser-bugs@iptel.org>             
... ...
@@ -196,6 +203,18 @@ prompt_pw()
196 203
     fi
197 204
 }
198 205
 
206
+# Convert relative path to the script directory to absolute if necessary by
207
+# extracting the directory of this script and prefixing the relative path with
208
+# it.
209
+abs_script_dir()
210
+{
211
+	my_dir=`dirname $0`;
212
+	if [ "${SCRIPT_DIR:0:1}" != "/" ] ; then
213
+		SCRIPT_DIR="${my_dir}/${SCRIPT_DIR}"
214
+    fi
215
+}
216
+
217
+
199 218
 #
200 219
 # Execute an SQL command
201 220
 #
... ...
@@ -298,12 +317,17 @@ if [ -z "$SQLUSER" ] ; then SQLUSER=$DEFAULT_SQLUSER; fi;
298 317
 if [ -z "$MYSQL" ] ; then MYSQL=$DEFAULT_MYSQL; fi
299 318
 if [ -z "$MYSQLDUMP" ] ; then MYSQLDUMP=$DEFAULT_MYSQLDUMP; fi
300 319
 if [ -z "$DUMP_OPTS" ] ; then DUMP_OPTS=$DEFAULT_DUMP_OPTS; fi 
301
-if [ -z "$CREATE_SCRIPT" ] ; then CREATE_SCRIPT=`dirname $0`"/"$DEFAULT_CREATE_SCRIPT; fi
302
-if [ -z "$DATA_SCRIPT" ] ; then DATA_SCRIPT=`dirname $0`"/"$DEFAULT_DATA_SCRIPT; fi
303
-if [ -z "$DROP_SCRIPT" ] ; then DROP_SCRIPT=`dirname $0`"/"$DEFAULT_DROP_SCRIPT; fi
320
+if [ -z "$CREATE_SCRIPT" ] ; then CREATE_SCRIPT=$DEFAULT_CREATE_SCRIPT; fi
321
+if [ -z "$DATA_SCRIPT" ] ; then DATA_SCRIPT=$DEFAULT_DATA_SCRIPT; fi
322
+if [ -z "$DROP_SCRIPT" ] ; then DROP_SCRIPT=$DEFAULT_DROP_SCRIPT; fi
323
+if [ -z "$SCRIPT_DIR" ] ; then SCRIPT_DIR=$DEFAULT_SCRIPT_DIR; fi;
324
+
325
+# Make the path to the script directory absolute
326
+abs_script_dir
304 327
 
305
-TEMP=`getopt -o hn:r:w:p:P:ts:u:vkq:: --long help,name:,ro-username:,rw-username:,\
306
-ro-password:,rw-password:,tables,server:,username:,verbose,keep-users,sql-password:: -n $COMMAND -- "$@"`
328
+TEMP=`getopt -o hn:r:w:p:P:ts:u:vkq::d: --long help,name:,ro-username:,rw-username:,\
329
+ro-password:,rw-password:,tables,server:,username:,verbose,keep-users,\
330
+sql-password::,script-dir: -n $COMMAND -- "$@"`
307 331
 if [ $? != 0 ] ; then exit 1; fi
308 332
 eval set -- "$TEMP"
309 333
 
... ...
@@ -318,9 +342,15 @@ while true ; do
318 342
 	-t|--tables)       DUMP_OPTS="$DUMP_OPTS -t "; shift ;;
319 343
 	-s|--server)       DBHOST=$2; shift 2 ;;
320 344
 	-u|--username)     SQLUSER=$2; shift 2 ;;
321
-        -v|--verbose)      MYSQL_OPTS="$MYSQL_OPTS -v "; shift ;;
345
+    -v|--verbose)      MYSQL_OPTS="$MYSQL_OPTS -v "; shift ;;
322 346
 	-k|--keep-users)   KEEP_USERS=1; shift ;;
323
-        -q|--sql-password)
347
+    -d|--script-dir)   
348
+        SCRIPT_DIR=$2;
349
+		# The script directory changed, make it absolute again
350
+        abs_script_dir
351
+        shift 2 
352
+        ;;
353
+    -q|--sql-password)
324 354
 	    case "$2" in
325 355
 		"") DONT_ASK=1; shift 2 ;;
326 356
 		*)  PW=$2; shift 2 ;;